Denormalization stores related data together, sometimes with deliberate duplication, so queries can retrieve it without expensive joins or separate lookups. It is useful when high query volume or large data sets make a normalized schema too slow or costly. For small, infrequently queried data sets, a normalized relational schema with joins may be simpler and sufficient. section 13.1.2 section 13.3
In a CQRS view, grouping related entities into a record can make the stored shape match the query result. A primary-key query can then retrieve the result in one lookup. The choice must also account for updates: event handlers need to find and update affected records efficiently. section 13.3.2
Order and delivery views
An order record can include its ticket and delivery so an order lookup retrieves them together. A courier’s location can also be copied into each current delivery, avoiding a separate lookup when returning a delivery. The copied location then has to be maintained as it changes. section 13.3.2
Choose the grouping with the database and operational costs in mind:
- Document and key-value stores can nest collections in a record. In a relational database, a related collection remains in its own table. section 13.3.2
- Duplicated data consumes storage and makes updates part of the design. In an event-driven CQRS view, propagation can lag, and a faulty event handler can leave the view stale or incorrect. section 13.2.3 section 13.3.2
- Check whether an existing view can support the query before designing a new one; weigh query efficiency against update efficiency and infrastructure costs. section 13.3 section 13.3.2 section 13.2.3
Figure 13.6 There are often multiple ways to group records, each with different tradeoffs. A customer’s orders can be stored in a customer document, or each order can be stored in its own document.
Compare grouping a customer’s orders inside one document with storing each order separately. section 13.3.2







