Engineering Labs

Event notification vs event-carried state transfer

A car plant's yard run by three services that never call each other, so the two main event styles can be compared side by side in readable logs, under normal load, a rush and a shift change.

The question#

How much should an event carry? A thin event that only says something happened keeps contracts small but sends receivers back to ask; a fat event that carries the state lets receivers work alone but couples them to its shape. This lab uses both in one system, where each is the right choice for a different reason.

The setup#

Every new car passes final inspection and must be driven to the parking lot. Parking management decides its slot, or sends it to a buffer zone when the lot is full; when a truck takes a car away, the lot moves the longest-waiting car in at once. The three services share no database and never call one another: each knows only RabbitMQ and the event contract.

EventPublished byCarriesStyle
final-inspection-passedfinal-inspectionthe whole carevent-carried state transfer
parking-allocatedparking-managementthe slot and the whole carevent-carried state transfer
buffer-zone-allocatedparking-managementthe buffer position and the whole carevent-carried state transfer
parking-vacatedparkingonly the slotevent notification
buffer-rebalancedparkingonly the VIN and the slotevent notification

What it shows#

  • State transfer removes runtime coupling. The parking lot learns everything about an arriving car from parking-allocated alone; it has never heard of final inspection and does not need it running.
  • Notification is enough when the receiver owns the state. Parking management keeps its own record of the slots, so “slot B2 is free” is all it needs.
  • Consistency comes from shared events, not a shared database. Each service builds its own state from what it hears; the demo’s closing counts reconcile (every car inspected was either given a slot or a buffer place, and every buffered car was later moved into a slot).
  • New consumers need no change to publishers. A dashboard or a shipping schedule would bind its own queue.

Reproduce it#

git clone https://github.com/caelus-engineering-labs/event-driven-systems-in-go.git
cd event-driven-systems-in-go
./demo.sh        # four phases, about 3.5 minutes; ./demo.sh 1 for a quick run

Delivery guarantees#

The plumbing follows RabbitMQ’s own recommendations, because event-driven designs usually fail there rather than in the domain model: publisher confirms and persistent messages, durable quorum queues, acknowledgement only after handling, idempotent handlers that ignore a redelivered event, prefetch 1 for ordered handling, and a dead-letter queue for messages that cannot be handled. Domain rules sit behind a one-method publisher interface and are unit-tested without a broker.

Limits#

One broker and one consumer per queue. Scaling a service out, and keeping per-car ordering when it is, is the next question a production design has to answer.

Repository