Chapter 8. CQRS and Event Sourcing

 

This chapter covers

  • The basics of Command Query Responsibility Segregation
  • CQRS in reactive systems
  • Commands and queries
  • CQRS and Event Sourcing combined

As you’ve seen in the previous chapters, the reactive paradigm is a powerful way to think about distributed computing. In this chapter, we build on that foundation by exploring two design patterns introduced in chapter 1: Command Query Responsibility Segregation (CQRS) and Event Sourcing (ES). We should note, however, that although these techniques work in concert and are a natural fit for reactive programming, they’re by no means the only way to design a reactive system.

To achieve our goal of exploring these two design patterns, we look at a common type of application: the database-driven application, which is the foundation of many, if not most, systems built today. We explore the challenges in building these types of applications in a distributed environment and show you how, through the reactive paradigm, you can use CQRS/ES to overcome these challenges.

First, we need to state what we mean by database-driven application. The term can mean many things to many people, but at its root is a simple meaning: a software application that takes in and persists data and provides a means to retrieve that data.

8.1. Driving factors toward CQRS/ES

8.2. CQRS origins: command, queries, and two distinct paths

8.3. The C in CQRS

8.4. The Q in CQRS

8.5. Event Sourcing

Summary