CQRS - The Simplest Introduction

CQRS or Command Query Responsibility Separation is easy to understand but it can become complex due to various levels to which developers take the principle behind it. Simply - CQRS is two models, where the used to be one. Nothing more at its heart.

Take the Customer aggregate below. This exposes both commands as void methods and queries as methods with return types. Public state is leaked, but needed in order to display or persist the data. Many frameworks or libraries require public accessibility in order to function.

CQRS states we split commands from queries. This means we end up with a pure Customer aggregate root that exposes behaviour only. Likewise we end up with a basic application service that simply returns data.

Benefits

Commands
Queries

Complexity

CQRS is an easy concept, that introduces many benefits. However implementation of this pattern can vary from simple, to complicated. The extent to which CQRS is implemented should be judged on a case by case basis. Many systems can get away without separating read and write stores, yet still enjoy the benefits that this pattern provides.