Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can CQRS contribute to more scalable applications

Lately I've been reading a lot on CQRS architecture. One of the foremost points stated on why one should use CQRS is scalability.

Now I don't quite understand how this can work.

Let's say you have your typical CQRS application design.

  • Two Datastores
  • One for the Command Side
  • One for Query Side
  • When a Command has been processed an Event is send which could update the second Datastore

It's often stated that having a datastore for querying and one for handling commands would make your application more scalable. But how can this work if the second datastore that stores the event data needs to respond to the query requests and also constantly needs to update iteself based on the incoming events ?

Why not have one datastore where the commands are stored and where the query side can re-use the stored data for fetching it's result data ?

like image 723
Jonas Geiregat Avatar asked Jun 10 '14 07:06

Jonas Geiregat


1 Answers

You might find interesting to read this old blog post from Greg Young himself, where he explains what exactly CQRS is.

CQRS is not about having 2 different stores, but, as stated on Greg's article:

CQRS is simply the creation of two objects where there was previously only one. The separation occurs based upon whether the methods are a command or a query

What you describe here is more Event Sourcing.

Now back to your question: How can CQRS contribute to more scalable applications? Greg answers that as well:

CQRS allows to host two services differently eg: we can host the read service on 25 servers and the write service on two. The processing of commands and queries is fundamentally asymmetrical, and scaling the services symmetrically does not make a lot of sense.

That's it!

like image 143
MaxSC Avatar answered Sep 23 '22 12:09

MaxSC