Module 3 · Database designLesson 24 of 886 minIntermediate

Normalization

Store each fact in exactly one place. Then a change is one write, and the data can't disagree with itself.

Try it

Play "Copied address" and watch one missed update leave a wrong address behind. Then play "Normalized", and finally "Read cost" to see the trade-off.

Normalization is a way of designing tables so that every fact lives in exactly one place.

The problem it solves

Imagine an orders table that stores the customer's name and address on every order. Three kinds of mistake become possible:

  • Update anomaly: the customer moves; you must update every order. Miss one and the data disagrees.
  • Insert anomaly: you can't store a customer who hasn't ordered yet.
  • Delete anomaly: deleting their only order deletes everything you knew about them.

The fix

Split the data:

  • customers (id, name, address)
  • orders (id, customer_id, total)

Each order points to its customer by customer_id (a foreign key). The address is stored once. Change it once, and every order shows the new value.

The formal rules are called normal forms (1NF, 2NF, 3NF). In practice, "every non-key column describes the key, the whole key, and nothing but the key" gets you to 3NF, which is where most apps aim.

When to break the rules: denormalization

Joins cost time. Read-heavy systems sometimes copy data on purpose:

  • storing author_name on each post so the feed needs no join,
  • keeping a comment_count on a post instead of counting every time,
  • building a read-optimised copy of the data for search or analytics.

That's denormalization. It's a fine choice, as long as something keeps the copies in sync: a transaction that updates both, a background job, or events. Start normalized; denormalize where measurements show you need speed.

Quick check

Each order row stores the customer's full address. What's the main risk?