Design a food delivery system
CoinbaseSoftware Engineer · Technical ScreenLast updated
This problem tests your ability to design a distributed, real-time logistics platform, focusing on high-concurrency order placement, real-time courier tracking, and transactional integrity during payment and dispatch.
Problem Statement
Design a food delivery system (similar to UberEats or DoorDash) that connects customers, restaurants, and couriers. The system must handle high-concurrency order placements, real-time location updates for couriers, and the matching of orders to available couriers.
Requirements
Functional
- Customers can browse restaurants and place orders.
- Restaurants can manage their menu and receive order notifications.
- Couriers can accept delivery requests and update their real-time location.
- The system must dispatch orders to the nearest available courier.
Non-Functional
- High availability and scalability during peak hours (e.g., Friday evenings).
- Low-latency real-time updates for courier location tracking.
- Strong consistency for payment processing and order status transitions.
Your Task
Describe the high-level architecture, key services, and database schema. Provide details on how you would handle:
- The real-time courier tracking feature (e.g., how to handle frequent location updates).
- The dispatching algorithm (how to find a courier efficiently).
- Handling payment idempotency so a user is not charged twice for the same order.
Design Constraints
- Assume 100,000 concurrent active orders and 50,000 active couriers.
- Focus on the choice between SQL and NoSQL for different services (e.g., Order service vs. Tracking service).
- Explain how you would ensure the system remains resilient if the notification service goes down.
Hints
Hint 1
Consider using a geospatial database or a quad-tree index to store courier locations to optimize the 'nearest courier' search.
Hint 2
Separate the read-heavy path of menu browsing from the write-heavy path of order placement and state transitions.
Hint 3
Use a message queue or event-driven architecture to decouple the order status update from downstream processes like restaurant notifications or customer push notifications.
Follow-up questions
- How would you handle the 'Thundering Herd' problem if thousands of customers attempt to order from the same restaurant at the exact same moment?
- If a courier's phone battery dies mid-delivery, how would you design the system to handle the state transition and re-assignment of the order?
- How would you design a batching system to allow a single courier to pick up orders from multiple restaurants in a single trip?
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.