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)
-
Create cart
-
Add / remove items
-
Update quantity / options
-
View cart
-
Checkout (convert cart → order) with strong correctness guarantees
-
Fulfillment happens on the order
-
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?).