0
0
Microservicessystem_design~10 mins

Synchronous vs asynchronous communication in Microservices - Scaling Approaches Compared

Choose your learning style9 modes available
Scalability Analysis - Synchronous vs asynchronous communication
Growth Table: Synchronous vs Asynchronous Communication
Users / RequestsSynchronous CommunicationAsynchronous Communication
100 usersDirect request-response calls work well; low latency; simple error handlingMessage queues lightly used; delays minimal; easy to manage
10,000 usersIncreased latency; some request timeouts; servers start to block waiting for responsesMessage queues handle bursts; decoupling improves resilience; some message backlog possible
1 million usersHigh latency; many blocked threads; servers overwhelmed; cascading failures possibleQueues scale with partitions; consumers scale horizontally; eventual consistency accepted; better fault tolerance
100 million usersSystem likely fails; synchronous calls cause bottlenecks; scaling very costlyDistributed queues with sharding; multiple consumer groups; complex monitoring; high throughput achievable
First Bottleneck

In synchronous communication, the first bottleneck is the application server's thread pool and CPU waiting on remote calls, causing blocked resources and increased latency.

In asynchronous communication, the bottleneck shifts to the message broker's throughput and storage capacity, as it must handle high message volumes reliably.

Scaling Solutions
  • Synchronous: Use load balancers and horizontal scaling of services to increase concurrent handling; implement timeouts and retries; introduce caching to reduce calls.
  • Asynchronous: Scale message brokers horizontally with partitioning and replication; add more consumers to process queues in parallel; use backpressure and rate limiting; implement dead-letter queues for failures.
  • For both, use circuit breakers to prevent cascading failures and improve system resilience.
Back-of-Envelope Cost Analysis

Assuming 1 million users generating 10 requests per second:

  • Total requests: 10 million requests/sec.
  • Synchronous servers: Each server handles ~3000 concurrent requests; need ~3300 servers to handle load.
  • Message broker: Needs to handle 10 million messages/sec; a single Kafka cluster can handle ~1 million messages/sec, so at least 10 clusters or partitions needed.
  • Storage: Message retention for 24 hours at 1 KB per message = ~864 GB storage.
  • Network bandwidth: 10 million requests/sec * 1 KB = ~10 GB/s (~80 Gbps), requiring high network capacity.
Interview Tip

Start by defining synchronous and asynchronous communication clearly. Discuss pros and cons related to latency, coupling, and fault tolerance. Identify bottlenecks at different scales. Propose scaling strategies specific to each mode. Use real numbers to justify your approach. Show understanding of trade-offs and system resilience.

Self Check

Your database handles 1000 QPS. Traffic grows 10x. What do you do first?

Answer: Introduce caching and read replicas to reduce load on the database. If still insufficient, consider sharding the database to distribute data and queries across multiple instances.

Key Result
Synchronous communication bottlenecks at server thread blocking under high load, while asynchronous communication shifts bottlenecks to message broker throughput and storage, enabling better scalability with proper partitioning and consumer scaling.