Sub topic 16
Trade-offs: when not to use event-driven architecture
This chapter assumes you know the earlier material: events versus commands, brokers, topics and queues, delivery guarantees, idempotent consumers, eventual consistency, dead-letter queues, the outbox pattern, and sagas. It does not teach them again. It asks whether you should pay for them at all.
Event-driven architecture (EDA) is a good fit for some problems and a poor one for others. Most failures come from adopting it by default, not from implementing it badly.
What you pay for
Each benefit of EDA comes with a cost. The costs are easy to underestimate because they appear later, in operations and debugging.
| Benefit | Cost it brings |
|---|---|
| Producers do not know their consumers | No single place shows who reacts to an event. The flow of a business process is spread across services. |
| Consumers fail independently | Failures are silent. A stuck consumer produces no error for the caller. |
| Brokers absorb load spikes | You must run, monitor and size the broker, and watch consumer lag. |
| Fan-out to many consumers | Every consumer needs idempotency, retries and a dead-letter policy. |
| Services stay available without each other | Data is eventually consistent, and users can see stale state. |
Compare this with a plain HTTP call. The caller sends a request, waits, and gets a result or an error. EDA replaces that with a message that something happened and no direct answer.
Signals that EDA is a poor fit
The caller needs an answer now
If a user clicks "Pay" and must see success or failure on the next screen, the work is request/response. You can wrap it in events, but then you build a reply channel, correlation IDs and timeouts to imitate what a synchronous call gives you for free.
A rule of thumb: if the producer needs the consumer's result to decide what to do next, you have a command with a reply, not a fact being published. Use a direct call.
You need strong consistency across the data
Eventual consistency means two stores may disagree for a while. Some domains cannot tolerate that window:
- Checking and decrementing a balance that must never go negative.
- Allocating the last unit of scarce inventory.
- Enforcing a uniqueness rule such as one active booking per seat.
These need one transaction in one database, or a single owner of the data that decides synchronously. Sagas can compensate for failures, but a compensation is a new action, not an undo. A customer may already have seen "confirmed" before the saga reverses it.
The system is small
With one team, one deployable and one database, a function call or a database transaction is simpler and faster. A broker adds a new server to operate, a new failure mode, and new test setups. Adding events to a small system often gives you the distributed-system costs without the scale that justifies them.
The team lacks the operational tooling
EDA moves problems from compile time and request time to runtime. You need:
- Tracing that follows a correlation ID across services.
- Metrics for consumer lag, retry counts and dead-letter queue depth.
- A process for inspecting and replaying dead-lettered messages.
- Schema governance, so an event change does not break unknown consumers.
If you cannot see these, an outage looks like "some orders never shipped" with no trail to follow.
The workflow is a strict, linear sequence
If step B must always follow step A, and nobody else cares, publishing an event between them adds indirection and no decoupling. A simple orchestrated function, or a single queue between the two steps, is clearer.
Failure modes specific to EDA
These are the problems teams report most often. Each one is a consequence of a design choice from earlier chapters.
- Hidden coupling. Consumers depend on the exact fields and meaning of an event. The producer does not know this. A "harmless" field rename breaks a consumer you forgot existed. Decoupling in deployment does not remove coupling in meaning.
- Event chains that nobody can follow. Service A emits an event, B reacts and emits another, C reacts to that. The business process exists only in the heads of the people who built it. This is sometimes called choreography sprawl. Past a few steps, an explicit orchestrator or a saga with a visible state is easier to reason about.
- Duplicate and out-of-order delivery. At-least-once delivery and partitioned ordering are guarantees you work around. Every consumer must handle repeats, and ordering holds only within a key.
- Poison messages. One malformed event can block a partition if the consumer retries forever. You need a retry limit and a dead-letter queue, and someone who reads that queue.
- Unbounded lag. A slow consumer does not slow the producer. The backlog grows quietly until data is hours old.
- Hard debugging. There is no single stack trace. You reconstruct the story from logs in several services.
- Testing gaps. Unit tests pass for each service while the interaction between them is wrong. You need contract tests for event schemas and some end-to-end tests with a real or realistic broker.
A decision checklist
Ask these questions about each interaction, not about the system as a whole. A system can mix styles.
| Question | If the answer is yes | If the answer is no |
|---|---|---|
| Does the producer need a result before continuing? | Prefer a synchronous call. | Events are an option. |
| Is it acceptable for consumers to act seconds or minutes later? | Events are an option. | Prefer a synchronous call. |
| Do several independent consumers care about the same fact? | Publish/subscribe fits well. | A direct call or one queue may be enough. |
| Must the data be consistent across services at all times? | Keep it in one transaction or one owner. | Eventual consistency is an option. |
| Can the team operate a broker and trace flows? | EDA is viable. | Defer it or use a managed service. |
| Is the load bursty, or are consumers slower than producers? | A broker as a buffer helps. | Little benefit from buffering. |
Two or more answers that point away from events is a strong sign to stay synchronous for that interaction.
A mixed design
A common, sensible shape keeps the critical path synchronous and uses events for side effects.
import uuid
from datetime import datetime, timezone
class FakeBroker:
def __init__(self):
self.messages = []
def publish(self, event):
self.messages.append(event)
inventory = {"sku-1": 1}
orders = {}
broker = FakeBroker()
def place_order(order_id, sku):
# Synchronous and strongly consistent: the caller needs the answer now.
if inventory.get(sku, 0) < 1:
return {"status": "rejected", "reason": "out of stock"}
inventory[sku] -= 1
orders[order_id] = {"sku": sku, "status": "placed"}
# Asynchronous: others react later, and the caller does not wait.
broker.publish({
"id": str(uuid.uuid4()),
"type": "order.placed",
"version": 1,
"occurredAt": datetime.now(timezone.utc).isoformat(),
"data": {"orderId": order_id, "sku": sku},
})
return {"status": "placed"}
print(place_order("o-1", "sku-1"))
print(place_order("o-2", "sku-1"))
print(len(broker.messages), "event published")The stock check is a direct decision with an immediate answer, so it stays synchronous. Receipts, analytics and shipping notifications do not affect the answer, so they hang off the event. In a real system you would write the order and the event in one transaction with the outbox pattern, not publish directly after the change.
Moving toward events gradually
You do not have to choose once. A practical path:
- Start with synchronous calls and a modular codebase.
- Move side effects with no result dependency to a queue, such as emails or search indexing.
- Add publish/subscribe when a second or third consumer appears for the same fact.
- Introduce schemas, versioning and tracing before the number of consumers grows.
- Reach for sagas, event sourcing or CQRS only when a concrete problem demands them.
Summary of the decision
Use events when the producer reports a fact, does not need a reply, and several consumers may care. Accept eventual consistency, duplicate delivery and extra operations as the price. Stay synchronous when the caller needs an answer, when data must be consistent right now, or when the system is small enough that a function call does the job. Mixing both is normal, and often the best result.
Exercise
A checkout service must charge a card and show the customer "paid" or "declined" on the same page. Teammates propose publishing a payment.requested event and having the payment service reply with payment.completed. Give two reasons this may be a poor use of events, and describe a better split between synchronous and asynchronous work.
Show answer
First, the caller needs the result immediately, so the event design needs correlation IDs, a reply channel and timeouts to imitate a synchronous call, which adds complexity with no decoupling benefit. Second, a reply that arrives late or never leaves the customer on an unclear screen, and the system must handle duplicates and retries of a charge. A better split is to call the payment service synchronously, with an idempotency key so retries do not double-charge, and return the result directly. After the payment succeeds, publish payment.completed (ideally through an outbox) so receipts, fulfilment and analytics react asynchronously.
Exercise
Your team has one service, one database, and four developers. A colleague wants to introduce a broker "so we are ready to scale." List three costs this adds today and one condition that would justify it later.
Show answer
Costs: a broker to deploy, secure, monitor and pay for; new failure modes such as duplicates, lag and poison messages, which every consumer must handle; and harder debugging and testing across asynchronous steps. A justifying condition is, for example, a second independent consumer that needs the same fact, a need to buffer bursts that the database cannot absorb, or work that must be split into separately deployed services owned by different teams.