| Users | Changes in System |
|---|---|
| 100 users | Single adapter instance handles requests; simple direct calls; low latency. |
| 10,000 users | Multiple adapter instances needed; increased load on adaptee; possible latency increase. |
| 1,000,000 users | Adapters become bottleneck; need load balancing; adaptee service may need scaling; caching considered. |
| 100,000,000 users | Adapters fully distributed; sharding of adaptee services; asynchronous communication; heavy caching and CDN usage. |
Adapter pattern in LLD - Scalability & System Analysis
The adaptee service behind the adapter is the first bottleneck. As all adapter calls translate to adaptee calls, the adaptee's capacity limits overall throughput.
- Horizontal scaling: Add more adapter instances behind a load balancer to distribute client requests.
- Adaptee scaling: Scale the adaptee service horizontally or vertically to handle increased load.
- Caching: Cache adaptee responses in adapters or a shared cache to reduce repeated calls.
- Asynchronous processing: Use message queues to decouple adapters from adaptee for heavy workloads.
- Sharding: Partition adaptee data/services to reduce load per instance.
Assuming each adapter instance handles ~2000 concurrent requests:
- At 10,000 users: ~5 adapter instances needed.
- At 1,000,000 users: ~500 adapter instances; adaptee must handle ~1M QPS.
- Storage depends on caching size; e.g., 1MB cache per adapter instance = 500MB at 500 instances.
- Network bandwidth: 1M QPS * average 1KB request/response = ~1GB/s bandwidth needed.
Start by explaining the adapter's role as a translator between incompatible interfaces. Then discuss how scaling affects both the adapter and adaptee. Identify the adaptee as the bottleneck and propose solutions like horizontal scaling, caching, and asynchronous processing. Use concrete numbers to show understanding of capacity limits.
Your database handles 1000 QPS. Traffic grows 10x. What do you do first?
Answer: Add read replicas and implement caching to reduce direct database load before scaling vertically or sharding.