Skip to content

Add support for async completion of Outbox entries #981

@chychkan

Description

@chychkan

First of all, I really appreciate that this library exists, its design and its simplicity. So, thank you! ❤️

Problem

We’d like to use this library to publish messages to Kafka. The KafkaProducer#send() API is fully asynchronous: it only enqueues the record into the client’s internal buffers and returns immediately. The message is not considered delivered until the returned Future completes or the callback is invoked.

Because of this, calling send() inside an outbox-invoked method does not mean the message has been delivered (or even attempted). If the JVM or producer crashes after send() returns but before Kafka acknowledges the write, the message is lost - even though the Outbox will mark the entry as “processed”.

This breaks the main guarantee of the Outbox pattern: only mark the entry as processed when the external system has safely accepted it.

Kafka requires waiting for the Future (or callback) to know whether the send succeeded or failed.

Impact

The only way to ensure delivery today is to call producer.flush() after every message, but this significantly reduces the throughput. And so the library becomes usable only for low-throughput use cases.

Potential solutions

It would help if the proxied method could:

  1. return a Future / CompletableFuture, which the Outbox would wait on before marking the entry as processed
    or
  2. accept a callback supplied by the Outbox, which the user could invoke when the asynchronous operation completes

This would allow integrating properly with APIs like Kafka’s producer without forcing a flush-per-message.

Question

Has anyone solved this use case? Is there an existing way to handle async completion, or would you be open to supporting one of these approaches?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions