liveBook · Manning

Data grouping

As explained in Microservices Patterns, Second Edition

The organization of related data together in a record to match how queries retrieve it.

Data grouping shapes a CQRS view’s records to match query results. Embed related entities for one-read retrieval, or keep them separate and gather them at query time. Balance query efficiency against event-handler update efficiency. section 13.3.2

Choose grouping by weighing query needs against database capabilities:

  • Embed related entities when queries return them together; an order record can include its ticket and delivery. section 13.3.2
  • Document and key-value stores can nest collections; relational rows can fold in a related entity only when there is at most one. section 13.3.2
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.
CQRSRecordGrouping

Compare storing a customer’s orders in one document with storing each order separately. section 13.3.2

How Microservices Patterns, Second Edition covers it

How deep it goes
Compares embedded and separate records, explains primary-key reads, and notes document, key-value, and relational database constraints.
Examples
Uses order, ticket, and delivery records, plus customer orders nested in one document or stored as separate documents.
What you can do after
Evaluate record grouping by query shape, lookup pattern, database capabilities, and event-handler update cost.
How it connects
Connects CQRS views with queries, event handlers, denormalization, and document, key-value, and relational databases.

Also explained in

Compare how 7 books explain data grouping →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.