| Users / Components | 100 | 10,000 | 1,000,000 | 100,000,000 |
|---|---|---|---|---|
| Number of components communicating | 10-20 | 100-200 | 1,000-2,000 | 10,000+ |
| Messages per second through mediator | 100-500 | 5,000-10,000 | 100,000-200,000 | 10M+ |
| Mediator complexity | Simple centralized logic | Moderate, some async handling | High, needs concurrency control | Very high, requires distributed mediator |
| Latency impact | Low | Moderate | High | Very high without partitioning |
| Single point of failure risk | High | High | Critical | Critical |
Mediator pattern in LLD - Scalability & System Analysis
The mediator component becomes the first bottleneck as the number of components and messages grow. It must handle all communication, so CPU and memory usage spike. At medium scale (10,000+ components), the mediator's processing and message routing slows down, increasing latency. At large scale, the single mediator cannot handle the load, causing delays and failures.
- Horizontal scaling: Split the mediator into multiple instances, each handling a subset of components (partitioning). Use a directory or registry service to route messages to the correct mediator.
- Asynchronous messaging: Use message queues or event buses to decouple senders and receivers, reducing blocking and improving throughput.
- Caching: Cache frequent communication patterns or results to reduce mediator processing.
- Load balancing: Distribute incoming messages evenly across mediator instances.
- Sharding: Partition components by domain or function to reduce mediator load.
- Failover and redundancy: Use multiple mediator instances with health checks to avoid single points of failure.
- At 10,000 components sending 10 messages/sec each, mediator handles ~100,000 messages/sec.
- Assuming 1 KB per message, bandwidth needed is ~100 MB/s (800 Mbps).
- CPU load depends on message processing complexity; expect multiple cores or distributed mediators.
- Memory needed depends on message queue sizes and state; estimate several GBs for buffering.
- Storage for logs or message history grows with message volume; plan for scalable storage solutions.
Start by explaining the mediator pattern's role in centralizing communication. Discuss how it simplifies component interactions but can become a bottleneck as scale grows. Then, outline how you would identify bottlenecks (CPU, memory, latency) and propose scaling strategies like partitioning the mediator, asynchronous messaging, and load balancing. Always connect your solutions to the specific bottleneck you identified.
Your mediator handles 1,000 messages per second. Traffic grows 10x. What do you do first and why?
Answer: The mediator is the bottleneck. First, partition the mediator into multiple instances to distribute the load. This reduces CPU and memory pressure on a single mediator and improves throughput.
