Normalization & Schema Design

Functional dependencies, update anomalies, 1NF through BCNF with worked examples, when to denormalise, and practical schema design advice.

Intermediate 4 min readLesson 5 of 14 Interview Q&A

Normalisation organises tables so that each fact is stored exactly once. That prevents inconsistencies when data changes. Denormalisation deliberately duplicates data for speed. Good schema design knows when to use each.

The problem: anomalies

A single wide table of orders:

order_idcustomercustomer_emailproductproduct_priceqty
1Adaada@x.ioKeyboard801
1Adaada@x.ioMouse252
2Alanalan@x.ioKeyboard801
AnomalyExample
UpdateAda changes her email: you must update every one of her rows, and missing one leaves inconsistent data
InsertYou can't add a new product until someone orders it
DeleteDeleting order 2 also deletes the only record that Alan exists

The cause: the table mixes facts about orders, customers and products.

Functional dependencies

X → Y ("X determines Y") means: rows with the same X always have the same Y.

  • customer → customer_email
  • product → product_price
  • (order_id, product) → qty

Normal forms are rules about which dependencies a table may contain.

The normal forms

  1. 1NF — every column holds a single atomic value; no repeating groups or lists (no phones = "555-1, 555-2", no phone1, phone2, phone3 columns).
  2. 2NF — 1NF, and no non-key column depends on only part of a composite key. (product_price depends only on product, not on (order_id, product) → move it out.)
  3. 3NF — 2NF, and no non-key column depends on another non-key column (no transitive dependencies). (customer_email depends on customer, not on the order → move it out.)
  4. BCNF — for every dependency X → Y, X must be a super key. A slightly stricter 3NF that handles rare edge cases with overlapping candidate keys.

The normalised design

FKFKFKcustomersid · name · emailordersid · customer_id · created_atorder_itemsorder_id · product_id · qty · unit_priceproductsid · name · price

Each fact now lives in one place. Note order_items.unit_price: it looks like duplication of products.price, but it's a different fact — the price at the time of purchase — which must not change when the catalogue price does. Recognising which "duplicates" are really separate facts is the art of modelling.

Higher normal forms

4NF removes independent multi-valued facts stored together (a person's skills and languages in one table create a cross product). 5NF deals with join dependencies. They rarely come up in practice; 3NF/BCNF is the usual target.

Denormalisation

Normalised schemas need joins, and joins at very large scale or in hot paths can be expensive. Denormalisation stores redundant data to speed up reads:

TechniqueExampleCost
Duplicated columnsStore customer_name on orders for listing pagesMust update both on change
Precomputed aggregatesposts.comment_countKeep it in sync (triggers, the app, or async jobs)
Materialised viewsDashboard tables refreshed periodicallyStaleness
Embedded documentsMongoDB order document containing its itemsHarder to query items across orders
Star schemaAnalytical fact table + dimension tablesDesigned for reads, loaded by ETL

OLTP vs OLAP schemas

OLTP (transactional)OLAP (analytical)
WorkloadMany small reads and writesFew huge scans and aggregations
SchemaNormalised (3NF)Denormalised star / snowflake schemas
StorageRow-orientedColumn-oriented
ExamplesPostgreSQL, MySQLSnowflake, BigQuery, ClickHouse, DuckDB

Practical schema design checklist

  • Pick clear, consistent names (snake_case, singular or plural, but consistent).
  • Give every table a primary key; add UNIQUE constraints on natural keys.
  • Declare foreign keys and index the FK columns.
  • Use the right types: TIMESTAMPTZ for instants, NUMERIC for money, BOOLEAN, enums or lookup tables for fixed sets.
  • Prefer NOT NULL; allow NULL only when "unknown" is genuinely meaningful.
  • Add created_at / updated_at; consider soft deletes (deleted_at) when you need history.
  • Model the domain, not the screens — UIs change faster than the data.
Key takeaways
  • Normalisation stores each fact once to avoid update, insert and delete anomalies.
  • 1NF: atomic values. 2NF: no partial dependencies. 3NF: no transitive dependencies. BCNF: every determinant is a key.
  • "The key, the whole key, and nothing but the key."
  • Denormalise deliberately for read performance, with a plan for consistency.
  • OLTP favours normalised row stores; analytics favours star schemas in column stores.
Interview questions
QWhen would you denormalise?medium

When a hot read path needs data from many joins and measurements show the joins are the bottleneck; when you need precomputed aggregates (counters, totals); or in analytics and read-optimised stores. Always define how the copies stay consistent: transactions, triggers, or asynchronous events with acceptable staleness.