The pitfalls of not knowing how to handle transactions
One pitfall that teams face is not knowing how to handle transactions that are distributed across multiple microservices. We will explore how we can frame transactions within a microservice and how to handle them when they involve multiple microservices. We will start with a concept that we explored in Chapter 3, Microservices Architecture Pitfalls, where we discussed domain-driven design and the concept of aggregation.
Aggregates are transactional boundaries. They form boundaries around transactions that enforce business rules and business invariants. These are then grouped by relevant entities that are part of the aggregate and its transactional boundary. These transactions are a single unit of work and can be made up of multiple operations that live in the space of that isolated transaction and produce a domain event that represents a state change to the aggregate and its internal entities. A command is an operation that...