0
0
Microservicessystem_design~10 mins

Message brokers (Kafka, RabbitMQ) in Microservices - Scalability & System Analysis

Choose your learning style9 modes available
Scalability Analysis - Message brokers (Kafka, RabbitMQ)
Growth Table: Message Brokers (Kafka, RabbitMQ)
ScaleUsers / MessagesWhat Changes?
100 users~100 msgs/secSingle broker instance handles traffic easily. Simple setup, low latency.
10,000 users~10,000 msgs/secBroker CPU and disk I/O increase. Need partitioning (Kafka) or multiple queues (RabbitMQ). Start monitoring lag.
1 million users~1 million msgs/secSingle broker insufficient. Must use cluster with multiple nodes. Network bandwidth and storage grow. Partitioning and replication critical.
100 million users~100 million msgs/secMassive cluster with multi-region deployment. Data retention and archival strategies needed. Network and storage bottlenecks dominate.
First Bottleneck

The first bottleneck is usually the broker's disk I/O and network bandwidth. Message brokers write messages to disk for durability and replicate them across nodes. As message volume grows, disk throughput and network capacity limit performance before CPU or memory.

Scaling Solutions
  • Partitioning/Sharding: Split topics or queues into partitions to distribute load across multiple broker nodes.
  • Clustering: Use broker clusters to increase throughput and provide fault tolerance.
  • Replication: Replicate partitions for high availability and data durability.
  • Caching: Use consumer-side caching or intermediate caches to reduce load on brokers.
  • Load Balancing: Distribute producers and consumers evenly across partitions and brokers.
  • Compression: Compress messages to reduce network and storage usage.
  • Retention Policies: Archive or delete old messages to manage storage growth.
  • Multi-region Deployment: Deploy brokers closer to users to reduce latency and network load.
Back-of-Envelope Cost Analysis
  • At 10,000 msgs/sec, assuming 1 KB per message, storage grows by ~864 GB/day (10,000 * 1 KB * 86,400 seconds).
  • Network bandwidth needed: 10,000 msgs/sec * 1 KB = ~10 MB/s (80 Mbps), manageable on 1 Gbps links.
  • At 1 million msgs/sec, storage grows ~86 TB/day, requiring distributed storage and archival.
  • Broker nodes handle ~5,000-10,000 msgs/sec each; so 1 million msgs/sec needs ~100-200 nodes.
  • Replication doubles or triples storage and network needs depending on replication factor.
Interview Tip

Start by clarifying message volume and durability needs. Identify bottlenecks like disk I/O and network early. Discuss partitioning and clustering as primary scaling methods. Mention trade-offs between consistency, availability, and latency. Use real numbers to justify scaling steps.

Self Check

Your message broker handles 1,000 QPS. Traffic grows 10x to 10,000 QPS. What do you do first?

Answer: Add partitions or queues and scale out the broker cluster horizontally to distribute load. This addresses disk I/O and network bottlenecks before upgrading hardware.

Key Result
Message brokers scale by partitioning and clustering to distribute disk and network load; disk I/O and network bandwidth are first bottlenecks as message volume grows.