Design cart management lifecycle service
Company: Uber
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Technical Screen
## Scenario
You are designing the backend for an on-demand delivery app (restaurants and grocery). Users can create a cart, modify items from multiple devices, and then checkout to create an order that will be fulfilled.
The prompt is intentionally vague. Drive the requirements, scope, and assumptions through clarifying questions.
## Core workflow (cart lifecycle)
1. Create cart
2. Add / remove items
3. Update quantity / options
4. View cart
5. Checkout (convert cart → order) with strong correctness guarantees
6. Fulfillment happens on the order
7. Cart closes after checkout, or expires if abandoned
## Functional requirements
- Create an active cart for a user and a merchant/store.
- Mutations:
- Add item
- Remove item
- Update quantity
- Update selected options (e.g., size, toppings)
- Read:
- Fetch active cart (commonly by user + merchant)
- Fetch cart details (header + full list of items)
- Checkout:
- Convert an active cart into an order exactly once.
- Validate correctness (prices/options, cart not stale, cart not already checked out, etc.).
## Non-functional requirements
- Correctness/consistency is the top priority, especially at checkout.
- Low latency and high availability are important, but cannot compromise correctness at checkout.
- Concurrency: multiple devices may update the same cart at the same time.
## Scale assumptions
- Up to **10M concurrent orders** (use this to derive rough QPS and storage assumptions).
## Data modeling expectations
Propose a data model and indexing strategy that supports typical queries and correctness.
Examples of typical queries to support:
- Get a user’s active cart quickly (often by `(user_id, merchant_id)` or `(user_id, status)`).
- Get all items by `cart_id`.
- At checkout, read cart + items efficiently and validate consistency.
Also discuss how you would handle:
- Optimistic concurrency control (e.g., `version` on cart header and conditional writes).
- If asked: finer-grained conflicts (e.g., can two devices modify different items without conflict?).
Quick Answer: This question evaluates system design and backend engineering competencies, focusing on data modeling, indexing strategy, concurrency control, transactional correctness, and scalability for a multi-device cart lifecycle and one-time checkout.