| Scale | Users | Rooms | Bookings per day | System Changes |
|---|---|---|---|---|
| Small | 100 | 500 | 200 | Single server, simple database, no caching |
| Medium | 10,000 | 50,000 | 10,000 | Load balancer, read replicas, caching for availability checks |
| Large | 1,000,000 | 500,000 | 100,000 | Sharded database, distributed cache, asynchronous booking processing |
| Very Large | 100,000,000 | 10,000,000 | 10,000,000 | Multi-region deployment, event-driven architecture, CDN for static content |
Hotel, Room, Booking classes in LLD - Scalability & System Analysis
At small to medium scale, the database is the first bottleneck. It handles all booking transactions and availability checks. As users and bookings grow, the database CPU and I/O get overwhelmed, causing slow responses and possible booking conflicts.
- Database Read Replicas: Offload read queries like room availability checks to replicas to reduce load on the primary database.
- Caching: Use in-memory caches (e.g., Redis) for frequently accessed data like room availability to reduce database hits.
- Horizontal Scaling: Add more application servers behind a load balancer to handle increased user requests.
- Database Sharding: Split booking data by hotel or region to distribute load across multiple database instances.
- Asynchronous Processing: Use message queues to handle booking confirmation and payment processing asynchronously to improve responsiveness.
- Multi-region Deployment: Deploy services closer to users to reduce latency and improve availability.
- At 10,000 bookings/day (~0.12 QPS), a single database can handle the load easily.
- At 100,000 bookings/day (~1.2 QPS), database load increases; read replicas and caching become necessary.
- Storage: Each booking record ~1 KB, so 10 million bookings need ~10 GB storage, manageable with modern databases.
- Network bandwidth: Assuming 1 KB per booking request/response, 100,000 bookings/day require ~100 MB data transfer, well within 1 Gbps network capacity.
Start by describing the system components and their roles (Hotel, Room, Booking). Then discuss expected traffic and data growth. Identify the first bottleneck (usually the database). Propose scaling solutions step-by-step, explaining why each is needed. Use real numbers to justify your choices. Finally, mention trade-offs and monitoring strategies.
Your database handles 1000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?
Answer: Add read replicas to distribute read queries and reduce load on the primary database. Also, implement caching for frequent read operations like room availability checks. This reduces database CPU and I/O usage, preventing overload.