Backend Architecture
Idempotency and retries: multiple-choice review
Six questions that cut across the whole unit. None is a definition to recite — each is a decision you make under load, where the wrong call is a double charge, a lost event, or a self-inflicted outage.
Confirm you can connect the moving parts the lessons built toward: the idempotency key, the server-side state machine, jittered retries, the outbox + inbox composition, and the concurrency races that turn a tidy design into a duplicate side effect.
A mobile client fires a POST /charge, the response is lost, and it retries. On the retry it generates a fresh UUID for the Idempotency-Key header. What is the consequence and why?
A request arrives with Idempotency-Key K1. The server finds a row for K1 with status=in_progress. Why return 409 immediately instead of blocking until the first request finishes?
A service returns 503 with Retry-After: 30 during an outage. Across the fleet, which client behaviour keeps the recovering service alive?
A team must publish an 'order.created' event to Kafka whenever an order row commits to Postgres. Why is the outbox pattern correct where 'write Postgres then publish Kafka' is not?
Two requests carrying the same idempotency key reach the server within a millisecond of each other. The handler does SELECT-then-INSERT into the idempotency_keys table. What happens, and what is the fix?
A payment API uses Redis alone (async fsync, SETNX) as its idempotency store. A node crashes a millisecond after a SETNX, losing that key. What is the production-grade reading of this design?
The unit is one chain: the client retries with one key per operation; the server resolves that key to new / in-flight (409) / replay / mismatch (422) and stores the result atomically with ON CONFLICT; retries use full jitter, honour Retry-After, and live under a fleet retry budget; the outbox + at-least-once relay + inbox dedup turn the impossible dual-write into effectively-once; and the durable store must survive a crash, because losing a key is how a tidy design becomes a double charge. Every production failure in the unit — Stripe 2017, Knight Capital, AWS S3, GitHub 2018 — is at-least-once without idempotent consumers, or retries without jitter.