System Design AI

Idempotency: Follow-Up Questions Interviewers Ask, With Answers

Idempotency shows up whenever a service must survive retries, network glitches, or partial failures. Interviewers ask about it because it reveals how you think about consistency, error handling, and client expectations. They also use it to gauge whether you can turn a vague guarantee into a concrete implementation that scales.

When you mention idempotency, the interviewer will dig deeper: they want to see if you know the difference between safe and unsafe operations, whether you can pick the right storage primitive, and how you would monitor the system once it’s live. Below are nine typical follow-up questions, ordered from the most basic probe to the hardest, each answered as a candidate might respond.

1. What does idempotency mean in the context of an API?

I would say that an idempotent API guarantees that making the same request multiple times yields the same effect as making it once. For example, a DELETE /users/123 call should remove the user whether it’s sent once or ten times. The response may differ (e.g., 200 vs 404), but the state of the system after the first successful call does not change on subsequent retries.

2. How do you make a write operation idempotent?

The usual pattern is to include a client-generated idempotency key, like a UUID, with each request. The service stores the key alongside the result in a durable table (e.g., DynamoDB). On a retry, the service looks up the key; if it exists, it returns the stored result instead of executing the write again. This approach works for operations that are otherwise non-idempotent, such as creating a payment record.

3. Where should the idempotency key be stored and for how long?

I would store the key in a low-latency, highly available store that supports conditional writes—DynamoDB or a PostgreSQL table with a unique constraint works well. Retention depends on the use case; for a payment API I’d keep keys for at least 24 hours to cover typical client retries, but I’d also set a TTL to purge old entries and keep storage costs low.

4. What are the trade-offs of using a separate idempotency table versus embedding the key in the primary data?

A separate table isolates the idempotency logic, keeping the main data model clean and allowing independent TTL policies. However, it adds an extra read/write per request, increasing latency by roughly 1-2 ms on average. Embedding the key in the primary table eliminates that extra hop but couples the lifecycle of the key to the business entity, which can be problematic if you need to purge keys sooner.

5. How do you handle idempotency for non-deterministic side effects, like sending emails?

I would make the side effect itself idempotent or guard it with the same key. For email, the service first claims the key with a conditional write that records it as 'sending'; only the request that wins the claim sends the email and then marks the key done, and a concurrent retry that loses the claim skips sending. If the process dies after sending but before marking the key, a later retry can still send twice; passing the same key to an email provider that deduplicates on it closes that gap, and otherwise a rare duplicate is the accepted cost.

6. What happens if the idempotency store itself fails during a retry?

If the store is unavailable, I would fall back to a safe default: return a 503 Service Unavailable and let the client retry later. Because the original request may have already been applied, the client must be prepared to handle a possible duplicate. In practice, I design the system so the store is highly available (multi-AZ replication) to keep that failure rare.

7. How would you test idempotency in a staging environment?

I’d write integration tests that issue the same request thousands of times with the same idempotency key and assert that the state changes only once. For example, I could create a user with a POST /users call, repeat it 5,000 times, and then verify that exactly one row exists in the users table. Load-testing tools can also simulate concurrent retries to catch race conditions.

8. Can you make a read-only operation idempotent, and does it matter?

Read-only operations are already idempotent because they don’t change state. A retry may return different data, newer or from a stale cache, but that does not break idempotency, which is about the effect on state, not identical responses. If the client needs to know whether the data changed between calls, I’d return a version token or ETag.

9. How does idempotency affect scaling and cost at massive traffic volumes?

At scale, the extra write to the idempotency store can become a bottleneck. For a service handling 100 million requests a day (≈1,200 req/s), a single DynamoDB table with provisioned throughput of 10,000 RCU and 5,000 WCU easily absorbs the load. If traffic grows to billions of requests a day (tens of thousands of writes a second), the table still needs no manual sharding: DynamoDB spreads random UUID keys across partitions on its own, so the work is raising capacity (or using on-demand mode) and keeping the TTL short to bound storage, balancing cost against the risk of duplicate side effects.

A senior-level answer typically covers the basic mechanisms, trade-offs, and a concrete example. A staff-level answer goes further: it discusses operational concerns, scaling strategies, and how to monitor the idempotency layer (e.g., latency histograms, error rates) to ensure it doesn’t become a hidden bottleneck. The staff response also ties the discussion back to product-level impact, such as how duplicate billing errors could affect revenue and user trust.

How to practice this

  1. Read the free worked design, Idempotency Keys. It is a single diagram (client, API, key store and the operation, with the retry and claim paths) with a write-up of how the pattern works, what it costs, and how it fails.
  2. On paper or a whiteboard, sketch your own API that includes the idempotency store, note where you’d place TTLs, and label the retry path. With Pro ($10/month), you can draw it on the practice canvas instead.
  3. Rehearse answering the nine questions out loud, timing yourself and focusing on concrete numbers and trade-offs.

Questions people ask

What is the difference between idempotent and safe operations?

Idempotent operations guarantee the same final state after repeated calls, while safe (read-only) operations never modify state. All safe operations are idempotent, but not all idempotent operations are safe.

Do all HTTP methods need idempotency?

RFC 7231 defines GET, HEAD, PUT, DELETE, and OPTIONS as idempotent. POST is not, so we usually add an explicit idempotency key for POST endpoints that perform writes.

Can a database transaction alone provide idempotency?

A transaction makes a single request atomic, but it doesn’t stop duplicate effects across retries. An external idempotency key is still required to detect and suppress repeats.

How do you monitor idempotency failures?

Track metrics like "idempotency_key_miss" and "idempotency_store_error". Alert if the miss rate rises, which may indicate missing keys on client retries or an under-provisioned store.