Design an Idempotent Action API
Design a durable command API that produces one business effect and one recoverable outcome across duplicate clicks, retries, races, and lost responses.
Problem statement
For this exercise, assume an authenticated client submits one supported state-changing action against one target resource. Each command carries a caller-scoped idempotency key retained for 24 hours.
An identical retry must return the original action identity and outcome; reusing a key with a different canonical request fingerprint must return a conflict from the submit operation.
A client that loses a response can query the stored accepted, rejected, or pending outcome, or learn that the action is unknown, instead of creating another action. Outcome lookup is entity-only and does not report a request-relative fingerprint conflict.
An acknowledged action and its idempotency outcome must survive a process restart and a single availability-zone failure. Authentication already exists. Exclude browser-side debouncing, payment processing, inventory allocation, cross-resource transactions, and arbitrary workflow orchestration.
What to build
- An authenticated client can submit one supported action for one target and receive a stable action identity and explicit outcome.
- Concurrent or later retries with the same caller, key, and canonical request return the original outcome without another business effect.
- Reusing a caller-scoped idempotency key for a different canonical request returns an explicit conflict and changes no action state.
- A client can query the authoritative outcome after a timeout or lost response and distinguish pending from unknown work.
At scale
- Sustain 20,000 command attempts per second, including bursts of 2,000 attempts per second against one target resource.
- Return a healthy synchronous command or replay response within 200 milliseconds at p99.
- Retain caller-scoped idempotency outcomes for 24 hours.
- Every acknowledged action and idempotency outcome must survive a process restart and one availability-zone failure.