๐Ÿ—ƒ๏ธ
๐Ÿ—ƒ๏ธ Working with Data ยท DATA-201 ยท Session 5 of 6

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.

โฑ 9 min read๐Ÿ“… Updated 2026-08-05๐Ÿ“Š Tables, charts & examples

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.

๐Ÿ“Œ Worked example
The name that changed in a thousand posts. A blog stored each author's full name inside every post record - simple, until a prolific author changed their name. Now the app had to update that name in every one of their nine hundred posts, and a script that missed a few left the site showing two different names for the same person. The fix wasn't a patch; it was a better model: store each author once in a users record, and have every post refer to the author by id. Change the name in that one place, and all nine hundred posts show it correctly, instantly, because they look it up rather than storing their own copy. One fact, one home - the quiet principle at the heart of modelling data well, and the reason relational databases are built the way they are.

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}
๐ŸŽฏ
Model the real things, and link them by id rather than duplicating. Identify the distinct kinds of things in your app and give each its own record type with clear fields. When two things relate - a post has an author - don't copy the author's whole details into every post; store the author's id and look it up. This keeps each fact in one place, which is the heart of good modelling: if a user changes their name, you update it in one record, not in every post they've written. Thinking in 'things and the links between them' is exactly how relational databases work.

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 nameEach post stores the author's id
Change a name -> update everywhereChange a name -> update one record
Copies drift out of syncOne source of truth
Contradictory data creeps inConsistent 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.

Session 5 of 6 complete

Next up: Data at Scale: Pages, Indexes & Speed

Continue to Session 6 โ†’

Related lessons

More in this course

Course home → · Browse all courses →