Quick revision
The short answer
Repeated duplicate-processing bugs mean idempotency is left to each engineer's memory, so we make it part of how every service is built. Idempotency becomes a design-review requirement for every write API and every consumer with side effects; a shared library or starter provides the key filter, dedup table schema, consumer inbox and metrics; the API contract is standardised with the Idempotency-Key header, retention and conflict status codes; golden-path templates include replay tests; and duplicate incidents are tracked as a metric and reviewed for trends.
What to remember
In this answer, we turned repeated duplicate-processing bugs into an organisation-wide standard. Idempotency became a design-review requirement for every write API and side-effect consumer, a shared starter provides the key filter, dedup schema, inbox and metrics, one API contract defines the Idempotency-Key header, retention and conflict codes, golden-path templates include replay tests that prove idempotency, and duplicate incidents are tracked and reviewed as a trend.
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.
Repeated duplicate-processing bugs mean idempotency is left to each engineer's memory, so we make it part of how every service is built. Idempotency becomes a design-review requirement for every write API and every consumer with side effects; a shared library or starter provides the key filter, dedup table schema, consumer inbox and metrics; the API contract is standardised with the Idempotency-Key header, retention and conflict status codes; golden-path templates include replay tests; and duplicate incidents are tracked as a metric and reviewed for trends.
Why this question is asked
Double emails are embarrassing, double refunds cost money, and duplicated ledger entries can become a regulatory problem. When incident reviews keep finding the same root cause in different teams, fixing each bug is not enough; the organisation is missing a standard. Interviewers ask this at the fifteen-year level to see whether we can turn a recurring technical failure into a system of requirements, tools and measures that changes behaviour. In this answer, we will look at why these bugs keep happening, then build the standard in layers: a review requirement, a shared starter, a common API contract, tests in the templates, and a metric to know whether it works.
1Why the Same Bug Keeps Coming Back
Duplicates are not a bug in one place; they are a property of distributed systems. Clients retry after timeouts, message brokers redeliver after rebalances, outbox relays resend after crashes, and schedulers run a job twice after a failover. Any operation with a side effect, sending an email, refunding, writing a ledger entry, will eventually run twice unless something stops it.
In most organisations, stopping it is left to the engineer writing the handler. Some remember, some do not, and those who do each build their own dedup table with its own gaps. The incident reviews show the result: the same lesson learned five times by five teams. A standard turns that lesson into the default.
2Make It a Design-Review Requirement
The first layer is a rule: every write API and every message consumer with side effects must state how it is idempotent. In a design review, the team answers three questions: what identifies a duplicate, a client key, a message id or a business key such as the refund id; where the dedup record is stored and whether it commits in the same transaction as the side effect; and how long it is kept.
This works because the questions are concrete and quick to answer when there is a standard way to do it. A reviewer is not asking the team to invent something; they are asking which of the standard mechanisms it uses. Services that cannot answer get a clear action before launch rather than an incident after it.
3Provide the Mechanism as a Shared Starter
Requirements without tools produce slow, inconsistent work. So the platform team ships a Spring Boot starter that contains the pieces every team needs: a servlet filter or interceptor that implements the Idempotency-Key header for write endpoints, a dedup table schema delivered as a Flyway or Liquibase migration, a consumer inbox that wraps @KafkaListener handlers and records processed message ids in the same transaction, and Micrometer metrics for duplicates detected, conflicts and key reuse.
- Design reviewevery write API and side-effect consumer states its dedup
- API contractIdempotency-Key header, retention, status codes
- Shared starterkey filter, dedup schema, inbox, metrics
- Golden-path templatesreplay tests included by default
- Metric and reviewduplicate incidents tracked and trended
5 layers, from the top down. Step through them one at a time.
Notice that the annotations are a sketch of what such a starter could offer, not an existing library. The point is that the right behaviour costs a team one line. When the easy path is the safe path, adoption follows without enforcement.
4Standardise the API Contract
Partners and internal clients should see one behaviour across all our APIs. We define it once: write endpoints accept an Idempotency-Key header; keys are scoped to the authenticated client; keys are retained for 24 hours, or whatever we choose, and documented; a retry with the same key and the same request returns the original response; the same key with a different request returns 422; a retry while the original is still processing returns 409 with Retry-After.
Having one contract means client libraries can implement retries once, and support engineers can explain the behaviour without checking each service. It also stops a subtle source of bugs, where one service replays responses and another silently ignores duplicates without replying, and the caller's retry logic only works with one of them.
5Prove It With Replay Tests in the Templates
Teams believe their code is idempotent until a duplicate proves otherwise. So the golden-path project templates, the starting point for every new service, include tests that do the proving: an API test that sends the same request twice with the same key and asserts one side effect and two identical responses, and a consumer test that delivers the same message twice and asserts one database change and one email sent through a test double.
Existing services get the same tests added when they adopt the starter. A test that replays messages is cheap to write and catches the exact failure the incident reviews kept finding.
6Measure Whether It Works
Finally, we track duplicate incidents as a metric: the number of incidents per quarter whose root cause was duplicate processing, by team and by kind, emails, refunds, ledger entries. We review the trend in the regular reliability review. Alongside it, the starter's own metrics show how many duplicates are being caught in production, which is a useful reminder that the problem is real even when incidents fall.
If the incident count does not drop within two or three quarters, we look at where the remaining incidents come from: services not yet on the starter, side effects outside the database that the inbox cannot cover, or gaps in the standard itself, and adjust.
7Follow-up questions
How would you handle side effects that are outside our database, such as emails?
The inbox protects the decision to send, because the processed id and an outbox row for the email commit together. The email provider call itself can still repeat if the sender crashes after sending and before marking it sent. Where the provider supports an idempotency key or a message id, we pass a deterministic one. Where it does not, we accept a rare duplicate for low-cost actions like emails and make sure money-related actions always use a provider key.
What do you do about existing services that are not idempotent?
Prioritise by cost of a duplicate. Money and ledger flows adopt the starter first, with a deadline. Notification flows follow. Services with no side effects beyond idempotent upserts may need nothing. The incident data tells us where to start.
Does this slow teams down?
Slightly at first, while they adopt the starter. After that it saves time, because they no longer design dedup themselves, and every duplicate incident avoided saves days of investigation and customer remediation.
8Conclusion
In this answer, we turned repeated duplicate-processing bugs into an organisation-wide standard. Idempotency became a design-review requirement for every write API and side-effect consumer, a shared starter provides the key filter, dedup schema, inbox and metrics, one API contract defines the Idempotency-Key header, retention and conflict codes, golden-path templates include replay tests that prove idempotency, and duplicate incidents are tracked and reviewed as a trend.
Open with
I would treat this as a missing standard rather than a series of individual bugs, because duplicates are a normal property of distributed systems: clients retry, brokers redeliver, relays resend.
Then, if they want more
First, I would make idempotency a design-review requirement: every write API and every consumer with side effects must say what identifies a duplicate, where the dedup record lives and whether it commits with the side effect, and how long it is kept.
Second, I would make the safe path the easy path with a shared Spring Boot starter: an Idempotency-Key filter for endpoints, a dedup table schema as a migration, a consumer inbox that records processed message ids in the same transaction, and metrics for duplicates and conflicts.
Third, a single API contract across all services: the Idempotency-Key header, scoped per client, a documented retention period, the original response replayed for a matching retry, 422 when a key is reused with a different request and 409 while the first is still in progress.
Fourth, the golden-path templates include tests that replay the same request and the same message and assert one side effect, so teams prove it rather than assume it. Finally, I would track duplicate incidents per quarter as a metric, review the trend in reliability reviews, and prioritise money and ledger flows for adoption.
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
- Spring Cloud documentation, Resilience4j 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 "Incident reviews across your teams show repeated duplicate-processing bugs: double...": https://scrivio-interview-library.netlify.app/spring-boot/distributed-data/c139bfb563/