| Users / Requests | What Changes in Layers |
|---|---|
| 100 users | Simple layer interactions; single instance; minimal caching; direct DB calls from infrastructure layer |
| 10,000 users | Introduce caching in infrastructure; separate read/write layers; add load balancer; start using async processing in use cases |
| 1,000,000 users | Horizontal scaling of interface and infrastructure layers; database sharding; CQRS pattern for read/write separation; event-driven communication between layers |
| 100,000,000 users | Microservices splitting by bounded contexts; global distributed data stores; advanced caching/CDN; eventual consistency; multi-region deployment |
Clean Architecture layers in LLD - Scalability & System Analysis
At small scale, the infrastructure layer's database access becomes the bottleneck due to synchronous calls and limited DB capacity.
As users grow, the interface layer's servers hit CPU and memory limits handling requests and orchestrating layers.
At large scale, network bandwidth and data consistency across layers become critical bottlenecks.
- Database Layer: Add read replicas, use connection pooling, implement caching (Redis/Memcached).
- Application Layer: Horizontal scaling with load balancers; use asynchronous messaging between layers.
- Interface Layer: Use CDNs for static content; implement API gateways for routing and throttling.
- Architecture: Apply CQRS and event-driven patterns to decouple layers and improve scalability.
- Data: Shard databases by user or feature; use eventual consistency where possible.
- At 10,000 users, expect ~5,000 QPS; a single DB instance can handle this with caching.
- At 1,000,000 users, ~500,000 QPS may require 50+ DB replicas and sharding.
- Network bandwidth: 1 Gbps supports ~125 MB/s; large user base needs multi-gigabit or distributed networks.
- Storage grows with data retention; consider tiered storage and archiving for old data.
Start by explaining the Clean Architecture layers and their responsibilities.
Discuss how each layer can become a bottleneck as users grow.
Propose scaling solutions layer by layer, focusing on database, application, and interface.
Use real 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 and implement caching to reduce direct DB load before scaling application servers.