Normalization vs denormalization

Topic 2 of 10 in Week 3: Databases9 min readIntermediateFree course

Overview

There are two opposite instincts in data design. One says: store every fact exactly once, so it can never be inconsistent. The other says: store data in the shape it’s read, so reads are fast. Both are right in different places. This lesson explains normalization, denormalization and how to choose.

The two approaches

Normalized versus denormalized. In the normalized design, a customers table holds id 7 and name Asha Rao, and an orders table holds order 981 with customer_id 7, so showing the name needs a join. This gives one place to update and no anomalies, but reads need joins. In the denormalized design, the orders row holds order 981, customer_id 7, a copy of the customer name and a pre-computed item_count of 3. Reads are fast with no joins, but the copies must be kept in sync.

Normalization

Normalization splits data into tables so that each fact lives in one place, linked by keys. The customer’s name lives in customers; orders refer to the customer by customer_id.

Benefits:

  • No update anomalies: change the name once and every order shows the new name.
  • Less storage and smaller rows.
  • Integrity: constraints and foreign keys keep data valid.

Cost: reads that need data from several tables require joins, which get expensive on large tables, across shards or at very high read rates.

Denormalization

Denormalization deliberately duplicates or pre-computes data to make reads cheap:

  • Copied fields: store customer_name on the order or author_name on the post.
  • Counters: like_count, comment_count, follower_count.
  • Pre-joined or pre-computed views: a user’s feed stored ready to read; daily sales totals.
  • One table per query: common in wide-column stores (next lesson).

Cost: writes do more work, data takes more space, and copies can become inconsistent if an update is missed.

Keeping copies correct

Every denormalized field needs an answer to “what updates it, and when?”:

Strategy How Consistency
Same transaction Insert the comment and increment comment_count together Always consistent (single database)
Database feature Triggers, materialized views, generated columns Consistent or refreshed on a schedule
Events + background job Publish “author renamed”; a worker updates copies Eventually consistent
Periodic rebuild Recompute nightly from the source of truth Stale between runs

A good habit: keep the normalized data as the source of truth and treat every denormalized structure as derived data that can be rebuilt from it. If a counter drifts, a repair job can recount.

Some copies are features, not shortcuts

Sometimes copying is correct rather than an optimisation. An order should store the price and address at the time of purchase. If the product price changes next week, past invoices must not change. That’s a snapshot, not a stale copy.

How to choose

Lean towards normalization when:

  • data changes often and must be correct everywhere (balances, inventory),
  • write volume is high and reads are moderate,
  • you’re early and access patterns are still changing.

Lean towards denormalization when:

  • reads vastly outnumber writes (feeds, product pages, profiles),
  • the copied data changes rarely (names, avatars),
  • joins would cross shards or services,
  • a slightly stale value is acceptable.

Most production systems combine them: a normalized relational core plus caches, counters, search indexes and read-optimized tables built from it.

In an interview

When you add a counter or a copied field, say how it stays correct: “I’ll keep like_count on the photo, incremented atomically when a like is inserted; if it drifts, a nightly job recounts.” That one sentence shows you understand the trade-off.

Recap

Normalization stores each fact once and joins at read time; denormalization copies and pre-computes data for fast reads at the cost of more complex writes. Keep a normalized source of truth, denormalize where reads dominate and staleness is acceptable, and give every copy a clear update strategy.

Exercise

Copy or join?

A blog platform shows a post page with the post, the author's name and avatar, the number of comments, and the latest 3 comments. The post page gets 50,000 views per second; authors rarely change their name; comments are added about 200 times per second across the site. For each piece of data, decide whether to read it via a join/query at request time or to store a denormalized copy, and explain how the copy stays correct.

Text
Author name and avatar:
Comment count:
Latest 3 comments:

Summary

  • Normalization stores each fact once and links data with keys, avoiding update anomalies.
  • Denormalization copies or pre-computes data where it is read, trading write effort and storage for fast reads.
  • Common forms: copied fields, counters, materialized views, read-optimized tables and caches.
  • Every copy needs an update strategy: same transaction, events and background jobs, or periodic rebuilds.
  • Keep a normalized source of truth and treat denormalized data as derived and rebuildable.