Design a Food Delivery Cart
UberSoftware Engineer · OnsiteLast updated
This question tests the ability to design a distributed, low-latency, and fault-tolerant shopping cart service for a high-concurrency food delivery platform.
Problem Statement
Design a Cart Service for a food delivery platform similar to Uber Eats. Users should be able to add, update, remove, and view items in their cart. The system must support thousands of concurrent requests, maintain state across devices, and ensure high availability.
Functional Requirements
- Add items to a cart (with customizations/add-ons).
- Update item quantities or remove items.
- Retrieve the current state of the cart (including price calculations and restaurant availability).
- Persist the cart so that it is accessible when a user logs in from a different device.
Non-Functional Requirements
- Low latency for cart updates and retrieval.
- High availability: Users must be able to edit their cart even if some internal services are momentarily overloaded.
- Consistency: The cart price must reflect the current menu prices provided by the restaurant service.
Deliverables
- High-level architecture diagram or description.
- API design (endpoints for add, update, remove, and get cart).
- Data schema (what fields are stored in the database).
- Strategies for handling stale data (e.g., if a menu item price changes or becomes unavailable after it was added to the cart).
- Trade-offs between strong consistency and eventual consistency.
Hints
Hint 1
Consider whether a relational database (like MySQL) or a NoSQL key-value store (like Redis or DynamoDB) is better suited for storing transient, high-churn cart state.
Hint 2
Think about how to handle the 'price drift' problem—should you calculate prices on-the-fly when the user views the cart or at the time of checkout?
Hint 3
Address how you would handle race conditions if a user clicks 'Add to Cart' multiple times in rapid succession from different devices.
Follow-up questions
- How would you optimize the system if a user has a very large cart with complex nested customizations?
- What changes would you make if the platform needs to support 'multi-restaurant' carts, where items from different restaurants are held in separate containers?
- How would you integrate a real-time inventory check to prevent a user from checking out an item that just sold out?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.