Bookmarks

EDA — event-driven architecture

An architectural style in which the parts of a system do not call each other directly but react to events: a producer publishes an event, and consumers are subscribed and react independently.

Also: event-driven design, EDA, event-driven style

checked 8 Nov

All terms

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

Verified 8 Nov

Not to be confused with

what it is mixed up with and how it differs

  • event sourcing

    In event sourcing the event log is the source of truth from which the state is assembled; event-driven architecture is only about how the parts of the system exchange events.

  • publish–subscribe (pub/sub)

    Pub/sub is a way of delivering a message to subscribers, a single channel; event-driven architecture is the style of the whole system, where pub/sub, queues and logs serve as the transport for events.

  • saga

    A saga carries a change through several services as a chain of local transactions with compensations — this is a technique inside event-driven architecture, not the architecture itself.

In depth in the references

where the topic is covered in detail