| Scale | Users / Orders per day | Key Changes |
|---|---|---|
| 100 users | ~200 orders/day | Single app server, single database instance, simple queue for order tasks |
| 10,000 users | ~20,000 orders/day | Multiple app servers behind load balancer, database read replicas, message queue for async processing |
| 1,000,000 users | ~2,000,000 orders/day | Sharded databases, distributed message queues, microservices for order stages, caching for product data |
| 100,000,000 users | ~200,000,000 orders/day | Global data centers, geo-distributed databases, event streaming platforms, advanced autoscaling, CDN for static content |
Order processing pipeline in HLD - Scalability & System Analysis
At small to medium scale, the database is the first bottleneck. It struggles to handle the high volume of order writes and reads, especially during peak times. The order processing queue can also become a bottleneck if not scaled properly, causing delays in order fulfillment.
- Database: Use read replicas to offload read traffic, implement sharding to distribute data across multiple servers, and optimize indexes.
- Application Servers: Horizontally scale by adding more servers behind a load balancer to handle increased user requests.
- Message Queues: Use distributed message queues like Kafka or RabbitMQ clusters to handle asynchronous order processing reliably.
- Caching: Cache frequently accessed data such as product details and user sessions using Redis or Memcached to reduce database load.
- CDN: Use Content Delivery Networks to serve static assets quickly and reduce load on origin servers.
- Microservices: Break down the order pipeline into smaller services (e.g., payment, inventory, shipping) to scale independently.
- Requests per second (RPS): At 1M orders/day, roughly 12 orders/second peak.
- Database QPS: Each order may generate multiple queries (write order, update inventory, read product info), estimate ~50 QPS at 1M orders/day.
- Storage: Assuming 1KB per order record, 2M orders/day = ~2GB/day storage growth.
- Bandwidth: Order data plus user interactions may require ~10-20 MB/s network throughput at peak.
Start by outlining the main components of the order pipeline. Discuss expected traffic and data growth. Identify the first bottleneck and explain why it occurs. Then propose targeted scaling solutions for each bottleneck. Use numbers to justify your choices and show understanding of trade-offs.
Your database handles 1000 QPS. Traffic grows 10x. What do you do first?
Answer: Add read replicas to distribute read load and implement caching to reduce database queries. Also consider connection pooling and query optimization before scaling vertically or sharding.
