Design an Idempotent Ride Request Endpoint With Idempotency Keys
Last updated: November 29, 2026
Quick Overview
Riders on flaky networks tap Request and the app retries, sometimes creating duplicate trips. Design and implement idempotency-key handling for POST ride requests, including concurrent duplicates, key reuse with a different body, and crashed attempts.
Uber
November 29, 20260
0
0 solved
Riders on flaky networks tap Request and the app retries, sometimes creating duplicate trips. Design and implement idempotency-key handling for POST ride requests, including concurrent duplicates, key reuse with a different body, and crashed attempts.
Duplicate ride requests cost Uber twice: two drivers dispatched and an unhappy rider. This API design question checks whether you can define idempotency semantics precisely, including in-flight requests and body mismatches, rather than just saying 'add a unique key'.
What the Interviewer Expects
- Have the client generate a key per user intent and send it on every retry
- Scope keys per user and store a fingerprint of the request body
- Return the stored response for completed duplicates
- Return a conflict for in-flight duplicates and for key reuse with a different body
- Handle crashed attempts with a lease and decide what happens when the create fails
- Expire keys after a retention window
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
- What status code should a duplicate in-flight request get, and how should the client react?
- How do you make the trip creation and the idempotency record atomic in a database?
- How long should keys be kept, and what if a retry arrives after that?
- How would you apply the same pattern to the cancel endpoint?
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
POST /v1/ride_requests with header Idempotency-Key. Same key and same body: exactly one trip, every retry gets the same response. Same key, different body: client bug, reject with 422. Duplicate w...
High-Level Design
Store rows keyed by (user_id, key) with fingerprint, state (IN_PROGRESS or DONE), lease_until, and the saved response. begin() atomically inserts the row or classifies the duplicate. After t...