Skip to main content
07

Normalization vs denormalization

EasyDatabasesSchema design

What is database normalization, and when would you denormalize?

TL;DR

Normalization organizes tables so each fact is stored once, which prevents update anomalies (changing a customer's email in one row but not another). In practice, reaching third normal form (3NF) is the target: every non-key column depends on the key, the whole key, and nothing but the key. Denormalization deliberately duplicates data to make reads faster by avoiding joins, and you pay with extra writes and the risk of inconsistency. Normalize by default; denormalize for measured read hot spots.

Key points

  • 1NF: atomic values; no repeating groups or comma-separated lists in a column.
  • 2NF: no column depends on only part of a composite key.
  • 3NF: no column depends on another non-key column (store city_id, not both zip and a derived city).
  • Common denormalizations: a comments_count column on posts, copying the product name and price onto order_items (which is also correct, since the historical price must not change), and materialized views.
  • Keep denormalized copies in sync with transactions, triggers, or events; and know which copy is the source of truth.
  • Analytics warehouses use star schemas (fact and dimension tables), which are denormalized on purpose.

Example

sql
-- Normalized
orders(id, customer_id, created_at)
customers(id, name, email)

-- Denormalized counter for a hot read path
ALTER TABLE posts ADD COLUMN comments_count int NOT NULL DEFAULT 0;
-- incremented in the same transaction as INSERT INTO comments

Common follow-ups

  • Is storing the price on an order line denormalization? Technically it duplicates data, but it records a different fact: the price at the time of purchase. It's required for correctness.
  • How does NoSQL handle this? Document databases often embed related data on purpose, because the document is shaped for one read.

What interviewers look for

Tip

Explain what problem normalization solves (anomalies), roughly what 3NF means, and a concrete, justified denormalization.

  • Red flag: reciting normal form definitions with no idea why they matter.

Was this helpful?

Related questions