Data modeling & choosing storage
Pick a data model from your access patterns, not from whichever database is fashionable.
List the queries your system must answer fast, then pick storage that makes exactly those cheap. Relational databases give you joins, transactions and constraints, which is why they are the right default when your data has relationships and correctness matters.
Document and wide-column stores earn their place when access is by a known key, the shape varies, or scale outgrows a single node. Their price is that cross-entity queries and transactions are now your problem.
Indexes are a trade: each one speeds up reads and slows down writes and takes space. Add them for real queries, check the plan, and remove the ones nobody uses.
Key points
- Start from access patterns. Schema follows queries.
- Relational is a strong default. Leave it for a reason you can state.
- Every index costs write throughput and storage.
- Denormalise deliberately and own the consistency work that follows.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Relational (Postgres) | Joins, constraints, transactions | Horizontal write scaling needs more design |
| Key-value / document | Simple scaling by key, flexible shape | Ad-hoc queries and multi-entity transactions are weak |
Answer these out loud
- 1Model users, posts and likes. Which query would you denormalise first and what breaks when a post is deleted?
- 2When would you reach for an append-only log instead of updating rows in place?
Build it
Create a table with 1M rows, run a filtered query with and without an index, and compare EXPLAIN output and insert time.
Use this from an agent
Any MCP client, including Grok, can read this lesson. See how to connect.
curl https://engineeros-delta.vercel.app/api/v1/topics/data-modeling-and-storage