Data Modeling Around Access Patterns
Core Concepts (5)
- 1.Model for the queries you must answer
- 2.Normalization protects correctness, denormalization buys speed
- 3.Indexes are copies of data with their own cost
- 4.Schemas encode business rules and age with them
- 5.Polyglot persistence adds power and operational burden
Map to Your Experience
Think of a query in your system that needs five joins or a full scan. How would the data have to look for that query to be trivial?
Design Brief: Model a Marketplace Twice
Learn
Data modeling is the act of deciding what facts the system stores and how they relate. A good model makes the common questions cheap to answer and the rules of the business hard to violate. A poor model does the reverse, and fixing it later means migrating live data, one of the costliest changes in software.
Normalization stores each fact once. A customer address lives in one row, and orders refer to it by identifier. This protects correctness: update the address in one place and every order sees it. The price is joins, and joins across large tables or across servers become expensive.
Denormalization copies facts to where they are read. An order might carry a snapshot of the shipping address, which is also historically correct, since the address on a past order should not change when a customer moves. Copies speed reads but create a duty to keep them in step, or to decide that they should deliberately diverge.
Start from the queries. List the five most frequent reads and the two most critical writes, with their expected rates. Then shape the model so those paths touch few records. Document stores, wide column stores, and relational tables all reward this habit, though they enforce different rules about how much you must decide up front.
Different parts of a system may deserve different stores: relational for transactions, a search index for text, a cache for hot reads. This is called polyglot persistence. Each added store is another thing to back up, monitor, secure, and keep consistent, so add one only when a clear access pattern justifies it.
Map
Pick one screen in a product you know and list every field it displays. Trace where each field is stored and how many tables or services must be consulted. Mark each field as stored once, copied, or computed, and note who is responsible for keeping copies fresh. Share the result with a colleague and note where their reading differs from yours.
Design
Produce two models for a small marketplace: one normalized and one tuned for the three busiest reads. Annotate every duplicated field with how it is refreshed and how stale it may become. Add a short note on which model you would ship first and what signal would trigger the move to the other. Keep the output to a single page that a peer could review in ten minutes without your help.
Requirements
- •Show both models side by side
- •Name the three read paths
- •List which fields are duplicated and where
Constraints
- •No more than eight entities
- •Explain how duplicated data is kept consistent
Must Cover
Trade-off Axis
write simplicity vs read speed
Referenced Patterns
Competencies Advanced
Ready to Design?
Open this day in the Design Studio. The studio follows this track: its days, concepts, patterns and trade-offs are loaded, and you keep one design across the whole track.
Open in Studio →