CQRS — Command Query Responsibility Segregation — A Java, Spring, SpringBoot, and Axon Example

João Esperancinha
The Startup
Published in
10 min readDec 17, 2019

--

Introduction

The first time this term appeared in Software Engineering lexicons was all the way back in 1997. It appeared in the book “Object-Oriented Software Construction” by Bertrand Meyer. At this time it was known as CQS (Command Query Separation). CQRS was finally introduced by Greg Young in 2010. This software architecture is designed to mitigate known caveats of Object-Oriented architecture. Specifically in this case these caveats are:

  • Writes and reads generate, almost all the time, a very different load against the system.
  • Writing operations are often much more complicated than reading and they affect different scopes of the application. Write operations need to guarantee that correct, validated and consistent data reaches the store correctly.
  • Security concerns are also different between write and read operations.
  • The way data is normally stored in the database is in a 3NF or in another optimized form. When we read data, we often use it to build views to provide the user with readable data. The data presented to the user is hardly ever normalized. This is also referred to as denormalized data. In other words, we present the data to the user with the only concern that…

--

--

João Esperancinha
The Startup

Kotlin, OCP JSE 11, OCP JSE 8, OCP JEE 7, VMA Spring Professional #java #kotlin #scala #jvm #kafka #flux #reactive #spring #springmvc #springwebflux #coroutines