My presentation Building microservices with event sourcing and CQRS describes the challenges of functionally decomposing a domain model in a microservices based application. It shows that a great way to solve those problems is with an event-driven architecture that is based on event sourcing and CQRS.
The presentation uses a simple banking application, which transfers money between accounts, as an example. The application has the architecture shown in the following diagram:
The application consists of four modules that communicate only via events and can be deployed either together in a monolithic application or separately as microservices.
The four modules are as follows:
- Accounts – the business logic for Accounts
- Money Transfers – the business logic for Money Transfers
- Account View Updater – updates a denormalized view of Accounts and Money Transfers in MongoDB
- Account View Reader – queries the denormalized view
You can find the source code and documentation for the example application in this github repository. There are currently two versions of the application: Java+Spring Boot and Scala+Spring Boot. I plan to publish a Scala/Play version shortly. The application uses a simple, embedded event store.