Problem

State data in traditional applications is represented through a set of entities. The entities are stored in a single data repository against which two types of operations can take place.

  • Commands: Operations that modify state
  • Queries: Operations that read state

An operation cannot both update state and return data. This distinction of operations helps simplify understanding the system. The segregation of operations into commands and queries is called the Command Query Separation (CQS) pattern. The CQS pattern requires the commands to have void return type and the queries to be idempotent.

If a relational database such as SQL Server is used for storing state, the entities may represent a subset of rows in one or more tables in the database.

A common problem that arises in these systems is that both the commands and queries are applied to the same set of entities. For example, to update the contact details of a customer in a traditional e-commerce application, the customer entity is retrieved from the database and presented on the screen, which is a query operation. The entity is then modified and saved in the database through the data access layer (DAL), which is a command operation.

Although, this model works well for applications that have a limited set of business logic, this approach has certain disadvantages:

  • There is a mismatch between the read and write representations of the data. While reading data, applications typically retrieve larger amount of data compared to writing that should affect one aggregate only.
  • Reading data is a more frequent operation than writing. Since traditional applications use a single data repository, you can't scale read and write operations independently.
  • Security and permissions are more cumbersome to manage in traditional applications because each entity is subject to both read and write operations, which might inadvertently expose data in the wrong context.
  • Coupled representation of read and write models in traditional applications impede agility since changes in functionality result in high friction and incurs cost and time.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.59.245