SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
  • Indexing
  • Partitioning
  • Replication
  • Sharding
  • Query Optimization
  • Denormalization
  • Materialized Views
  • Connection Pooling
  • Replication Models
  • Replication Lag
  • Quorum (R + W > N)
  • Shard Keys, Hot Shards and Resharding
  • Cross-Shard Joins
  • Backups, RPO, RTO and Disaster Recovery
  • Point-in-Time Recovery
  • Data Archiving and TTL
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Data and Storage/Database Scaling

Denormalization

Copy data on purpose to avoid slow joins, and pay for it with extra writes.

⏱ 12 min readIntermediateInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Denormalization means storing the same piece of data in more than one place on purpose, so reads need fewer joins. Reads get faster and simpler. Writes get heavier and riskier.

  • Normalization stores each fact once (clean, small, safe to update). Denormalization copies facts to where they are read.
  • It pays off when data is read much more than it changes.
  • You must keep the copies in sync, or the data will disagree with itself.

02Concept: What is it?

Good relational design is normalized: each fact lives in exactly one table. A customer's name is in the customers table, and orders only hold a customer_id. To show an order with the name, the database does a join. Joins are fine on small data. On huge data, or across shards, they get slow or impossible.

Normalized vs denormalized
Normalized (join on read)
🧾ordersid, item, customer_id
↔JOIN
👤customersid, name
Name stored once. Read needs a join.
Denormalized (one wide table)
🧾ordersid, item, customer_id, customer_name
Name copied into every order. No join.
The denormalized table repeats the name in each order, so one read has everything.

The idea is simple: do the work at write time instead of read time. You pay a little extra each time you write, so that each read is cheap.

🧠The one-sentence trade
Denormalization gives up storage and write simplicity to gain read speed. Use it for reads you do millions of times, not for everything.

03Real-Life Example

🍵The Shop Receipt
A shop keeps a customer card with the customer's name and address. Each sale slip says only "customer 7". To print a delivery label, the clerk has to find the card, read the address and write the label. That is normalized: the address is stored once, and it is easy to correct. Now a busy clerk starts writing the full name and address on every slip. Labels print at once. But when the customer moves, the clerk must fix every old slip, or some slips show the old address.
Shop
Database
The customer card (stored once)
A normalized table
Slip with only the customer number
A foreign key
Finding the card for every label
A join on every read
Address written on every slip
A denormalized copy
Customer moves: fix every slip
Update all copies (write cost)
Some slips show the old address
An update anomaly (stale copy)
Slips for last year's sales are never fixed
Historical snapshots (sometimes wanted!)
Where the cost moves
👀Normalized readjoin: more work
↔move the work
✍️Denormalized writecopy: more work
→↓so reads become
⚡Fast readone row
The work does not disappear. It moves from the read path to the write path.

04Why Do We Need It?

⚡Faster reads
One row or one document has everything the page needs.
🧩Avoid heavy joins
Joins across big tables, or across shards, are slow or not possible.
📈Read scaling
Simpler queries use less CPU, so the same machines serve more reads.
🌍Works across shards
If related data is copied together, a query hits one shard.
🧮Precomputed numbers
Store counts and totals (likes_count) instead of counting rows each time.
📄Fits NoSQL
Many NoSQL stores have no joins at all, so you design the data around the read.
Design the data for how it is read. If reads outnumber writes by a lot, copy data to where it is used.

05Where Do We Use It?

🏠Feeds and timelines
Store the author name and avatar inside each post, so a feed does not join per post.
🛒Product and order pages
Keep the product title and price at purchase time inside the order line.
🔢Counters
Keep comment_count on the post. Update it when comments are added.
📊Analytics and warehouses
Star schemas and wide tables avoid joins on huge data.
📄Document databases
Embed related data inside one document (an order with its items).
🔎Search indexes
Flatten many tables into one search document.

06Types / Parts / How It Works

Common denormalization patterns

PatternExampleCost
Copy a columnPut customer_name into orders.Update all copies if the name changes.
Precomputed aggregateposts.comment_count, orders.total.Update the number on every insert or delete. Races are possible.
Embed child rowsStore order items as a JSON array in the order (or a document).Large documents. Hard to query items alone.
Pre-joined tableA wide reporting table built from several tables.Must be rebuilt or kept in sync.
Summary tabledaily_sales (date, total) built from orders.Refreshed by a job or trigger.
Materialized viewThe database keeps and refreshes a stored query result.Storage and refresh cost (see Materialized Views).
Snapshot of historyCopy the price into the order line at purchase time.None really. This is often correct, not a bug.
How the copies stay in sync
👤Source of truthcustomers
→↓change
🔄Sync stepsame transaction, trigger, or event
→↓update copies
🧾Copiesorders.customer_name
Truth Sync mechanism Copies
Choose one. They differ in how fresh the copies are and how complicated the code is.
Normalized
one place per fact
  • Easy, safe updates
  • Smaller storage
  • Flexible queries
  • Reads need joins
Denormalized
copies where they are read
  • Very fast, simple reads
  • More storage
  • Heavier, riskier writes
  • Shaped for known queries
VisualizerRead cost vs write cost, and the update anomalyDrag reads per write from 1 to 1000. Then raise the copies and rename share. Finally, click 'Update only ONE copy' and see the data disagree.
Total work for 50 reads and 1 write (shorter bar is better)
Normalized (orders + customers, join on read)151.0 units
read 3 each, write 1.0
Denormalized (name copied into every order)53.7 units
read 1 each, write 3.7 on average
Read cost
3 vs 1
normalized vs denormalized
Average write cost
1.0 vs 3.7
normalized vs denormalized
Winner now
Denorm
64% less work
Break-even
2 : 1
reads per write needed (in this list)
With 50 reads for each write, the single wide table wins by 64%. Each read saves a join, and that saving is repeated 50 times, while the extra write work is paid only once.
Try the update anomaly: Asha changes her name
Normalized: 1 row to change
customers: id 7, name Asha Rao
#101 Keyboard (customer 7 = Asha Rao)
#102 Mouse (customer 7 = Asha Rao)
#103 Monitor (customer 7 = Asha Rao)
#104 Cable (customer 7 = Asha Rao)
Denormalized: 4 rows to change
All copies agree.
#101 Keyboard | Asha Rao
#102 Mouse | Asha Rao
#103 Monitor | Asha Rao
#104 Cable | Asha Rao

A simplified cost model in abstract units with a simulated, deterministic data set (no random numbers). Real costs depend on indexes, cache hits and row size. The shape is what matters: denormalization trades cheaper, simpler reads for more expensive and riskier writes.

07How to Use It / Steps / Implementation

Denormalize safely

  1. 1
    Start normalized
    A clean model is easier to change. Do not copy data on day one.
  2. 2
    Find the hot read
    Use query stats to find the slow or very frequent reads that join many tables.
  3. 3
    Check the read to write ratio
    Copy only data that is read often and changes rarely (a product title, an author name).
  4. 4
    Try cheaper fixes first
    Indexes, query tuning, caching, or a materialized view may be enough.
  5. 5
    Pick a source of truth
    One table owns the value. Copies are derived and can be rebuilt from it.
  6. 6
    Choose how to sync
    Same transaction (strong), database trigger, event or change-data-capture stream (eventually), or a nightly rebuild (stale but simple).
  7. 7
    Add a repair job
    A script that compares copies with the source and fixes drift. Copies always drift eventually.
  8. 8
    Document it
    Write down which columns are copies and where the truth lives.
⚠️Counters and races
Two users add a comment at the same time. If both read count = 10 and write 11, one comment is lost from the count. Use an atomic update (SET count = count + 1), and a repair job that recounts now and then.
Good fit: reads per write10 : 1, 100 : 1 or more

08Key Terms to Know

TermMeaning in easy words
NormalizationDesigning tables so each fact is stored once
DenormalizationCopying data on purpose to speed up reads
JoinCombining rows from two tables using a shared key
Source of truthThe one place whose value is correct
Update anomalyCopies disagree because some were not updated
Derived dataData computed or copied from other data
Read:write ratioHow many reads happen for each write
Write amplificationOne logical change causing many physical writes
EmbeddingStoring child data inside the parent record or document
Change data capture (CDC)A stream of every change in a database, used to update copies
Star schemaA warehouse design: one wide facts table surrounded by small dimension tables

09Pros, Cons and Trade-offs

✅ Pros
  • Much faster, simpler reads
  • Fewer or no joins
  • Fits sharded and NoSQL systems
  • Cheap counters and summaries
  • Can store history as it was
⚠️ Cons
  • Extra storage
  • Writes touch more rows
  • Copies can go stale or disagree
  • More code to keep in sync
  • Harder to change the shape later
  • Bugs can be hard to see

Trade-offs

ChoiceWe gainWe lose
Copy data into the read tableNo join on readUpdate work and anomaly risk
Store a counterO(1) countRace conditions, drift
Sync in the same transactionCopies always agreeSlower, more locks, same database only
Sync with eventsScales, decoupledEventual consistency, extra moving parts
Rebuild nightlySimpleData is up to a day old
Stay normalizedClean and safeJoins may become the bottleneck

10Common Problems and Mistakes

Common mistakes

  1. Denormalizing too early. You pay the cost before you know you have a read problem.
  2. Copying data that changes often. Every change becomes a huge update.
  3. No source of truth. Nobody knows which copy is right when they disagree.
  4. Forgetting one writer. A new service updates the source without updating the copies.
  5. Non-atomic counters. Read, add one, write back. Concurrent requests lose updates.
  6. No repair job. Small drift grows silently for months.
  7. Mixing up history with drift. A price copied at purchase should not change when the product price changes.

Things to watch

🧨Huge fan-out updates
Renaming one celebrity can mean updating millions of copies. Consider reading that field live.
🕰️Eventual consistency
With async sync, copies are briefly stale. Make sure the product is fine with that.
💾Storage growth
Copies multiply bytes. Also hurts cache and memory use.
🔐Privacy
Deleting a user means deleting every copy of their data too.

11Real-World Examples

🐦Social feeds
Posts carry the author name and avatar. Feeds are often precomputed per user (fan-out on write).
🍃MongoDB
Its data modelling advice is to embed data that is read together, and to use references when it is not.
🪐Cassandra and DynamoDB
Tables are designed per query, so the same data is stored several times in different shapes.
🏬Data warehouses
Wide, flattened fact tables are common for fast analytics.
🛍️Order history
Orders store the product name and price at purchase time so old orders never change.
🔎Elasticsearch
Each search document is a flattened view built from several tables.
📝Note
These are general ideas. Each product has its own modelling advice.
Mini case: a post with its author
👤userstruth
→↓profile edited
📨EventUserUpdated
→↓worker
📝postsauthor_name, avatar copies
→↓one row read
🏠Feed page
Keep the author in one table. Copy name and avatar into the post for the feed. Fix copies from an event when the author edits their profile.

12Related Topics to Read Next

Relational Databases→

Normalization is the starting point.

Materialized Views→

Let the database maintain a stored, pre-joined result.

Query Optimization→

Try indexes and tuning before copying data.

Sharding→

Joins across shards are hard, so related data is copied together.

Document Databases→

Embedding is denormalization by design.

SQL vs NoSQL→

How each style handles joins and copies.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔What: store copies or precomputed values on purpose to avoid joins.
  • ✔Why: reads become one lookup, and reads usually outnumber writes.
  • ✔Cost: more storage, heavier writes, and copies that can disagree.
  • ✔Good fit: read-heavy, rarely changing data, big or sharded datasets, NoSQL.
  • ✔Keep in sync: same transaction, triggers, events (CDC), or a rebuild job.
  • ✔Always: one source of truth and a repair job.
  • ✔Order: normalize first, then index, cache, materialize, and only then copy.
  • ✔One line: “Pay a little more on every write so that every read is cheap.”
← Previous
Query Optimization
Next →
Materialized Views