Sub topic 5
Event notification versus event-carried state transfer
This chapter assumes you know what an event, a producer, a consumer and a broker are from the earlier chapters. It also assumes you are comfortable with HTTP APIs and basic database reads and writes. The question here is how much data an event should carry, because that choice shapes coupling, availability and consistency.
Two ways to describe the same fact
Suppose an order service publishes order.placed. Two designs are common.
- Event notification. The event says that something happened and carries little else, usually an ID. A consumer that needs details calls the producer's API.
- Event-carried state transfer (ECST). The event carries the data consumers need. Consumers keep their own local copy and never call the producer.
Martin Fowler describes these as separate patterns because their consequences differ even though both use the same broker and the same publish step.
Event notification
A notification event is thin:
{
"id": "6f1c2d9e-3b7a-4c55-9d0e-1a2b3c4d5e6f",
"type": "order.placed",
"version": 1,
"occurredAt": "2026-11-26T11:00:00Z",
"data": { "orderId": "o-1" }
}The consumer reacts by fetching what it needs:
orders_db = {
"o-1": {"order_id": "o-1", "customer_id": "c-9", "total_cents": 4599},
}
def get_order(order_id):
# Stands in for GET /orders/{id} on the order service.
return orders_db.get(order_id)
def on_order_placed(event):
order = get_order(event["data"]["orderId"])
if order is None:
print("order no longer exists, skipping")
return
print("invoice", order["customer_id"], order["total_cents"])
on_order_placed({"type": "order.placed", "data": {"orderId": "o-1"}})Strengths:
- Events are small and rarely change shape, so schema versioning is easy.
- The producer stays the single source of truth. The consumer reads current data, not a snapshot.
- Access control stays in one place. The API decides who may see an order, so sensitive fields never travel through the broker.
Weaknesses:
- Runtime coupling returns. If the order service is down, the consumer cannot finish its work, even though the broker delivered the event.
- Callback load. Ten consumers produce ten calls per event. A burst of events becomes a burst of API traffic, and the producer must absorb it.
- Time-of-read ambiguity. The consumer sees the order as it is now, not as it was when the event fired. If the order was cancelled in between, the invoice consumer sees a cancelled order.
- Hidden dependency. The producer's API becomes a contract that the event schema does not show.
Event-carried state transfer
An ECST event includes the state consumers need:
{
"id": "0b8e5a1c-7d42-4f0a-8c63-52f1e9a7b310",
"type": "customer.changed",
"version": 1,
"occurredAt": "2026-11-26T11:02:00Z",
"data": {
"customerId": "c-9",
"revision": 7,
"email": "[email protected]",
"shippingCountry": "NL"
}
}Each consumer maintains a local replica built from these events:
customers = {}
def on_customer_changed(event):
data = event["data"]
current = customers.get(data["customerId"])
if current is not None and current["revision"] >= data["revision"]:
return # stale or duplicate event: keep the newer state
customers[data["customerId"]] = {
"email": data["email"],
"shipping_country": data["shippingCountry"],
"revision": data["revision"],
}
newer = {"data": {"customerId": "c-9", "revision": 7,
"email": "[email protected]", "shippingCountry": "NL"}}
older = {"data": {"customerId": "c-9", "revision": 6,
"email": "[email protected]", "shippingCountry": "DE"}}
on_customer_changed(newer)
on_customer_changed(older) # arrives late, must not overwrite
print(customers["c-9"]["email"]) # [email protected]The revision field matters. Brokers can redeliver events and, across partitions, deliver them out of order. Without a revision or version check, a late event overwrites newer state. The check also makes the handler idempotent for this kind of update, which connects to the delivery-guarantee chapters.
Strengths:
- Availability. The consumer works while the producer is down, because it reads its own copy.
- Low latency and no callback load. Reads are local.
- Autonomy. The consumer can shape its replica for its own queries, keeping only the fields it needs.
Weaknesses:
- Staleness. The replica lags behind the source. How far depends on broker lag and consumer speed.
- Duplicated data. Every consumer stores its own copy, and each must be correct.
- Schema coupling. The payload is now a public data contract. Adding, renaming or removing fields affects every replica.
- Bootstrapping. A new consumer has no history. It needs a snapshot, a replay of a compacted topic, or a one-time export from the producer.
- Privacy and deletion. Personal data copied into many stores must also be removed from all of them. Events should carry only the fields consumers have a reason to hold.
Comparing the flows
| Aspect | Event notification | Event-carried state transfer |
|---|---|---|
| Payload | ID and metadata | Data consumers need |
| Consumer needs producer at handling time | Yes | No |
| Data freshness | Current at read time | As fresh as the last processed event |
| Load on producer | One callback per consumer per event | None from consumers |
| Schema as a contract | Small | Large |
| Where the data lives | One place | One copy per consumer |
| Sensitive data in the broker | Minimal | Must be chosen deliberately |
| Bootstrapping a new consumer | Trivial | Needs snapshot or replay |
Choosing between them
Ask these questions about each event type, not about the whole system:
- Must the consumer keep working when the producer is down? If yes, lean toward state transfer.
- Does the consumer need the data now, or the data as of the event? An invoice usually needs the state at placement time, so a snapshot in the event is correct. A "refresh the dashboard" signal needs only a nudge.
- How many consumers react, and how often? Many consumers and high event rates make callbacks expensive.
- How sensitive is the data? If only a few consumers may see it, keep it behind an API and publish a notification.
- How large is the state? A 2 MB document in every event strains the broker. Many brokers cap message size at about 1 MB by default.
A third option sits between the two. An event can carry a subset of state: the fields that most consumers need plus the ID for everything else. This is often the most practical design. Consumers handle the common case locally and call back only for rare details.
Common mistakes
- A "notification" that always triggers a callback. If every consumer must fetch the same details, the event is thin for no benefit. Move the common fields into the payload.
- State transfer without a version. Without a revision, timestamp or sequence number, a replica cannot reject stale events. Wall-clock timestamps are weaker than a per-entity revision, because clocks differ across machines.
- Treating the replica as the source of truth. Consumers should not write back to their copy of another service's data. They also should not make decisions that require strict freshness, such as checking available credit.
- Putting the whole database row in the event. The payload then mirrors the producer's internal tables, and any internal change becomes a breaking change. Design the payload as a public contract.
- Forgetting deletes. A replica never learns about a removal unless the producer publishes something like
customer.deleted. Otherwise the replica keeps the record forever. - No answer for new consumers. Decide up front how a replica gets its initial state.
Exercise
A shipping service needs the customer's delivery address when an order is placed. The customer service publishes thin customer.changed events containing only a customer ID. Shipping calls the customer API after every event, and it stops processing orders whenever the customer service is down. Which change addresses this, and what must the shipping service add to stay correct?
Show answer
Switch customer.changed to event-carried state transfer, with the address fields in the payload, so shipping keeps a local replica and no longer calls the customer API. To stay correct, shipping needs a per-customer revision check to ignore stale or duplicate events, a way to bootstrap the replica for the initial load (snapshot or replay), and handling of a delete event. It must also accept that the address may be slightly stale.