Scrivio Interview library
ScenarioIntermediate7 min read · updated 12 November 2026

Two microservices, Billing and Accounts, each own their data. A support engineer reports that for some customers the plan shown in Billing differs from Accounts for hours. Both services exchange events over a broker. How would you investigate and what design changes would you make so the divergence is bounded and detectable?

Divergence that lasts hours is not normal lag; it means changes are being lost or stuck. We investigate by checking for dual writes that can commit the database but fail the broker send, then consumer lag, dead-letter topics and poison messages that block a partition. The design fix is to make every committed change produce an event through a transactional outbox or CDC, add a reconciliation job that compares both sides by id and version, and publish lag and divergence as metrics with a staleness budget per field.

Why this question is asked

Eventual consistency promises that copies converge. When two services disagree for hours, that promise is broken somewhere, and support engineers are usually the first to notice. Interviewers ask this scenario at the ten-year level because a good answer moves from symptoms to a systematic investigation and then to design changes that make the problem bounded and visible, not just fixed once. In this answer, we will set up the situation, investigate the three places events go missing or get stuck, and then add the three design changes: reliable publication, reconciliation, and metrics with a staleness budget.

1Setting the Scene: Who Owns the Plan?

Billing and Accounts each have their own database, and they exchange events over a broker such as Kafka. Before investigating, we need to know which service owns the customer's plan, meaning which one is the source of truth that accepts the change first. Suppose Accounts owns it: a customer upgrades in Accounts, Accounts publishes PlanChanged, and Billing updates its copy.

Normal lag between them is seconds. If Billing shows the old plan for hours, one of three things happened. The event was never published. It was published but Billing never applied it. Or Billing applied it and then something overwrote it with an older value. Our investigation checks these in order, starting from one affected customer id.

2Were Events Lost by a Dual Write?

A dual write is code that writes to two systems, the database and the broker, without one transaction covering both. It looks harmless and it is the most common cause of permanent divergence.

Java
@Transactional
public void changePlan(long customerId, Plan plan) {
accountRepository.updatePlan(customerId, plan);
kafkaTemplate.send("plan-changed", key(customerId), new PlanChanged(customerId, plan));
} // commit happens here, after the send
// broker down for 2 s -> send fails or times out, but the DB commits anyway in some setups
// DB commit fails -> event already sent, Billing applies a change that never happened
// pod killed after commit -> with an async send, the event may never leave the buffer

To check for this, we take a list of customer ids that changed plan in Accounts during a day and compare it with the PlanChanged events in the topic for the same period. If some changes have no event, publication is the problem. Logs of send failures and producer errors around those timestamps usually confirm it.

3Is the Consumer Stuck or Skipping?

If the events exist, we look at Billing's consumer. Consumer group lag shows how many messages it has not read per partition. A partition with lag that only grows points to a poison message, a record that fails every time, for example because it cannot be deserialized after a schema change. With a blocking retry policy the consumer retries it forever and every event behind it waits, which is exactly how one bad event delays unrelated customers for hours.

We also check the dead-letter topic, where a consumer sends records it gave up on. Records parked there were never applied, and nobody is replaying them. Finally we check the Billing handler itself for silent drops: an exception caught and logged, a filter that ignores unknown plan codes, or a version check that rejects events by mistake.

Step throughInvestigating one diverged customer
  1. Pick one customer id with a mismatchcompare plan and version on both sides
  2. Event in the topic for that change?
    YesCheck Billing consumerNoDual write lost it
  3. Billing consumer lag growing?
    YesFind the poison messageNoCheck DLT
  4. Record in the dead-letter topic?
    YesFix and replayNoCheck handler logic
  5. Handler skipped or overwrote itlogs, version checks, filters

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

Each answer narrows the problem to publication, consumption or application logic.

4Fix 1: Every Committed Change Produces an Event

The structural fix for lost events is a transactional outbox. Instead of sending to the broker, the service inserts the event into an outbox table in the same database transaction as the business change. Either both commit or neither does. A relay process then reads the outbox and publishes to Kafka, retrying until it succeeds, which gives at-least-once delivery. The alternative is change data capture (CDC), where a tool such as Debezium reads the database's transaction log and turns committed changes into events, so the application does not publish at all.

Either way, the guarantee becomes: if the change committed, an event will be published. Since delivery is at least once, Billing must apply events idempotently, for example with a versioned upsert, so a duplicate has no effect.

5Fix 2: Reconciliation as a Safety Net

Even with an outbox, bugs, manual database fixes and replays from old backups can still create divergence. So we add reconciliation: a scheduled job that compares both sides by id and version and repairs what differs. Accounts can expose a cheap endpoint or export of customer id, plan and version changed since a time, and the job compares that with Billing's table.

Java
@Scheduled(cron = "0 */15 * * * *")
void reconcilePlans() {
Instant since = Instant.now().minus(Duration.ofHours(2));
for (PlanSnapshot src : accountsClient.plansChangedSince(since)) {
BillingPlan copy = billingRepository.find(src.customerId());
if (copy == null || copy.version() < src.version()) {
divergence.increment(); // counted before repair
billingRepository.upsertIfNewer(src); // or ask Accounts to re-emit
}
}
}

Notice that the job repairs only towards the owner, and only when the owner's version is newer. It also counts what it fixes. A reconciliation job that silently repairs hides the bug that caused the divergence, so the count is as important as the repair.

6Fix 3: Make Divergence Visible and Bounded

Bounded means we have a number. For each replicated field we agree a maximum acceptable staleness with the business: perhaps 1 minute for the plan used to compute invoices, and 1 hour for a marketing segment. Then we expose metrics that tell us whether we are within that budget: consumer lag per partition, the age of the oldest unpublished outbox row, the event-to-apply time in Billing, records in the dead-letter topic, and the divergence count from reconciliation.

Alerts follow from the budget. If the oldest outbox row is older than 1 minute, or the dead-letter topic is not empty, someone is paged before a support engineer notices. That turns hours of silent divergence into a minutes-long incident with a clear signal.

7Follow-up questions

Who should own the reconciliation job, and which side is the source of truth?

The source of truth is the service that owns the data and accepts its changes, here Accounts for the plan. I would let the consuming side, Billing, own the reconciliation job, because Billing is the one that depends on having a correct copy, while the owner provides a supported way to read its current state, such as a paged endpoint or export by id and version. If Billing finds differences it repairs its own copy or asks Accounts to re-emit; it never writes back into the owner.

Why not just make Billing call Accounts synchronously for the plan?

It removes the copy but couples availability: when Accounts is slow or down, invoicing stops. For data that is read very often or needed during batch runs, a local copy with bounded, monitored staleness is usually the better trade. For a single critical check, such as validating the plan at the moment of an upgrade charge, a synchronous read from the owner is reasonable.

Does the outbox remove the need for idempotent consumers?

No. The relay can publish the same row twice, for example if it crashes after sending but before marking the row as sent. So consumers must still deduplicate or apply events with a version check.

8Conclusion

In this answer, we treated hours of divergence as lost or stuck events rather than normal lag. We traced one customer through publication, consumption and application: dual writes that lose events, poison messages and dead-letter topics that stall or park them, and handlers that skip them. Then we made the divergence bounded and detectable with three changes: a transactional outbox or CDC so every committed change produces an event, a reconciliation job that repairs differences by id and version and counts them, and metrics with alerts against a staleness budget agreed per field.

What to say in the interviewAbout 90 seconds aloud

Open with

First I would establish which service owns the plan, say Accounts, and pick a few affected customers to trace. Divergence for hours is not normal lag, so something is lost or stuck.

Then, if they want more

I would check publication first: if Accounts writes its database and then sends to Kafka in the same method, that dual write can commit one and fail the other, so I compare the changes in the table with the events in the topic.

If the events exist, I look at Billing's consumer: lag per partition, a poison message being retried forever that blocks everything behind it, records sitting in the dead-letter topic, and handler logic that silently drops or overwrites events.

For the design, I would make publication reliable with a transactional outbox, or CDC such as Debezium, so every committed change produces an event, and keep Billing idempotent with versioned upserts because delivery is at least once.

Then I would add a reconciliation job that compares both sides by id and version every few minutes, repairs towards the owner and counts every repair.

Finally, I would agree a maximum staleness per field with the business and expose consumer lag, outbox age, dead-letter size and divergence count as metrics with alerts against that budget, so we find out in minutes rather than from support.

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 "Two microservices, Billing and Accounts, each own their data. A support engineer reports...": https://scrivio-interview-library.netlify.app/spring-boot/distributed-data/e1993b877b/