An event is a recorded fact about a state change: “an order has been placed”, “the payment has gone through”. The producer service publishes it and moves straight on, without knowing who will react to it or how; each consumer receives the event in its own time and at its own pace. Because of this loose coupling, a new reaction to the stream of events is added as a separate subscriber, leaving the existing code untouched.
How the exchange works
Between producers and consumers there is usually a message broker: it accepts events, stores them and delivers them to subscribers even when those subscribers are unavailable. There are several kinds of channel:
- a queue — one of several consumers picks up the event (the work is distributed);
- pub/sub — all subscribers of the channel receive the event (the fact is spread);
- an event log — the records are kept in order, and consumers read them independently, each from its own position.
An online shop example: the order service publishes an OrderPlaced event; the warehouse (reserves the goods), the email service (sends an email) and analytics (updates metrics) are subscribed to it. The order service knows nothing about any of them and does not wait for their replies — placing an order takes milliseconds, and the rest is completed asynchronously.
Notification and state transfer
The event in a message can carry different amounts of data. In a notification it is the minimum: “order 1024 has been placed”, and the recipient fetches the details by querying the producer. With state transfer the event carries everything needed for the reaction — the consumer does not have to go back and does not depend on the producer’s availability, but it duplicates the data and raises the question of keeping the copies consistent.
The cost of the style
- consistency is eventual: while an event is in transit, the system appears inconsistent;
- delivery is usually “at least once”, so the reactions are made idempotent;
- there is no single place to see the flow of control — end-to-end tracing needs event correlation;
- ordering guarantees are needed within an entity, and the event format has to be agreed.
Sources
the term is written from these pages- Martin Fowler — What do you mean by “Event-Driven”? (2017)martinfowler.com/articles/201701-event-driven.html(opens in a new tab)
- AWS — What is an Event-Driven Architecture?aws.amazon.com/event-driven-architecture/(opens in a new tab)
- Microsoft Learn — Event-driven architecture stylelearn.microsoft.com/en-us/azure/architecture/guide/architecture-styles/event-driven(opens in a new tab)
Verified 8 Nov