Search code examples
elasticsearchcqrs

CQRS why not just have elasticsearch for both read and write?


I am thinking of having a CQRS architecture for my project. This means having a read and a write database and an update process to keep both databases in sync.

Since I am going to update the read (elasticsearch) database anyway after each command, I wonder: what is the use of having a write database at all?


Solution

  • The purpose of seperation is distributing load accross multiple databases. Use one write optimized database for write operations and update read optimized database as asynchronous. So this way, write load is not affects read database. We can scale them independently.

    Another reason is read and write schemas may be differ. You can have a blog site which lists recent blogs on home page, you need to write all data to write database but you need only some of the data for listing or indexing it. Hence, using CQRS on infrastructure level provides us to independent scalability of databases.