// RULES
Microservice rules
Best practices for microservices, one rule per page: why it matters, how to apply it and an example. They are grouped into checklists you can apply to a service.
7 rules of 70 · Clear filters
Data
- A read model names the service that writes the data
A service that is the read side of a CQRS pair says which service owns the writes, so the source of truth is never in doubt.
MediumChecked automatically
- Derived data can be rebuilt from its source
A materialized view or read model can be dropped and recreated from the data it derives from, and the procedure has been run.
MediumChecked by hand
- Each aggregate states its invariants
Every aggregate lists the rules that must hold whenever it is saved, so the consistency boundary has a reason.
MediumChecked automatically
- Each saga names its trigger and its steps
A saga the service takes part in is written down: what starts it and the steps of the normal path, in order.
MediumChecked automatically
- Materialized views name their source and storage
Every materialized view says what it is built from and where it is kept.
MediumChecked automatically
- Retention and deletion are defined
For each kind of data it owns, the service says how long it is kept and how it is removed.
MediumChecked by hand
- The aggregates the service owns are declared
The service names its aggregates, so it is clear what changes together in one transaction and what does not.
MediumChecked automatically