A domain can generate some results when executing commands. Those results are known as events. When an event is produced as a result of executing a command, it can be processed in different ways. For example, it can be stored in an append-only system or trigger events in other domains.

What are events?

An event is something that has happened in the past. They usually cause a reaction elsewhere. It is important to clarify that events are different from each other. It means that although two events have been created based on the same information, they are completely different. In other words, events cannot be duplicated and cannot be modified.

Events are immutable

When something happens in the real world, it is impossible for us to change that action, because it immediately becomes a part of the past. This principle of the real world is also applicable to our model behaviour in a software application.

Domain events are immutable because they have already occurred. We can save everything that happens, but we cannot change it. As per the real-world, nothing can be modified and these events produce reactions elsewhere.

What are domain events?

Domain events are the second of the three activities that can occur in a domain. Domain events describe the actions or events that occur in the domain. They are important to domain experts. Therefore, they are built based on ubiquitous language. A domain event is represented by any notation that is useful to create it. Such a notation can be JSON or YAML.

Let us assume that a customer of a bank wants to transfer money. Once the command is sent and the bank’s system processes it, a domain event is produced and saved in the system.

Get hands-on with 1200+ tech skills courses.