0
0
Microservicessystem_design~12 mins

Synchronous vs asynchronous communication in Microservices - Architecture Patterns Compared

Choose your learning style9 modes available
System Overview - Synchronous vs asynchronous communication

This system demonstrates two common ways microservices communicate: synchronous and asynchronous. Synchronous communication means services wait for a response before continuing, like a phone call. Asynchronous communication means services send messages and continue without waiting, like sending emails.

Key requirements include reliable message delivery, scalability, and clear separation of communication styles.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  +---------------------------+
  |                           |
  v                           v
Service A (Sync)          Service B (Async)
  |                           |
  v                           v
Service C (Sync)          Message Queue
  |                           |
  v                           v
Database                  Service C (Async)
                            |
                            v
                         Database
Components
User
user
Initiates requests to the system
Load Balancer
load_balancer
Distributes incoming requests evenly to API Gateway instances
API Gateway
api_gateway
Routes requests to appropriate microservices
Service A (Sync)
service
Handles synchronous requests and calls Service C synchronously
Service C (Sync)
service
Processes synchronous requests and accesses the database
Service B (Async)
service
Handles asynchronous requests and sends messages to the queue
Message Queue
message_queue
Stores messages for asynchronous processing by Service C
Service C (Async)
service
Consumes messages from the queue and updates the database asynchronously
Database
database
Stores persistent data accessed by services
Request Flow - 19 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayService A (Sync)
Service A (Sync)Service C (Sync)
Service C (Sync)Database
DatabaseService C (Sync)
Service C (Sync)Service A (Sync)
Service A (Sync)API Gateway
API GatewayLoad Balancer
Load BalancerUser
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayService B (Async)
Service B (Async)Message Queue
Message QueueService B (Async)
API GatewayLoad Balancer
Load BalancerUser
Message QueueService C (Async)
Service C (Async)Database
Failure Scenario
Component Fails:Message Queue
Impact:Asynchronous messages cannot be delivered, causing delays or loss of async processing. Synchronous calls remain unaffected.
Mitigation:Use message queue replication and persistent storage to prevent message loss. Implement retry mechanisms and alerting.
Architecture Quiz - 3 Questions
Test your understanding
Which component ensures that asynchronous messages are stored until processed?
AAPI Gateway
BMessage Queue
CLoad Balancer
DService A
Design Principle
This architecture clearly separates synchronous and asynchronous communication paths. Synchronous calls wait for immediate responses, suitable for real-time needs. Asynchronous calls use a message queue to decouple services, improving scalability and resilience by allowing processing to happen later without blocking the user.