Java Magazine, Jan/Feb 2018
ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2018 75 beyond CRUD ers to update their internal model but only one subscriber EventHandler is supposed to trigger further commands from these events Publishing the events has to happen in a reliable way to keep the system in a consistent state in the long run Benefits of CQRS One of the benefits of separating the responsibilities of reads and writes in the CQRS model is the fact that the query and command sides can scale independently In typical enterprise applications the read operations outnumber the write operations Because being eventually consistent on the read side is in most cases not a big problem returning replicated data has a positive impact on the overall performance Using CQRS enables you to deploy for example a greater number of query service instances to scale out just the read side The domain model representations of each of the services solve the problem of the rising numbers of events in an event sourced system Because more and more events are stored in the system over time the overall performance of operations would decrease if the application state were solely calculated on demand by applying all events each time Updating the representation continuously and using these models in the commands and queries maintains a constant level of performance This corresponds to the concept of snapshots Another benefit of this separation is the given failover capacity at least for the read side Because all instances maintain an eventually consistent representation of the systems state this cached state is still available if the event store goes down Even though no new events can be written the clients can still access the last state Applications that implement CQRS also have the capability to implement further use cases that operate on events from the past because they implement event sourcing as well Now I will show an actual CQRS implementation in a Java EE application Example CQRS Application As an example Im using a scalable coffee shop that consists of three services responsible for order management orders bean storage beans and coffee brewing barista Each service is free to choose its internal domain object representation and the collaboration is done using
You must have JavaScript enabled to view digital editions.