Definition of event-driven architecture
In “event-driven architecture”, the adjective means “driven by events”. The expression is one of common usage: Martin Fowler opens the article he devotes to it, “What do you mean by “Event-Driven”?” (martinfowler.com, 7 February 2017), with an observation: those who talk about events mean fairly different things.
In common usage, event-driven architecture refers to a system whose components communicate by publishing and consuming events. An event records a fact that has occurred: an order confirmed, an address changed. The emitter does not need to know who will read it. An intermediary, a message broker or an event streaming platform, such as RabbitMQ or Apache Kafka, can receive them and deliver them to subscribers.
Several applications can thus react to the same fact, independently of one another, and an additional application can subscribe without the emitter being modified. The use of events falls under the rules of exchange set by IT urbanisation.
Notification, state transfer, event sourcing, CQRS: the models Fowler separates
The article reports on a workshop in which the author took part with colleagues. He draws from it four models that the same word covers.
| Model | Principle | Trade-off noted in the article |
|---|---|---|
| Event notification | A system signals a change. The event may carry only a little data, and the recipient calls the emitter back if it needs more | The overall flow is written in no program and becomes difficult to follow |
| Event-carried state transfer | The event carries the changed data. The recipient keeps its own copy and no longer queries the source | Duplicated data, complexity shifted onto the recipient |
| Event sourcing | Every change of state is recorded as an event, and the state is rebuilt by replaying the log | Tricky replay when a result depends on an external system, event formats that evolve |
| CQRS | Separate data structures for reading and for writing | The complexity of two models to maintain |
CQRS, Fowler writes, does not strictly speaking belong to events: it is also practised without them.
Water meter readings published as events
Suppose a water utility equipped with smart meters. At each reading, the collection system publishes a “reading taken” event, which carries the meter identifier, the date and the value. Three applications subscribe to it: billing, leak detection and the customers’ online account area. Each keeps its own copy of the readings without querying the collection system: this is event-carried state transfer.
Three trade-offs come with this set-up. Depending on the delivery guarantees configured in the tool, the same reading may arrive twice, or after a more recent reading, and each subscriber must tolerate this. To explain an incorrect bill, the path of an event across several applications has to be reconstructed, which is made easier by the tracing described in our article on distributed systems observability. Finally, the event format becomes a contract between teams. Two public specifications help to write it: AsyncAPI, to describe the exchanges, and CloudEvents, to describe events in a common way.
Event-driven architecture, command, message queue, microservices: not to be confused
An event is not a command. The former states a fact and expects no response; the latter asks for an action. Fowler warns against the event that serves as a disguised command, when the emitter actually expects the recipient to act.
A message queue is a means of transport, which carries commands as well as events. Its presence does not say which model the system applies.
Microservices architecture splits an application into separately deployable services. These services exchange through direct calls or through events, and neither choice entails the other.
Complex event processing refers, in common usage, to detecting patterns in a stream of events. It is a form of processing, which can rely on an event-driven architecture without being the same thing.
The mode of exchange is chosen flow by flow, between event, API call and file; our page IT architecture sets out the criteria.