Read/Write Model

Checkout lesson on UDEMY Section preview

Terminology

CQS

Command Query Separation

Operation

A message that tells application | system to do something

  • An operation is either a command or a query

Command

Change the state of aggregate

  • Writes to the database
  • An action initiated by an actor/user/service/time
  • The ACTION must be carried out
  • Named as verb

Query

Serves state of the aggregate

  • Reads from the database
  • Also known as Query Model or Read Model

Common model for Commands & Queries

Requires translation between Domain model and Read/Write models

CQS-Realization

CQS principle

Suggests clear demarcation between methods that change the state & those that don’t change the state of domain

Same object method should NOT be used for both command and query

Command and Query needs to deal with different set of concerns

In this illustration:

  • Read model - looks for flexibility & performance
  • Write model - deals with complex logic, need to be transactional & must scale

CQ-separation-example

Command-Query Realization

  • Synchronous & Asynchronous protocols
  • Wire format is flexible

References

Read-Write Model splitting