Modelling Your Data Well
How you *structure* your data shapes how easy everything else becomes. Good data modelling โ deciding what your records are and how they relate โ is quiet, high-leverage design work.
Before you store or query data, you decide its shape: what your records are, what fields they hold, and how they relate. This is data modelling, and it's quietly one of the most important decisions in an app - a good model makes everything downstream easy, while a poor one makes simple things hard and invites bugs. You don't need to be a database expert; a few sensible principles go a long way. This session covers modelling data well.
Decide your records and fields
Start by identifying the things your app is about (users, posts, orders) - each becomes a kind of record - and the fields each needs.
# a 'user' record
{"id": 1, "name": "Ada", "email": "a@b.co", "joined": "2026-01-05"}
# a 'post' record - note it refers to its author by id
{"id": 7, "title": "Hello", "body": "...", "author_id": 1}Don't repeat data
The most valuable modelling principle is to avoid duplicating the same information, because duplicated data drifts out of sync and causes bugs.
| Bad (duplicated) | Good (referenced) |
|---|---|
| Each post stores the author's full name | Each post stores the author's id |
| Change a name -> update everywhere | Change a name -> update one record |
| Copies drift out of sync | One source of truth |
| Contradictory data creeps in | Consistent data by design |
This principle (loosely, 'normalization') is why relational databases split data into related tables. You don't need to over-apply it - some duplication is fine for simplicity in small apps - but the core instinct is gold: keep each piece of information in one authoritative place, and refer to it from elsewhere by id, rather than copying it around.
Structure for the long run
- Identify the things your app is about - each becomes a record type with clear fields.
- Link related things by id, don't copy their details around.
- Don't duplicate data - keep each fact in one authoritative place (one source of truth).
- Good modelling makes everything downstream easier; it's high-leverage design.
๐ฏ Key takeaways
- Data modelling - deciding your records, fields, and how they relate - shapes how easy everything else becomes.
- Identify the real things your app is about; each becomes a record type with clear fields.
- Link related things by id rather than copying their details, so each fact lives in one place.
- Avoid duplicating data (one source of truth) - duplicated data drifts out of sync and causes bugs.
Frequently asked
Why is duplicating data such a problem - isn't it simpler to just store everything together?
Storing everything together can feel simpler at first, but duplicating the same information in multiple places is one of the most common sources of data bugs, because those copies inevitably drift out of sync - and that's why avoiding duplication is a core modelling principle. Consider a blog where, instead of linking each post to its author by an id, you copy the author's full name and email into every post record. It works initially and feels convenient - each post has everything in one place. But now the author changes their name (or you fix a typo in their email). You have to find and update that information in every single post they've written, and if you miss even one, you now have contradictory data: some posts say the old name, some the new. Which is correct? Your app has no way to know, and users see inconsistent information. Multiply this across an app with lots of related data, and duplication becomes a persistent source of subtle, hard-to-fix inconsistencies - the same 'fact' recorded in many places, gradually diverging as some copies get updated and others don't. The alternative - storing the author's details once in a user record and having each post refer to the author by id - means there's a single authoritative place for each fact (the user's name lives in one user record). Change it there, and every post automatically reflects the change because they all look it up rather than storing their own copy. This is 'one source of truth': each piece of information exists in exactly one place, so it can't contradict itself. That's the deep reason relational databases split data into related tables and link them - it's not bureaucracy, it's preventing the drift-and-contradiction problem that duplication causes. Now, the honest nuance: some duplication is acceptable, even sensible, in certain cases - for simplicity in very small apps, or deliberately for performance in advanced scenarios (sometimes you copy data to avoid expensive lookups, a trade-off called denormalization, but that's a conscious choice with its own handling). And you shouldn't over-apply the principle to the point of making simple things complicated. But the default instinct that serves you well is: don't casually duplicate information that could change - keep each such fact in one place and reference it from elsewhere by id. So 'storing everything together' is simpler in the very short term but creates a maintenance and consistency problem that grows with your app; referencing shared data by id is slightly more structure up front but keeps your data consistent and changes easy forever after. The bugs that duplication causes - out-of-sync copies, contradictory records, missed updates - are exactly the kind that are frustrating to track down, so modelling to avoid them from the start is high-leverage. Keep each fact in one authoritative place; link, don't copy.
How do I know how to structure my data - is there a right answer or is it judgement?
It's largely judgement guided by solid principles - there's rarely one single 'correct' model, but there are clearly better and worse ones, and a few reliable guidelines lead you to good structure most of the time. The core approach is to identify the distinct 'things' (entities) your app deals with and how they relate. Ask: what are the nouns in my app's world? A blog has users, posts, and comments; a shop has customers, products, and orders; a task app has projects and tasks. Each distinct kind of thing generally becomes its own record type (or table), with fields for the information it holds. Then ask how these things relate: a post belongs to a user (its author), a comment belongs to a post, an order belongs to a customer and contains products. Those relationships you represent by referencing ids (a post stores its author's id) rather than duplicating data, as we discussed. That entity-and-relationship thinking - what are the things, and how do they connect - is the heart of data modelling and takes you most of the way. Beyond that, the guiding principles are: keep each fact in one place (avoid duplication / one source of truth); give each record a clear identity (an id); make fields represent single, clear pieces of information; and structure data to match how you'll use it (the questions you'll ask of it). There's genuine judgement in applying these - for instance, how finely to split things apart (should an address be fields on a user, or its own record?) often depends on your app's needs, and reasonable developers might model the same domain slightly differently. Experience sharpens this judgement, and you'll refine your instincts by building things, occasionally getting a model wrong, feeling the pain (queries that are awkward, data that's hard to keep consistent), and learning from it. A practical way to develop the skill: sketch your entities and relationships before coding (even informally - 'users have many posts; posts have many comments'), start with a reasonable model applying the principles, and adjust as you learn what your app actually needs. Don't aim for a theoretically perfect model up front (you can't fully predict everything, and over-engineering the model is its own mistake); aim for a sensible, principled structure that you can evolve. Also lean on the accumulated wisdom: for common app types, there are well-known good models (the blog with users/posts/comments is a classic for good reason), and studying how existing apps and tutorials structure similar data teaches you patterns. So: it's judgement, but well-supported judgement - identify your entities and relationships, apply the principles (one source of truth, link by id, clear fields, structure for your queries), start with a reasonable model, and refine with experience. There's not one right answer, but there are good answers that these guidelines reliably lead you toward, and good-enough beats perfect - a sensible model you can adjust serves you far better than agonising over an ideal one. Data modelling is a skill you build by doing, guided by a handful of durable principles, and it's worth developing because a good model quietly makes an entire app easier to build and maintain.
Related lessons
Databases & SQL
When files aren't enough, you reach for a database โ and the language for talking to most โฆ
Working with DataData at Scale: Pages, Indexes & Speed
A little data is easy; a lot of data needs care. Paginating results, indexing for fast looโฆ
Data Structures & AlgorithmsWhy Data Structures Matter
How you store data decides how easy - and how fast - everything else becomes. Choosing theโฆ