Make Order Placement Idempotent Across Flaky Mobile Retries
Last updated: November 29, 2026
Quick Overview
Implement a wrapper around an order placement function so that a client retry carrying the same idempotency key returns the original result instead of creating a second order, rejects reuse of a key with a different cart, and lets a failed attempt be retried.
Swiggy
November 29, 20260
0
0 solved
Implement a wrapper around an order placement function so that a client retry carrying the same idempotency key returns the original result instead of creating a second order, rejects reuse of a key with a different cart, and lets a failed attempt be retried.
Many Swiggy users order on patchy mobile data, so the app retries Place Order and payment calls, and a duplicate order means two kitchens cooking and a refund. The screen checks whether you understand idempotency keys, request fingerprints, in-flight state and expiry.
What the Interviewer Expects
- Scopes keys per user so two users cannot collide
- Stores a fingerprint of the request and rejects mismatched reuse
- Distinguishes pending, completed and failed attempts
- Releases the key when the attempt fails before committing
- Expires keys after a TTL
- Explains what changes when this moves to a shared store like Redis or DynamoDB
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How would you implement the pending state across many app servers?
- The order was created but the response was lost and the server crashed before saving it. How do you recover?
- How long should keys live, and what does that cost in storage at Swiggy's order volume?
- How do idempotency keys interact with the payment gateway's own idempotency?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
place(user_id, key, body) must: create at most one order per (user, key); return the same response on a retry; raise if the key is reused with a different body; return a retry-later error while the ...
High-Level Design
A map from (user_id, key) to [fingerprint, state, response, expires_at]. The fingerprint is a SHA-256 of the canonical JSON of user and body. The lock is held only to read and write the record, ne...