Practice/Databricks/Design an Online Bookstore
Design an Online Bookstore
System DesignOptional
Problem Statement
Design a comprehensive food delivery system that connects restaurants, delivery drivers, and hungry customers through a mobile and web platform. The system must handle restaurant discovery, real-time menu browsing, order placement, payment processing, driver assignment, live order tracking, and delivery confirmation.
Think of platforms like DoorDash, Uber Eats, or Grubhub operating in a major metropolitan area. Your system needs to coordinate thousands of concurrent orders across hundreds of restaurants while maintaining accurate estimated delivery times, preventing order conflicts, and optimizing driver utilization. The challenge lies in managing a three-sided marketplace where restaurant capacity, driver availability, and customer demand must be balanced in real time while keeping all parties informed of order status through the entire fulfillment lifecycle.
Key Requirements
Functional
- Restaurant Discovery & Menu Browsing -- customers search for restaurants by cuisine, location, price range, and ratings; view menus with real-time pricing and availability
- Order Placement & Cart Management -- customers build multi-item orders, apply promotions, select delivery addresses, and complete checkout with payment
- Driver Assignment & Routing -- system assigns available drivers to orders based on proximity, capacity, and efficiency; provides turn-by-turn navigation
- Real-Time Order Tracking -- all parties see live order status updates from preparation through delivery, including driver location on a map
- Multi-Party Notifications -- restaurants receive order details, drivers get pickup instructions, customers get ETAs; all receive status changes instantly
Non-Functional
- Scalability -- support 100K concurrent users, 10K orders per minute during peak lunch/dinner hours, with 50K active drivers across multiple cities
- Reliability -- 99.9% uptime for order placement; zero payment double-charges; graceful degradation when driver GPS or restaurant systems are temporarily unavailable
- Latency -- menu browsing under 200ms p95; order confirmation within 1 second; location updates reflected within 3 seconds
- Consistency -- eventual consistency acceptable for menu updates and driver locations; strong consistency required for order state transitions and payment processing
What Interviewers Focus On
Based on real interview experiences, these are the areas interviewers probe most deeply:
1. Real-Time Location Tracking and Updates
The system must efficiently broadcast driver locations to potentially thousands of customers tracking their orders while avoiding excessive database writes and stale data. Interviewers want to see how you handle high-frequency position updates without overwhelming your backend or draining driver phone batteries.
Hints to consider:
- Use WebSockets or Server-Sent Events for pushing location updates to customers rather than polling
- Implement spatial indexing with geohashing or quadtrees to quickly find nearby drivers and restaurants
- Consider batching and sampling location updates (e.g., only write to database every 10 seconds or when position changes significantly)
- Leverage Redis GeoSpatial data structures for fast proximity queries during driver assignment
2. Order State Management and Workflow Orchestration
An order transitions through multiple states (placed, confirmed, preparing, ready, picked up, in transit, delivered) involving coordination between customer, restaurant, and driver. Interviewers expect you to handle partial failures, timeouts, and race conditions without losing orders or creating inconsistent states.
Hints to consider:
- Model order state as an explicit state machine with valid transitions and guard conditions
- Use a saga pattern or orchestration service to manage the multi-step workflow across services
- Implement idempotency keys to safely retry payment and order creation requests
- Store state transitions with timestamps in an append-only event log for auditability and debugging
3. Driver Assignment and Matching Algorithms
Efficiently pairing available drivers with new orders is critical for delivery time and system throughput. The naive approach of scanning all drivers for every order doesn't scale, and interviewers want to see intelligent strategies for matching based on location, capacity, and predicted delivery time.
Hints to consider:
- Maintain an in-memory index of available drivers partitioned by geographic zones (geohash prefixes)
- Consider driver capacity for stacked orders (picking up multiple orders on one route)
- Balance between greedy assignment (closest driver) and global optimization (better overall efficiency)
- Implement reservation timeouts so unaccepted assignments expire and get reassigned automatically
4. Menu and Restaurant Data Consistency
Restaurant menus change frequently (items out of stock, price updates, hours changes), but you can't afford to show stale data or let customers order unavailable items. Interviewers look for caching strategies that balance freshness with read performance.
Hints to consider:
- Cache menu data aggressively with short TTLs (1-5 minutes) or cache invalidation webhooks from restaurant systems
- Separate frequently-changing data (availability, pricing) from static content (descriptions, images) for different caching strategies
- Validate item availability at checkout time before charging to catch race conditions
- Use eventual consistency with version numbers or timestamps to detect stale cached data
5. Payment Processing and Financial Transactions
The system handles money flowing between customers, the platform, restaurants, and drivers with strict requirements around accuracy, idempotency, and security. Interviewers expect discussion of authorization holds, settlement timing, refunds, and preventing double charges.
Hints to consider:
- Separate authorization (hold funds) from capture (actually charge) to handle order cancellations
- Use idempotency keys tied to order IDs to prevent duplicate charges if requests are retried
- Store payment intent IDs and transaction records in your database for reconciliation and auditing
- Handle partial refunds for missing items or delivery issues through a separate refund workflow
Suggested Approach