Quick revision
The short answer
I would make idempotency part of the platform rather than a habit. The event platform standards require a unique event id on every event and idempotent handling in every consumer; a shared library or template provides tested deduplication and transaction handling; the shared test kit redelivers every message twice in tests; replay and chaos exercises check real consumers with duplicates; and design review asks about idempotency for each new consumer.
What to remember
In this answer, we saw that idempotency across forty teams cannot rely on memory. We made it reliable with layers: platform standards that require unique event ids and idempotent consumers, a shared library that gets deduplication and transactions right once, a test kit that delivers every message twice by default, replay and chaos exercises in staging, and an idempotency question in design review. Metrics on skipped duplicates and incidents show whether the practice is holding.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would make idempotency part of the platform rather than a habit. The event platform standards require a unique event id on every event and idempotent handling in every consumer; a shared library or template provides tested deduplication and transaction handling; the shared test kit redelivers every message twice in tests; replay and chaos exercises check real consumers with duplicates; and design review asks about idempotency for each new consumer.
Why this question is asked
With forty teams, any practice that depends on everyone remembering will fail somewhere, and duplicate processing failures are quiet: a customer charged twice, a counter that drifts, an email sent three times. Each team may know the theory perfectly, but under deadline pressure the dedup check is the first thing skipped. Interviewers ask this leadership question to see whether we can turn a technical rule into something the organisation does by default. In this answer, we will look at why awareness is not enough, then go through the layers that make it reliable: standards, a shared library, tests, exercises and review, and finally how to measure whether it is working.
1Why Awareness Is Not Enough
Idempotent consumers are well understood: at-least-once delivery means duplicates, so every consumer must produce the same effect when a message arrives twice. The problem at scale is not knowledge but consistency. Each team writes its own dedup code, some get the transaction boundary wrong, some forget cleanup, some have no event id to deduplicate on because the producer never set one.
Duplicates are also rare in normal operation, so the bug can sit unnoticed for months until a rebalance storm or a broker failover redelivers thousands of messages at once. So the goal is to make the correct behaviour the easy path and to detect the incorrect one before production. I think of it as several layers, each catching what the previous one missed.
- Platform standardevery event has a unique id; consumers must be idempotent
- Shared librarytested dedup and transaction handling
- Shared test kitevery test delivers each message twice
- Replay and chaos exercisesduplicates in staging, on purpose
- Design reviewidempotency question for each new consumer
- Metricsduplicates detected, incidents from double processing
6 layers, from the top down. Step through them one at a time.
Each layer catches what the one above it missed.
2Standards: Unique Ids and an Explicit Rule
The event platform standard, the document every producer and consumer follows, would say two things. Every event carries a unique, stable event id in a standard header or envelope field, set once by the producer and kept on resend. And every consumer must be idempotent, with its technique stated in its documentation: deduplication table, version check, natural idempotency, or idempotency keys for external calls.
The first rule can be enforced automatically. The shared producer library sets the id, and the schema registry or a CI check rejects event schemas without the envelope. Without a reliable id, the rest of the effort fails, so this is the foundation.
3A Shared Library With Tested Transaction Handling
The most common bug in hand-written deduplication is the transaction boundary: the id recorded in one transaction and the side effect in another, or the offset committed before the database. So the platform team provides a small library, for example a Spring Boot starter, that does it correctly once and is tested heavily.
Notice what the team writes: only the business logic. The id extraction, the insert-or-skip, the transaction, the metric and the cleanup come from the starter, written once by people who think about these details every day. Teams that need a version check or natural idempotency instead can opt out with a documented reason, but the default does the right thing. A template repository for new consumers includes the starter, so new services start correct.
4Tests That Deliver Every Message Twice
The shared test kit, the test utilities every team already uses for Kafka tests, changes its default behaviour: every message published in a consumer test is delivered twice, and the test's assertions must still pass. A test that checks 'balance is 150 after one PaymentReceived of 50' now fails if the consumer adds 100.
Making duplicate delivery the default, rather than an extra test teams must remember, is the important part. A team must actively turn it off, and that shows up in review.
5Replay and Chaos Exercises
Unit and integration tests prove the code; exercises prove the running system. Regularly, in staging, we replay the last hour of a topic to its consumers, or we force consumer group rebalances and broker restarts during load. Then we compare business totals, balances, order counts, emails sent, with what they should be. A consumer that double counts shows up as a mismatch, and the owning team gets a specific finding to fix.
These exercises also test the operational side: dashboards, alerts and the dedup tables' growth under replay. Running them quarterly, with results shared across teams, keeps the practice visible.
6Design Review and Measuring Whether It Works
In the design review for a new consumer, one standard question is 'what happens when this message arrives twice, and when it arrives late?' The answer names the technique. It takes two minutes, and it catches the external side effects, emails and payment calls, that the library cannot handle without an idempotency key.
Finally, we measure. The starter's metric shows how many duplicates are being skipped, which proves duplicates really happen and the protection works. We count incidents caused by double processing per quarter, and track how many consumers use the starter or have a documented alternative. If incidents fall and coverage rises toward forty teams, the practice is working; if not, the metrics tell us which layer to strengthen.
7Follow-up questions
What about teams in other languages?
The standard and the event id are language neutral. For the library, we provide equivalents for the main languages or a documented reference implementation with conformance tests. The duplicate-delivery test idea and the replay exercises apply to every consumer regardless of language.
Will mandatory duplicate delivery slow down test suites?
Slightly, since each message is processed twice, but consumer tests are usually dominated by container startup, not processing. The cost is small compared with finding a double-charge bug in production.
How do you handle existing consumers?
We run the replay exercise against them first, which finds the ones that are not idempotent. Those get fixed with the starter, prioritised by business risk, starting with consumers that move money or stock.
8Conclusion
In this answer, we saw that idempotency across forty teams cannot rely on memory. We made it reliable with layers: platform standards that require unique event ids and idempotent consumers, a shared library that gets deduplication and transactions right once, a test kit that delivers every message twice by default, replay and chaos exercises in staging, and an idempotency question in design review. Metrics on skipped duplicates and incidents show whether the practice is holding.
Open with
I would turn it from something teams remember into something the platform does by default. First the standard: every event carries a unique, stable event id in the envelope, set by the shared producer library and checked by the schema registry, and every consumer must be idempotent with its technique documented.
Then, if they want more
Second, a Spring Boot starter for consumers that handles deduplication correctly: it reads the id, inserts it into a processed table in the same transaction as the business logic, skips duplicates, emits a metric and cleans up. Teams write only their business code, and the template for new services includes it.
Third, the shared test kit delivers every message twice by default, so a consumer that is not idempotent fails its own tests. Fourth, regular replay and chaos exercises in staging, replaying topics and forcing rebalances, then checking business totals.
Fifth, design review always asks what happens when a message arrives twice or late, which catches external side effects like emails and payments that need idempotency keys. And I would measure duplicates skipped and double-processing incidents, to see whether it is working and where to strengthen it.
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.
- Official documentation
- Apache Kafka documentation, Spring for Apache Kafka reference
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 "How would you make idempotent consumers a reliable practice across 40 teams rather than...": https://scrivio-interview-library.netlify.app/spring-boot/event-driven-patterns/6f65d10090/