Order Outbox Service active
Two Java and Spring Boot microservices. When the message broker goes down, events wait in the database and none are lost. When the broker returns, the system recovers on its own.
The problem in one line
You save the order to the database and publish the event to the queue. Two separate operations, and there is no way to make them atomic: if the second one fails, the order exists and nobody finds out. It is called the dual write problem, and it shows up in almost any microservice system.
How it is solved
The pattern is the transactional outbox, built from three parts:
- A single commit. The order and its event are written in the same Postgres transaction, across two tables. Kafka takes no part in the HTTP request. If the commit succeeds, both exist. If it fails, neither does.
- A separate relay. A scheduled process reads pending events and publishes them. If the broker does not answer, it retries later, spacing attempts further apart so it does not hammer a service that is already struggling.
- An idempotent consumer. With at-least-once delivery, retries will duplicate messages. So the consuming service keeps a deduplication table with a unique key, and a second identical message is discarded before it has any effect.
Without that table, every retry would reach the customer as a repeated notification.
What the animation shows
With the broker deliberately switched off, the API keeps accepting orders and returning 201, because it never needed Kafka for that. The event waits in its table while the relay retries at 2, 4, 8, 16, 32 and 64 seconds. Once the fast retries are exhausted, the row is flagged as degraded and the relay keeps picking it up indefinitely.
When the broker returns, the event publishes itself, with no repair scripts or manual reprocessing. That run ended with 15 notifications for 15 orders, with no duplicates and no losses.
The service will not start with mismatched deadlines
Manual verification turned up rows marked as failed whose event had in fact been delivered. The code waited 5 seconds for confirmation, while the Kafka client kept retrying underneath for 120 seconds, its default value, which had not been configured.
Besides aligning the two values, the service now refuses to start if those deadlines drift apart, and prints a message explaining why. That keeps the mismatch from coming back by accident.
Architecture rules in ArchUnit
The domain and application layers import nothing from Spring, JPA or Hibernate. Ten ArchUnit rules (five per service) enforce this and break the build if the code crosses them.
The dashboard
The repository includes a React panel showing the circuit live: orders coming in, their event moving from pending to published, and the notification appearing in the other service’s database. The whole thing comes up with one command (docker compose up), with nothing to configure.
Out of scope
The system has no authentication and no real notification delivery. There is no public deployment either: the stack is two databases, Kafka and two services, and it does not fit comfortably in a free tier. The scope was limited to the delivery guarantee.