24 CQRS: An Architecture of a Bounded Context

WHAT’S IN THIS CHAPTER?

  • The challenges of using a single model for complex presentation and domain logic needs
  • How the CQRS pattern segregates the reading and writing models
  • The popular misconceptions of the CQRS pattern
  • How CQRS can help bounded contexts to scale

Wrox.com Code Downloads for this Chapter

The wrox.com code downloads for this chapter are found at www.wrox.com/go/domaindrivendesign on the Download Code tab. The code is in the Chapter 24 download and individually named according to the names throughout the chapter.

CQRS (Command Query Responsibility Segregation) is a simple pattern that you can apply to a bounded context. It separates the domain model into two models: a read model and a write model (sometimes called a transactional model).

The reason for the separation is to enable a model to serve the needs of a single context without compromise. The two contexts in question are reporting on the state of the domain and performing business tasks, also known as the read and write sides. Using a single model for bounded contexts that have complex presentation needs and rich domain logic often results in that model becoming overly complex and devoid of integrity, generating confusion for domain experts and a maintenance nightmare for developers. By applying the CQRS pattern, a model is split in two, enabling each model to be optimized to serve each context more effectively.

CQRS is not a top-level architecture; it is ...

Get Patterns, Principles, and Practices of Domain-Driven Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.