| Scale | Users | Orders per Second | Menu Items | Data Size | System Changes |
|---|---|---|---|---|---|
| Small | 100 users | 10 orders/sec | 100 items | MBs | Single server, simple DB, no caching |
| Medium | 10,000 users | 1,000 orders/sec | 1,000 items | GBs | DB read replicas, caching menu, load balancer |
| Large | 1,000,000 users | 50,000 orders/sec | 10,000 items | TBs | Sharded DB, distributed cache, multiple app servers |
| Very Large | 100,000,000 users | 5,000,000 orders/sec | 100,000+ items | Petabytes | Microservices, global CDN, event-driven architecture, data partitioning |
Restaurant, Menu, Order classes in LLD - Scalability & System Analysis
At small scale, the database is the first bottleneck because it handles all order writes and menu reads. As users grow, the DB CPU and disk I/O limit throughput. The application server can handle more connections, but DB queries slow down.
- Database Read Replicas: Use replicas to serve menu reads and reduce load on primary DB.
- Caching: Cache menu data in memory (e.g., Redis) to reduce DB hits.
- Horizontal Scaling: Add more app servers behind a load balancer to handle more users.
- Sharding: Partition orders by restaurant or region to distribute DB load.
- Event-Driven Architecture: Use message queues to process orders asynchronously at large scale.
- CDN: Use CDN to serve static menu images and reduce bandwidth.
- At 10,000 orders/sec, DB needs to handle ~10,000 writes/sec plus reads.
- Menu data size grows with items; caching reduces DB storage cost.
- Network bandwidth must support order data and menu images; estimate 1 Gbps for medium scale.
- Storage for orders grows linearly; archiving old orders reduces DB size.
Start by describing the system components and their roles. Then discuss expected traffic and data growth. Identify the first bottleneck logically (usually DB). Propose scaling solutions step-by-step, explaining why each helps. Mention trade-offs and cost considerations. Keep answers structured and clear.
Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Add read replicas and implement caching for menu data to reduce DB load. Also, consider connection pooling and optimize queries before scaling vertically.