What if your system could work on many things at once without waiting for answers?
Event-driven vs request-driven in Microservices - When to Use Which
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine a busy restaurant where every customer must personally ask the chef for each dish, waiting for the chef to finish before ordering the next. This is like a request-driven system where every action waits for a direct response.
This approach causes long waits and confusion when many customers order at once. The chef gets overwhelmed, mistakes happen, and the kitchen slows down. Similarly, request-driven systems struggle with delays and tight coupling between services.
Event-driven design changes this by letting customers place orders on a board. The chef picks up orders as they come, cooks them independently, and notifies when ready. Services communicate by sending events, allowing work to happen asynchronously and independently.
response = service.call(data) process(response)
service.emit(event)
// continue without waiting
onEvent(eventResponse, handle)This approach enables systems to handle many tasks smoothly at the same time, improving speed, flexibility, and fault tolerance.
Online shopping platforms use event-driven systems to update inventory, notify shipping, and send customer alerts without waiting for each step to finish before starting the next.
Request-driven systems wait for direct replies, causing delays under load.
Event-driven systems use asynchronous messages to work independently and faster.
Choosing event-driven design helps build scalable, resilient microservices.
Practice
Solution
Step 1: Understand event-driven communication
Event-driven systems use messages or events to notify other services asynchronously, without waiting for a reply.Step 2: Compare with request-driven communication
Request-driven systems make direct calls and wait for responses, which is synchronous communication.Final Answer:
Services communicate by sending messages without waiting for immediate responses. -> Option AQuick Check:
Event-driven = asynchronous messaging [OK]
- Confusing event-driven with synchronous calls
- Thinking event-driven requires shared databases
- Assuming event-driven always uses batch processing
Solution
Step 1: Identify request-driven behavior
Request-driven means a service calls another and waits for the response before moving on.Step 2: Eliminate other options
Options A and D describe asynchronous or event-driven behavior; Service A writes data to a shared database for Service B to read later. describes shared database, not direct calls.Final Answer:
Service A calls Service B and waits for a response before proceeding. -> Option DQuick Check:
Request-driven = synchronous call and wait [OK]
- Mixing event-driven with request-driven
- Thinking shared database equals request-driven
- Confusing batch processing with request-driven calls
Solution
Step 1: Analyze asynchronous event processing
Service A sends an event and does not wait; Service B processes independently.Step 2: Identify the advantage
This allows Service B to handle events at its own speed without blocking Service A, improving scalability and decoupling.Final Answer:
Service B can process events at its own pace without blocking Service A. -> Option AQuick Check:
Asynchronous event-driven = decoupled processing [OK]
- Assuming sender waits for receiver
- Confusing shared database with event broker
- Expecting immediate response in event-driven
Solution
Step 1: Identify problem with synchronous calls
High latency and failures occur because the caller waits and depends on the callee's immediate response.Step 2: Apply event-driven solution
Switching to asynchronous events decouples services, allowing retries and better fault tolerance without blocking.Final Answer:
Replace synchronous calls with asynchronous events and retries. -> Option BQuick Check:
Event-driven improves reliability by decoupling [OK]
- Just increasing timeout doesn't fix failures
- Shared database doesn't solve latency issues
- Batching synchronous calls still blocks
Solution
Step 1: Analyze requirements for fast feedback and flexibility
Fast user feedback needs synchronous validation; flexible processing benefits from asynchronous events.Step 2: Combine architectures appropriately
Request-driven calls provide immediate validation; event-driven updates allow inventory to process independently and scale.Final Answer:
Use request-driven calls for order validation and event-driven for inventory updates. -> Option CQuick Check:
Mix sync for speed + async for flexibility [OK]
- Using only event-driven delays user feedback
- Using only request-driven limits scalability
- Batch processing is too slow for online orders
