Scrivio Interview library
LeadershipAdvanced6 min read · updated 12 November 2026

Half of your teams publish events directly after database commits and the other half use various outbox implementations. Incidents show lost and phantom events. What platform approach would you take?

We would make the transactional outbox the required pattern for state-change events that other services depend on, and back that rule with one supported implementation, a shared library or a CDC platform, with built-in metrics and documentation, so following it is easier than not. For Spring services we would evaluate Spring Modulith's event publication registry as part of that choice. We would migrate teams in order of the business impact of a lost or phantom event, and add reconciliation checks to critical flows, so losses are detected whatever mechanism a service uses.

Background to this question

When half the teams publish after commit and the other half have built their own outbox, the company has two problems: the first half loses events, and the second half has many implementations to maintain, each with its own bugs. The incidents are the visible part. A platform leader is expected to fix the cause, not each incident. In this answer, we will recap why direct publishing fails and why home-grown outboxes vary, set the rule and its scope, choose and build one supported implementation, look at Spring Modulith as an option, plan the migration by impact, and add the reconciliation that catches whatever is left.

1Why Both Approaches Produce Incidents

Publishing directly after a database commit uses two systems with two commits. If the service crashes or the broker is down after the commit, the event is lost, because it only existed in memory. If it publishes before the commit, or inside the transaction, a rollback leaves a phantom event for a change that never happened. These are the lost and phantom events in the incident reports.

The teams with outboxes avoided that, but each built its own. One relay runs on two instances and reorders events. Another marks rows published before Kafka acknowledges, so a crash loses them. A third never deletes rows, and its table has 400 million rows. So the pattern is right, and the variety of implementations is the problem.

What the incident reviews typically show
ApproachFailure seenCause
Publish after commitlost eventscrash or broker outage after commit
Publish inside transactionphantom eventsrollback after the send
Home-grown outbox Areordered eventstwo relays with SKIP LOCKED
Home-grown outbox Blost eventsrow marked before broker ack
Home-grown outbox Cslow insertstable never cleaned

2Setting the Rule and Its Scope

The rule is short: any event that announces a state change other services depend on must be written through a transactional outbox in the same transaction as the change. OrderPlaced, PaymentCaptured and StockReserved are in scope. Purely informational signals, such as a cache-warming hint or a metrics ping, where a lost message causes no harm, are not, and teams can publish them directly.

Scoping matters, because a rule that covers everything is resented and then ignored. A rule tied to the cost of a lost event is easy to explain: if another team would act wrongly when your event is missing or false, it goes through the outbox.

3One Supported Implementation

The rule only works if following it is easy. So the platform provides one supported implementation, built once and correctly, with the lessons from the incidents built in: a single active relay or CDC so ordering per aggregate is kept, rows marked only after the broker acknowledges, cleanup of old rows, and the aggregate id as the Kafka key. It ships with metrics, at least the age of the oldest unpublished event, the backlog size and the publish rate, plus a dashboard and alert templates, and documentation with a worked example.

The choice between a shared library with a polling relay and a central CDC platform with Debezium depends on what the platform team can operate and how many databases are involved. A library is easier to adopt service by service; CDC is more efficient at high volume but needs Kafka Connect run as a service for every team. Many companies offer the library first and CDC for the highest-volume services.

Java
// What a team writes with the shared library
@Transactional
public void capture(PaymentId id) {
payments.markCaptured(id);
outbox.publish(new PaymentCaptured(id), id.value()); // same transaction; key = aggregate id
}
// the library's relay publishes it, keeps order per key, cleans up, and exports
// outbox_oldest_unpublished_seconds, outbox_backlog_rows, outbox_published_total

4Spring Modulith's Event Publication Registry as an Option

For Spring services, Spring Modulith offers something close to this out of the box. When a Spring application event is published inside a transaction to listeners such as @ApplicationModuleListener, its event publication registry stores a record of each publication in a database table in the same transaction, marks it complete when the listener succeeds, and can resubmit incomplete ones after a restart. Its event externalization support can also forward selected events, marked for example with @Externalized, to a broker such as Kafka.

It is worth evaluating rather than adopting by default. We would check how it handles ordering per aggregate when events are resubmitted, its throughput under our volumes, how completed entries are cleaned up, what metrics it exposes, and how it fits services that are not Spring. Check the details in your version, since the project has evolved quickly. If it meets the needs, it can be the supported implementation for Spring services; if not, the shared library is.

5Migration by Impact, and Reconciliation for Everything

Teams move in order of business impact. Services whose lost or phantom events cost money or customers, such as payments, orders and stock, move first. Those whose events feed reports or notifications move later. Teams with home-grown outboxes that work well move when they next change that code, while those behind recent incidents move now.

Step throughPlatform rollout
  1. Set the ruleoutbox for state-change events others depend on
  2. Ship one implementationlibrary or CDC, metrics, docs
  3. Migrate by business impactpayments and orders first
  4. Add reconciliationcritical flows, hourly counts
  5. Reconciliation differences?
    YesInvestigate and fix the causeNoReport the flow as healthy

5 steps in order. Play them, or step through them one at a time.

Finally, for critical flows we add reconciliation, because no mechanism is perfect and a migration takes months. A reconciliation job compares the two sides regularly, for example every hour it counts payments captured in the payment database and PaymentCaptured events received by the ledger, and alerts on any difference, listing the ids. It catches losses whatever their cause, including bugs in the outbox itself or in consumers, and it gives leadership a measurable answer to whether the problem is solved.

6Follow-up questions

What if a team insists its own outbox is fine?

Ask it to meet the same checks: ordering per aggregate under failover, marking only after acknowledgement, cleanup, and the standard metrics, and to pass the reconciliation. If it does, it can stay until the code next changes. The aim is correct events and fewer implementations, not uniformity for its own sake.

Why not just use Kafka transactions instead of an outbox?

Kafka transactions make several Kafka writes atomic, and consumed offsets with produced records. They cannot include a database commit. Since the problem is the gap between the database and Kafka, they do not solve it on their own.

How do you prove the platform is reducing incidents?

Track lost and phantom event incidents per quarter, reconciliation differences per flow, and the share of in-scope events going through the supported implementation. If adoption rises and both incidents and differences fall, the approach is working.

7Conclusion

In this answer, we made the transactional outbox the required pattern for state-change events other services depend on, provided one supported implementation with metrics and documentation, considered Spring Modulith's event publication registry as an option for Spring services, migrated teams in order of business impact, and added reconciliation checks so lost events are detected regardless of the mechanism.

What to say in the interviewAbout 90 seconds aloud

Open with

Both halves are producing incidents for different reasons. Publishing after commit uses two systems, so a crash or broker outage after the commit loses the event, and publishing inside the transaction gives phantom events on rollback.

Then, if they want more

The outbox teams have the right pattern, but every implementation is different, and the reviews usually show reordering from two relays, rows marked before the broker acks, or tables never cleaned. So I'd set a clear rule: any state-change event that other services depend on goes through a transactional outbox in the same transaction as the change.

Informational signals can still be published directly. Then I'd make the rule easy to follow with one supported implementation, either a shared library with a single active relay or a CDC platform with Debezium, built with those lessons in, keyed by aggregate id, cleaning up old rows, and exporting the age of the oldest unpublished event with dashboards and alerts.

For Spring services I'd evaluate Spring Modulith's event publication registry and externalization against our needs, like ordering, throughput and cleanup, before choosing it. Migration goes in order of business impact, so payments, orders and stock first.

And for critical flows I'd add reconciliation, like hourly counts of payments captured versus events the ledger received, which catches losses whatever the mechanism and shows whether the problem is really fixed.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Half of your teams publish events directly after database commits and the other half use...": https://scrivio-interview-library.netlify.app/spring-boot/event-driven-patterns/152cea5511/