Microservice CQRS Pattern Explained

Anish Antony
7 min readDec 11, 2021
Photo by XPS on Unsplash

CQRS stands for Command and Query Responsibility Segregation. Basically, this pattern separates read and update operations for a database. Normally, in monolithic applications, most of the time we have 1 database and this database should respond to both query execution and update operations. That means a database is both working for complex join queries, and also perform CRUD operations. But if the application goes more complex this query and crud operations will be also is going to be unmanageable situations.

In the example of a reading database, if your application required some query that needs to join more than 10 tables, this will lock the database due to latency of query computation. When performing crud operations we would need to make complex validations and process long business logic, so this will cause to lock database operations. So reading and writing databases have different approaches that we can define the different strategies to handle the operations. In order to that CQRS offers to use “separation of concernsprinciples and separate reading from database and the writing to the database with the help of two databases. In this way, we can use different databases for reading and writing database types like using no-SQL for reading and using relational databases for crud operations.

--

--

Anish Antony

Fullstack Developer | Blogger | Experience on Java, Python, React, Angular, Golang | http://www.behindjava.com