Event Driven Architecture

Events

Events are an indication of something of significance that has happened at a point in time i.e., past. When an event occurs one or more Consumers are notified. Consumers react to the event independent of the producer and other consumers.

Events Driven Architecture (EDA)

Software architecture paradigm that promotes designing of systems as a collection of loosely coupled components that act as event producers and consumers.

EDA is an architecture paradigm promoting the production, detection, consumption of, and reaction to events. Microservices are producers and consumers of events.

Events are Asynchronous and require use of messaging technology for realization.

eda-overview

Example

In this example when a new account is created, an event Account Created is produced. This event is consumed by multiple downstream components to carry out actions independently.

  • Pub-Sub pattern in use
  • Messages published to a Kafka topic

eda-example

Event Content

  • All relevant data in the event
  • Only meta-data in the event. Consumer pulls the detailed information from the producer.

In this illustration Event contains only the meta-data, the consumer pulls the details by invoking an API.

event-content-metadata

API vs EDA

API are directed commands whereas events are observable

api-vs-eda

API EDA
Caller has knowledge of API Producer doesn’t know Consumers
Synchronous Asynchronous
Message = Request / Response Message = Event data
Relatively high coupling Highly Decoupled & Extensible
Centralized business logic Business logic across components
Easy to understand the flow Relatively difficult to follow

Event Consumers

Event consumers subscribe to the events of interest & react to it. Consumers can be:

  • within the same microservice
  • in a different microservice
  • an external service

DDD & Events

Domain Driven Design suggests using the events for modeling a domain.

Events occur naturally in all domains!! e.g., Order placed, Account created ….

Events are an integral part of the model | Bounded Context

Events are part of the Ubiquitous Language