The distributed transaction problem
With microservices, each service is a transaction boundary and acts on an aggregate root. Thus, if we place an order using an Order microservice and allocate stock using a Stock microservice, those operations happen in separate transactions. We could of course have the Order microservice call the Stock microservice, but this would mean the two microservices are tightly bound. The Order microservice would depend on the Stock microservice and fail if the Stock microservice were unavailable for some reason. It could also lead to a complex web of interdependent microservices that would not be able to be built, tested, deployed, or scaled independently.
A better solution is for us to use domain events and an event bus. Domain events are a record of something that happened in the business logic of our microservice and contain details of the change (or details of a failed change). In the preceding example, for instance, when we successfully place an...