0
0
Microservicessystem_design~12 mins

Request-response vs event-driven in Microservices - Architecture Patterns Compared

Choose your learning style9 modes available
System Overview - Request-response vs event-driven

This system compares two common communication styles in microservices: request-response and event-driven. Request-response is a direct, synchronous way where one service asks another and waits for a reply. Event-driven is asynchronous, where services emit events and others react without waiting.

Key requirements include clear communication, scalability, and fault tolerance.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  +---------------------+---------------------+
  |                     |                     |
Request-Response     Event-Driven          Event Bus
Service A            Service B             (Message Queue)
  |                     |                     |
Database A           Database B            Service C
  |                     |                     |
Cache A              Cache B               Database C
Components
User
client
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 services and handles authentication
Request-Response Service A
service
Handles synchronous requests and responses
Database A
database
Stores data for Service A
Cache A
cache
Speeds up data retrieval for Service A
Event-Driven Service B
service
Emits events asynchronously for other services to consume
Event Bus (Message Queue)
message_queue
Decouples services by delivering events asynchronously
Service C
service
Consumes events from the event bus and processes them
Database B
database
Stores data for Service B
Cache B
cache
Speeds up data retrieval for Service B
Database C
database
Stores data for Service C
Request Flow - 9 Hops
UserLoad Balancer
Load BalancerAPI Gateway
API GatewayRequest-Response Service A
Request-Response Service ACache A
Cache ARequest-Response Service A
Request-Response Service AUser
Event-Driven Service BEvent Bus (Message Queue)
Event Bus (Message Queue)Service C
Service CDatabase C
Failure Scenario
Component Fails:Event Bus (Message Queue)
Impact:Events cannot be delivered to consuming services, causing delays or loss of asynchronous processing.
Mitigation:Use message queue replication and persistence to avoid data loss and enable failover. Services can retry sending events.
Architecture Quiz - 3 Questions
Test your understanding
Which component handles synchronous communication in this architecture?
AService C
BEvent Bus (Message Queue)
CRequest-Response Service A
DCache B
Design Principle
This architecture shows how request-response enables immediate, synchronous communication suitable for direct user interactions, while event-driven design allows services to communicate asynchronously, improving scalability and decoupling. Both styles have distinct components and failure modes, requiring different handling strategies.