Scrivio Interview library
DebuggingIntermediate6 min read · updated 13 November 2026

Ten minutes after a release, the rate on the customer-events topic rises from 300 to 45,000 records per second and keeps climbing. The top keys are the same few thousand customer ids repeating.

The release made the preferences service write a marketing flag back to the customer service whenever it receives CustomerUpdated. What is happening, how do you stop it now, and how do you prevent event loops?

It is an event loop: CustomerUpdated makes the preferences service write the marketing flag back, the customer service saves and publishes CustomerUpdated again, and the cycle repeats for every customer touched, adding load on each turn. To stop it now, pause or scale the preferences consumer to zero or roll back, add a produce quota on the customer service if brokers are suffering, and then check other consumers for side effects. To prevent it, publish CustomerUpdated only when stored state actually changes, give each field one owning service so derived data is not written back, and add causation, correlation and hop-count headers plus alerts on sudden rate increases.

Why this question is asked

Event loops are one of the classic failures of event-driven systems, and they tend to appear right after a release that looks perfectly innocent: one service starts reacting to an event by updating the service that produced it. The symptom is dramatic, a topic rate that climbs by two orders of magnitude in minutes, and the fix needs both quick action and a design change. Interviewers ask this to see whether we can recognise the pattern from the numbers, stop the damage safely, and prevent loops structurally rather than with a one-off patch. In this answer, we will trace the loop, stop it, fix the producer, fix the design, and add guards.

1Recognising the Loop

Two facts in the question give it away. The rate rises from 300 to 45,000 records per second and keeps climbing, so something is generating records faster than any user could. And the top keys are the same few thousand customer ids repeating, so the same customers are being updated over and over. Something is feeding the topic from the topic itself.

The release explains it. When the preferences service receives CustomerUpdated, it now calls the customer service to set a marketing flag. The customer service saves the customer, and its code publishes CustomerUpdated after every save. The preferences service receives that event and writes the flag again, and so on. Each cycle takes a few hundred milliseconds, and every customer touched by any update enters the loop and never leaves, so the number of looping customers grows with every normal update.

Step throughThe loop, one customer
Customer servicecustomer-eventsPreferences service
CustomerUpdated (id 42)
deliver CustomerUpdated
set marketing flag for 42
save customer 42, same values
CustomerUpdated (id 42) again
deliver again, and the cycle repeats

6 messages in order. Play them, or step through them one at a time.

Nothing in the loop checks whether anything changed, so it never stops on its own.

2Stopping It Now

The first goal is to break the cycle at its cheapest point. The preferences consumer is the step that turns an event into a new write, so we pause it or scale it to zero, or roll back the release. With Spring Kafka, a paused container keeps its group membership and offsets, so when we resume with fixed code it continues from where it stopped. The rate on customer-events should drop back to normal within seconds.

If the brokers are already struggling, with high produce latency or request queues growing, we can protect them with a produce quota on the customer service's principal, which throttles that client without touching others. Quotas are applied dynamically, without restarting anything.

Then we look at the blast radius. Every other consumer of customer-events received tens of millions of duplicate CustomerUpdated events. Most will only have redone idempotent work, but any consumer with side effects, such as sending a welcome email or calling a partner API on each update, may have done something many times. We check those consumers and their lag, and decide whether to skip the storm by moving a group's offsets past it, which is only safe if the events in that window carry no real changes the consumer needs.

3Fix the Producer: Publish Only Real Changes

The customer service publishes CustomerUpdated after every save, whether or not anything changed. That is the missing brake. If it compares the stored state before and after and publishes only when something differs, writing the same flag a second time produces no event, and the loop ends after one round.

Java
@Transactional
public void update(long id, CustomerChange change) {
Customer before = repo.findById(id).orElseThrow();
Customer after = before.apply(change);
if (after.equals(before)) {
return; // no change, no event: the loop stops here
}
repo.save(after);
outbox.add(new CustomerUpdated(id, after.version(), diff(before, after))); // published via the outbox
}

Notice that this also improves the event itself: it now carries the version and what changed, so consumers can ignore updates to fields they do not care about. On its own, though, this fix is fragile; a future change that writes a timestamp such as lastSeenAt on every update would bring the loop back.

4Fix the Design: One Owner per Field

The deeper problem is that the marketing flag is derived by the preferences service from customer data, and then written back into the customer service, the source of that data. Data now flows in a circle. The rule that prevents this is simple: each field has one owning service, and derived data lives in the service that derives it. The preferences service should keep the marketing flag in its own store and publish a PreferencesChanged event if others need it, rather than writing it into the customer record.

With that rule, data flows in one direction along each dependency: customer data flows from the customer service outward, preference data from the preferences service outward, and no service writes back to its source.

5Add Guards

Even with good design, loops can be introduced by accident, so we add guards that make them visible and limited. Every event carries a correlationId, the id of the original business action, and a causationId, the id of the event or request that directly caused it. Tracing tools can then draw the chain, and a chain of thousands of events with the same correlation id stands out immediately.

A hop-count header, incremented each time a service publishes an event in reaction to another, gives a hard stop: a consumer refuses or dead-letters events above a limit such as 10 and raises an alert. Finally, alerts on a sudden rate increase per topic, for example ten times the rate of the same hour last week sustained for five minutes, would have caught this incident within minutes of the release.

Guards and what they catch
GuardCatchesWhere
Publish only on real changeWrites of identical valuesProducer
One owner per fieldWrite-back of derived dataDesign review
correlationId, causationIdLong chains, in tracingEvery event
Hop-count limitAny runaway chainConsumers
Rate-increase alert per topicStorms after a releaseMonitoring

6Follow-up questions

Why does the rate keep climbing instead of staying constant?

Because new customers keep entering the loop. Every normal update to a customer starts a cycle for that customer, and no cycle ever ends, so the number of looping customers only grows until something stops it.

Is a hop-count header enough on its own?

No, it limits the damage but does not prevent the loop; each chain still runs up to the limit. It is a safety net behind the real fixes, which are publishing only on change and keeping data ownership one-directional.

How would you test for loops before a release?

Run an integration test that publishes one CustomerUpdated and asserts that the system settles: after a few seconds, no more events with that correlation id are produced. Contract reviews that check whether a new consumer writes back to the producer of the event it consumes also help.

7Conclusion

In this answer, we recognised an event loop from a climbing rate and repeating keys, and traced it to the preferences service writing back to the customer service, which republished CustomerUpdated on every save. We stopped it by pausing the consumer or rolling back, protected the brokers with a quota, and checked other consumers for side effects. We then fixed the producer to publish only real changes, fixed the design with one owner per field, and added correlation, causation and hop-count headers plus rate alerts.

What to say in the interviewAbout 80 seconds aloud

Open with

This is an event loop. The preferences service receives CustomerUpdated and writes the marketing flag back to the customer service; the customer service saves and publishes CustomerUpdated after every save; preferences receives it and writes again.

Then, if they want more

Every customer touched enters the loop and never leaves, which is why the rate keeps climbing and the top keys are the same customers repeating. To stop it now I would pause or scale the preferences consumer to zero, or roll back the release, which breaks the cycle immediately.

If the brokers are suffering, I would add a produce quota for the customer service's principal. Then I would check other consumers of customer-events for side effects, because they all received millions of duplicates. For the fix, first the producer should publish CustomerUpdated only when the stored state actually changed, so writing the same flag again produces nothing.

More importantly, each field should have one owning service, and derived data like the marketing flag should live in the service that derives it rather than being written back to the source.

Finally I would add guards: correlationId and causationId headers so tracing shows chains, a hop-count header that consumers refuse above a limit, and an alert on sudden rate increases per topic.

About this answer

Last updated
13 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.
Official documentation
Apache Kafka documentation
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 "The release made the preferences service write a marketing flag back to the customer...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-design/b60dd5dcb6/