Sub topic 16
Trade-offs: When Not to Use Event-Driven Architecture
This chapter assumes you know what events, brokers, topics and queues are. It also assumes you have met at-least-once delivery, idempotent consumers and eventual consistency from earlier chapters. Here you will weigh what the style costs against what it gives you.
What you gain
Event-driven architecture (EDA) buys you three things:
- Loose coupling. A producer publishes a fact and does not know who reacts to it. Adding a consumer needs no change to the producer.
- Independent scaling and failure isolation. A slow or crashed consumer does not block the producer. The broker buffers events until the consumer catches up.
- Fan-out. One event can drive many reactions, such as stock, receipts and analytics.
What you pay
Each gain has a matching cost.
| Benefit | Cost you accept |
|---|---|
| Decoupled services | Control flow is hidden. No single place shows the whole process. |
| Asynchronous work | Eventual consistency. Users may read stale data. |
| Broker buffering | A new piece of infrastructure to run, secure and monitor. |
| Reliable redelivery | Duplicates, so every consumer must be idempotent. |
| Independent consumers | Schema changes must stay compatible with consumers you may not know about. |
| Fan-out | Failures are harder to trace across services. |
The hidden control flow is the cost teams underestimate most. In a request/response system you can read a call stack. In an event system, the answer to "what happens when an order is placed?" is spread across every subscriber.
Signs that EDA is a poor fit
Consider a simpler design in these cases:
- The caller needs an immediate answer. Checking a password or computing a price is a query. A plain synchronous call is clearer. Do not wrap a request/response in two events just to look decoupled.
- You need strong consistency across steps. If two changes must be visible together, or a read must see the write just made, eventual consistency works against you. Keep them in one service and one database transaction.
- The system is small. One team, one deployable and a handful of features rarely justify a broker. A function call or an in-process event bus (like the one shown earlier in this tutorial) gives most of the structure at none of the operating cost.
- The team cannot operate it yet. Dead-letter queues, replays, tracing and schema governance take skill and tooling. Without them, failures go unnoticed.
- The process is a strict sequence with one owner. If step B always follows step A and one team owns both, a direct call is easier to read and debug.
A decision checklist
Ask these questions about each interaction, not about the whole system:
- Does the producer truly not care who reacts, or when?
- Can consumers tolerate delay, duplicates and stale reads?
- Is more than one consumer likely, now or soon?
- Can you trace an event end to end and replay failed ones?
If most answers are "no", use a direct call. Mixed designs are normal. Many systems use synchronous calls for queries and for steps that need an answer, and events for notifications and for work that can happen later.
Exercise
A team builds a checkout service. At checkout it must verify that the discount code is valid and show the final price to the user right away. It must also notify the warehouse, email a receipt and update analytics. Which of these should be events, and which should be direct calls? Give a reason for each group.
Show answer
Validating the code and computing the price should be a direct synchronous call (a query), because the user needs the answer immediately and a stale or delayed result would be wrong. Notifying the warehouse, sending the receipt and updating analytics should be events, because they can happen later, several independent consumers react to the same fact, and a failure in one should not block checkout or the others.