$ man normalization # store each fact once, or where it is read?

Normalization or Denormalization

Normalization means storing each fact exactly once and linking tables with keys: a customer’s city lives in one customers row, and orders point to it by customer_id. Denormalization means deliberately copying facts next to where they are read, such as the city on every order row, so queries need fewer joins. Normalization protects correctness when data changes; denormalization buys read speed and simplicity at the cost of keeping copies in sync.

What goes wrong with copies

$ UPDATE ... SET city = 'Toronto' WHERE customer = 'Sam'
An update anomaly, and the normalized fix
orders · denormalized ORDERCUSTOMERCITYAMOUNT 1001SamNew York250 1002AliceChicago120 1003SamNew York450 1004SamNew York980 Sam moved: the city is stored 3 times Toronto Toronto job updated 2 of 3 rows: Sam now lives in 2 cities customers IDNAMECITY 7SamToronto 8AliceChicago UPDATE customers … → 1 row orders ORDERCUSTOMER_IDAMOUNT 10017250 10028120 10037450 10047980 JOIN on customer_id
  1. A denormalized orders table repeats the customer's name and city on every order.
  2. Sam moves to Toronto. The fact "where Sam lives" is stored three times, so the update must find and change all three rows.
  3. A job (or a race with another write) changes only two. The table now contradicts itself: an update anomaly.
  4. Normalized: the city lives once in customers; orders keep only customer_id. The move is a one-row update and cannot be half-applied.
  5. The price: every query that shows an order with its city now needs a JOIN. On one machine that is cheap; across shards or in a giant fact table it can be the slowest part of the query.

Normal forms, briefly

Each normal form removes one kind of redundancy. In practice, aiming for 3NF in transactional databases covers almost everything.

Form Rule Violation example Fix
1NF One value per cell, no repeating groups phones = '212-555-0101, 416-555-0199' A customer_phones table
2NF 1NF, and every column depends on the whole key In order_items(order_id, product_id, product_name), the name depends only on product_id Move names to products
3NF 2NF, and no column depends on another non-key column orders(customer_id, customer_city): city depends on the customer, not the order Move city to customers
BCNF Every determinant is a candidate key Rare edge cases with overlapping keys Split the table further

Normalization also prevents insert anomalies (cannot store a new customer until they order) and delete anomalies (deleting Alice’s only order deletes the fact that Alice exists).

Where each one wins

Normalize Denormalize
Workload OLTP: many small reads and writes OLAP and read-heavy APIs
Data changes Often Rarely, or append-only (events, facts)
Correctness risk Low: one copy Copies can drift; needs pipelines or triggers to sync
Reads Need joins One table or one document
Storage Smaller Larger (cheap with columnar compression)
Typical home PostgreSQL, MySQL app schemas Star schemas, wide tables in BigQuery/ClickHouse, Cassandra and DynamoDB tables, search indexes

Why distributed systems lean on denormalization

On one machine a join is a memory operation. When tables are sharded differently, a join means moving data across the network (a shuffle), which is often the most expensive step in a Spark or Trino query. So distributed designs either:

  • Co-locate related data by sharding both tables on the same key (all of a customer’s orders on the customer’s shard), or
  • Denormalize: Cassandra and DynamoDB model “one table per query”; Elasticsearch documents embed what they display; warehouses use wide fact tables and small dimension tables that can be broadcast to every node.

The usual pattern in data platforms is both: a normalized source of truth in the operational database, and denormalized, rebuildable copies (warehouse tables, search indexes, caches) fed by ELT or CDC. Because they can be rebuilt from the source, drift is fixable.

Common mistakes

  • Denormalizing an OLTP schema up front “for performance” before measuring. Indexes and a read replica usually suffice.
  • Modelling a warehouse in 3NF and making every analyst join 15 tables. Use a dimensional model.
  • Confusing denormalization with history. An order should store the price at purchase time. That is a separate fact, not a redundant copy of products.price. Likewise, if you need “city at the time of the order”, use a slowly changing dimension, not a live join.
  • Denormalized copies with no owner. Every copy needs a pipeline that keeps it fresh and a way to rebuild it.

Learning Resources

Books

  • Designing Data-Intensive Applications (2nd ed.), Martin Kleppmann and Chris Riccomini: the chapter on data models and query languages
  • The Data Warehouse Toolkit, Ralph Kimball and Margy Ross: dimensional modelling

Articles and docs

Videos