Member-only story

DDD — Command Query Responsibility Segregation (CQRS)

Phillip Johnson
CodeX
Published in
5 min readMar 20, 2022
Photo by hannah joshua on Unsplash

Commands are complex, Queries are simple

Previously we’ve looked at DDD Entities, that have state, and Events, where state changes. To reduce complexity we can be specific about what has state and encapsulate where it changes. Events are high level code, sitting in the middle of the Onion Architecture. In this article, we will look at how lower level commands link the user interface or API with events to enable users to change state.

Onion Architecture

Domain events exist in the high level Domain centre of an Onion Architecture diagram, covered by Robert C. Martin in Clean Architecture. The outer layer of the onion contains low level details, inputs and outputs such as storage, user Interfaces, and APIs. Commands are somewhere in between, linking the inputs to the higher level domain so that users can trigger the events to change state.

Introducing CQRS

For a user to interact with a system, and for it to be useful, we need to be able to do two things. First is to display information to the user. To do that we need to read the…

--

--

CodeX
CodeX

Published in CodeX

Everything connected with Tech & Code. Follow to join our 1M+ monthly readers

Phillip Johnson
Phillip Johnson

Written by Phillip Johnson

Over 20 years experience in software engineering, mostly in leadership positions. Passionate about software craftsmanship.

Responses (1)