Domain events in domain driven design

Published on

Right now I am reading “Domain driven design distilled” to get started with DDD.

Some notes on domain events worth a TIL entry:

A domain event is a record of some business-significant occurrence in a Bounded Context.

Domain events can be published and consumed in your own Bounded Context and by others.
Used to inform interested listeners of important events in a specific domain.

Communicate well the intent using Ubiquitous Language, naming your domain event using a common language understood by everyone.

A domain event name represents a past occurrence, thus should end with a verb in the past tense.

When a Domain event is defined ask yourself, “What caused the Domain Event to be published?”
You will find the name of the command that caused the event.

Event: ProductCreated
Command: CreateProduct

The domain event should hold all the properties that the command had.

It’s important to note that a Command could be rejected (e.g. violation of business rules, invariants, validation, etc.)

On the other hand a Domain event is a fact, and thus cannot be rejected.

For example if the Domain event is caused by a time-related activity (new year, fiscal year ended, etc.) you could published the domain event directly, without going through a command.