What is Command Query Segregation Pattern (CQRS)?

The (CQRS) Command Query Responsibility Segregation is a design pattern that manages different operations of databases in separate ways.

It has two types of operations: command operation and query operation.

The command operation manipulates the write database data by performing operations like the insert, update, and delete commands. If the user wants to use the query operation, then the system will use the read database, in which the user will not be able to manipulate data.

Let's look at an illustration for a better understanding.

CQRS visual implementation

We can see in this illustration that when a user requests an operation and if it is relevant to the command operations, it passes over to the Write DB. If it is relevant to the query, it passes over to the Read DB and performs the operation accordingly.

Let's look at the advantages and disadvantages of CQRS in the below table.

Advantages and disadvantages of CQRS

Advantages

Disadvantages

Separating both read and write operations enhance the speed of operation.

Implementing a CQRS pattern in a database is a complex process.

Managing data is easy.

Using more then one database can increase chances of failure.

We can use two different types of databases for read and write operations.

Using two different types of databases also requires knowledge of different database technologies.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved