Data modeling
Designing the structure of data to fit the domain and its queries.
The data model shapes what the product can do easily. A good model reflects the domain, enforces important rules and supports the main queries. It is one of the hardest things to change later, so it deserves thought upfront.
Why it matters for a product engineer
The data model decides what the product can do easily and what it can barely do at all. A good model reflects the domain, enforces the important rules and supports the main queries. It is one of the hardest things to change later, because data outlives the code that wrote it. So it deserves thought before the first table, and again each time the product’s main question changes.
How to do it
- Name the entities in the product’s own words, and the relationships between them: one to one, one to many, many to many.
- List the main questions the product must answer, and check that the model answers them without scanning everything.
- Give each thing that changes on its own its own table or record. If one change rewrites a large record, the model is too coarse.
- Put the important rules in the database: required fields, unique values, foreign keys.
- Record where data came from and who may see it, especially if it feeds an AI system.
- Expect change. Leave room to add fields and relationships without moving all the data.
Common mistakes
- Modelling the first screen instead of the domain.
- A list stored inside another record, so changing one item rewrites the whole record.
- Free text where the product needs a fixed set of values.
- No owner for a field, so nobody knows what it means.
Example
At first, each Stripe customer had at most one subscription, stored inside the customer record. When users wanted several subscriptions, it became a list inside the customer. As subscriptions gained trials, coupons and invoices, every change to one subscription rewrote the whole customer. Stripe moved subscriptions into their own table, which meant migrating hundreds of millions of objects without downtime.
Three ways Stripe stored subscriptions
| Several per customer | To change one | |
|---|---|---|
| One field in the customer | No | Rewrite the customer |
| A list in the customer | Yes | Rewrite the customer |
| Their own table | Yes | Update one record |
Each model was right for the product of its time. The cost came from keeping the old shape after the product changed.
ReportedJacqueline Xu, 'Online migrations at scale', Stripe, 2 Feb 2017
Sources: Designing data-intensive applications (Martin Kleppmann) ↗ · Online migrations at scale (Jacqueline Xu, Stripe) ↗
Technical leverage
Represent product entities and relationships explicitly, including document provenance and access boundaries when data feeds an AI system.
Evidence of mastery
Put it into practice- Practice
- Model a knowledge-backed product feature and test how updates, deletions and permissions propagate.
- Artifact
- A schema and sample queries showing traceability from a result to its authorized source.
What good looks like
- Relationships and integrity constraints match the domain.
- Source deletion and permission changes reach derived indexes.
Use this evidence to assess your work. Your map status is a self-assessment, not a certification.
Resources
1- bookGo deeper · Paid
Designing data-intensive applications ↗
Martin Kleppmann · 600 pagesThe standard book on data systems, consistency and scale. Read it when a product's data starts to hurt.
Tools
1- ToolOpen source