Java Magazine, Jan/Feb 2018
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 ORACLE COM JAVAMAGAZINE JANUARY FEBRUARY 2018 73 beyond CRUD This OrderPlaced event then causes the cofee bean storage to check whether there are beans available and to publish either an OrderAccepted event or an OrderFailedInsufficientBeans event The current state of the order is calculated by applying all events related to that order as in an event sourced system This way of modeling causes the process to be eventually consistent and because the application ensures that all events are published in a reliable way the final outcome of the use cases will be consistent If you compare this way of modeling to the real world you can see that these methods of collaboration are common When you order a cup of cofee the waiter accepts your order even though its possible that for some reason the coffee will never make it to you In that case the waiter will come back later and apologize for not being able to deliver the cofee and will offer a compensating transaction even though the order was accepted in the first place Eventually you will end up with your coffee another drink or your money back Because the real world is all about distributed collaboration often in an asynchronous way it makes sense to model applications in an event driven way Enter CQRS Now that Ive summarized implementing event driven and event sourced applications I will introduce the CQRS principle which prescribes separating the responsibilities of reads and writes CQRS causes methods to either modify the state of the system without returning any value or to return values without any side efect The commands that is the writes are not supposed to return values they either return successfully or throw an error The queries that is the reads only return data see Figure 3 This principle is simple in theory but has important implications Once you split up a system following this approach the applications collaborate only by events that are published to
You must have JavaScript enabled to view digital editions.