0
0
LLDsystem_design~10 mins

Adapter pattern in LLD - Scalability & System Analysis

Choose your learning style9 modes available
Scalability Analysis - Adapter pattern
Growth Table: Adapter Pattern
UsersChanges in System
100 usersSingle adapter instance handles requests; simple direct calls; low latency.
10,000 usersMultiple adapter instances needed; increased load on adaptee; possible latency increase.
1,000,000 usersAdapters become bottleneck; need load balancing; adaptee service may need scaling; caching considered.
100,000,000 usersAdapters fully distributed; sharding of adaptee services; asynchronous communication; heavy caching and CDN usage.
First Bottleneck

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.

Scaling Solutions
  • 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.
Back-of-Envelope Cost Analysis

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.
Interview Tip

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.

Self Check

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.

Key Result
The adaptee service behind the adapter is the first bottleneck as user load grows; scaling requires distributing adapter instances, scaling adaptee services, and adding caching or asynchronous processing.