liveBook · Manning

Domain event

As explained in Microservices Patterns, Second Edition

An event representing a business-significant state change of a domain entity or aggregate.

A domain event represents a business-significant state change of a business entity or aggregate. Other services can use these events to keep their own data in step with changes in the domain. section 10.1.2 section 13.2.1

Domain events and integration events can look alike, but they serve different needs. In a choreography-based saga, an integration event may carry request parameters solely to transport them, expose only part of a domain event, report a command failure without a state change, or communicate a query result. Passing unused data through a participant can create coupling: that participant may need to change when the data structure changes. section 10.1.2

Creating an order

In a Create Order saga, Order Created and Customer Credit Reserved closely mirror domain events from the order and customer domains. By contrast, Customer Credit Limit Exceeded is an integration event reporting a failed command, not a state change. section 10.1.2

For a CQRS view, design provider events backward from the queries the view must support. Each provider supplies its share of the result data and the supporting data needed to filter, sort, or maintain the view. A provider event published by an aggregate contains its ID and any related aggregate IDs needed as foreign keys. section 13.3.4

Maintaining order history

An OrderCreated provider event contains the Order ID for the record to create and the Consumer ID stored with it, so a later query can find the consumer’s orders. View event handlers extract event data and delegate create, update, or delete operations to the view repository. section 13.3.4

Event contracts are an organizational decision as well as a technical one. When different teams own the query and provider services, they must negotiate which events and properties providers publish. Duplicate handling usually belongs in the view repository, where the event is applied. section 13.3.4

How Microservices Patterns, Second Edition covers it

How deep it goes
Defines domain events, distinguishes integration events, and details provider event fields and handler responsibilities.
Examples
Uses order creation, customer credit reservation, and an order history view to illustrate events and their data.
What you can do after
Evaluate whether saga events represent domain changes and design provider event data for a CQRS view.
How it connects
Connects domain events to aggregates, domain-driven design, choreography-based sagas, CQRS, and idempotent consumers.

Also explained in

Compare how 4 books explain domain event →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.