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
  • Common Database Types
  • SQL vs NoSQL
  • ACID Transactions
  • B-Trees and B+ Trees
  • LSM Trees
  • Transaction Isolation Levels
  • Locking and MVCC
  • Normalization
  • OLTP vs OLAP
  • BASE and PACELC
  • Write-Ahead Log (WAL)
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 Basics

Normalization

Store each fact once, by splitting data into tables, so it cannot disagree with itself.

โฑ 13 min readBeginnerMust KnowInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Normalization means organising tables so that every fact is stored exactly once. If a customer's city is written in one place, it can never disagree with itself.

  • You split one wide, repetitive table into several small tables, and link them with keys.
  • It prevents update, insert and delete anomalies: bugs where a change is made in some copies of a fact but not others.
  • The price is more joins when you read. That is why systems sometimes denormalize on purpose later.

02Concept: What is it?

Imagine one spreadsheet that holds every order. Each row repeats the customer's name, city and zip code, plus the product's name and price. It looks easy, but the same fact appears again and again. This causes three kinds of trouble, called anomalies:

AnomalyWhat goes wrongExample
UpdateYou change a fact in some rows but not all, so the data contradicts itselfAsha moves to Mumbai. Two of her five rows say Pune, three say Mumbai.
InsertYou cannot store a fact until something else existsYou cannot add a new product until someone orders it.
DeleteRemoving one thing destroys an unrelated factDeleting a customerโ€™s only order also deletes the productโ€™s price.

Normalization fixes this by following a few rules, called normal forms. Each form removes one kind of repetition.

FormRule in plain wordsFixes
1NFEach cell holds one value. No lists in a cell, no repeating columns like phone1, phone2, phone3.Cells you cannot search or change cleanly
2NFEvery non-key column depends on the whole key, not on a part of it. (Only matters when the key has several columns.)Facts about the order stored on every order line
3NFNon-key columns depend on the key and nothing else. No column that really depends on another non-key column.Facts like zone that depend on zip, not on the order
BCNFA slightly stricter 3NF: every determining column must be a key.Rare edge cases
๐Ÿง One sentence to remember
Every non-key column should depend on "the key, the whole key, and nothing but the key".
One messy table becomes small, linked tables
Before
๐Ÿงพorderscustomer, city, zip, product, price...
Repeated factsmany copies
โ†’โ†“split by facts
After
๐Ÿ“ฆorder_lines
๐Ÿงพorders
๐Ÿ‘คcustomers
๐Ÿท๏ธproducts
Repeated factsone copy each
Each fact lives in exactly one place. Keys connect the pieces.

03Real-Life Example

๐ŸตThe Address Book on Sticky Notes
Suppose every friend has their own sticky note, and each note lists the friend, the street they live on and the street's postal area. Three friends live on the same street, so the street's postal area is written three times. When the post office changes the area code, you must find and fix three notes. Miss one, and your notes disagree. A better way: one card per street with its area code, and each friend's note simply says "lives on Oak Street". Now the area code is written once.
Sticky notes
Database
One note per friend with everything written out
One wide table with repeated facts
The area code written on three notes
A repeated value that can drift apart
Fixing only two of the three notes
An update anomaly
One card per street
A separate table with a primary key
โ€œLives on Oak Streetโ€ on a friendโ€™s note
A foreign key that points to that table
Looking up the street card to find the area code
A join
Copying the area code back onto every note for speed
Denormalization

04Why Do We Need It?

๐ŸŽฏOne truth
A fact stored once cannot contradict itself.
๐Ÿ› ๏ธSafe changes
Updating, inserting and deleting each touch one place.
๐Ÿ“‰Less storage
No copies of the same text on millions of rows.
๐ŸงฑClear model
Each table is about one thing, which makes the design easy to understand.
๐Ÿ”’Easier rules
Keys and constraints can protect each fact in one place.
๐ŸงชFewer bugs
Whole classes of โ€œwhy do these two screens show different values?โ€ disappear.
Normalize to keep the data correct. Denormalize later, on purpose, only where reads are too slow.

05Where Do We Use It?

๐Ÿ—„๏ธRelational databases
The default way to design tables in PostgreSQL, MySQL and similar systems.
๐Ÿ’ณOLTP systems
Shops, banks and booking apps with many small, correct updates.
๐Ÿ‘ฅCustomer and account data
Names, addresses and settings that change and must stay consistent.
๐Ÿ“šReference data
Countries, currencies, product catalogues: one row each, referenced everywhere.
๐ŸงพOrders and invoices
Orders, order lines and products are the textbook example.
๐ŸงญDesign interviews
Drawing a clean schema is part of almost every data question.

06Types / Parts / How It Works

The normal forms, one step at a time

From messy to 3NF
๐ŸงพMessylists in cells, repeated facts
โ†’โ†“atomic cells
1๏ธโƒฃ1NFone value per cell
โ†’โ†“split by key part
2๏ธโƒฃ2NFno partial dependency
โ†’โ†“split transitive facts
3๏ธโƒฃ3NFthe key and nothing else
Repeated Each fact once
Each step removes one kind of repeated fact.
ConceptMeaningExample
Primary keyA column (or columns) that identifies a row uniquelyorder_id, or (order_id, line_no)
Foreign keyA column that points to a row in another tableorders.customer_id โ†’ customers.id
Partial dependencyA column depends on only part of a composite keycustomer city depends on order_id, not on (order_id, line_no)
Transitive dependencyA column depends on another non-key columnzone depends on zip, and zip depends on the key

Normalized vs denormalized

NormalizedDenormalized
Facts storedOnceSeveral times, on purpose
WritesSimple and safe: change one rowMore work: change every copy
ReadsNeed joinsFast, often one table
Good forLive apps with many updates (OLTP)Read-heavy reports and caches
RiskSlow reads if you join too muchCopies drifting apart
VisualizerFrom one messy table to 3NF, with exact countsSwitch between the four stages and watch the tables split. Press the button to change Asha's city and count how many rows have to change.
How normalized is the data?
orders (everything in one table)
Imagine the Asha rows had a list like "Pen, Book" in one cell. That breaks 1NF.
orderlinecustomercityzipzoneproductpriceqty
11AshaPune411001WestPen210
12AshaPune411001WestBook91
21BenLeedsLS1NorthPen24
31AshaPune411001WestPen26
32AshaPune411001WestLamp251
41ChenLeedsLS1NorthBook92
51BenLeedsLS1NorthLamp251
61ChenLeedsLS1NorthPen23
Cells stored
72
of 72 in the messy table
Rows to change
4
for Asha's city
Cells saved
0
vs the messy table
Tables to read a line
1
joined to see one full order line
Asha's city is stored on 4 rows. Change it in only some of them and the table disagrees with itself (an update anomaly).

A fixed, made-up dataset of 8 order lines. The counts are exact for this data, but real savings depend on how much your data repeats. In the 3NF view the city lives in a zip-code table purely to show a transitive dependency (zip โ†’ city and zone), which is a simplification.

07How to Use It / Steps / Implementation

Normalizing a table step by step

  1. 1
    Find the key
    Decide what makes a row unique. For an order line it may be (order_id, line_no).
  2. 2
    Make cells atomic (1NF)
    One value per cell. Replace โ€œPen, Bookโ€ in one cell with one row per item. Replace phone1, phone2 with rows in a phones table.
  3. 3
    Remove partial dependencies (2NF)
    Ask of each column: does it depend on the whole key? Customer and order date depend on order_id only, so move them to an orders table.
  4. 4
    Remove transitive dependencies (3NF)
    Ask: does it depend on something other than the key? If zone depends on zip, move zip and zone to their own table.
  5. 5
    Connect with foreign keys
    Each split table points to the next with a foreign key, and the database enforces that the pointer is valid.
  6. 6
    Check with a change test
    For each fact, ask: if it changes, how many rows must I edit? The answer should be one.
  7. 7
    Denormalize only with proof
    If a measured query is too slow, add a copy or a summary on purpose, and write down how it is kept in sync.
๐Ÿ’กDo not over-split
Going further than 3NF rarely helps in practice. Stop when each fact lives in one place and the joins are still reasonable. Add indexes on the foreign keys you join on.
โš ๏ธNoSQL is different
Document and wide-column databases often store data in a nested, repeated shape on purpose, because they avoid joins. Normalization is mainly a relational idea.

08Key Terms to Know

TermMeaning in easy words
NormalizationOrganising tables so each fact is stored once
AnomalyA bug caused by a repeated fact: update, insert or delete
Normal formA named rule for how tables should be arranged (1NF, 2NF, 3NF)
Primary keyThe column or columns that identify a row
Foreign keyA column that points to a row in another table
Atomic valueA single value in a cell, not a list
Partial dependencyA column that depends on only part of a composite key
Transitive dependencyA column that depends on another non-key column
JoinCombining rows from two tables using a key
DenormalizationCopying data back on purpose to make reads faster
RedundancyThe same fact stored in more than one place

09Pros, Cons and Trade-offs

โœ… Pros
  • Each fact is stored once, so it stays consistent
  • Updates, inserts and deletes are simple and safe
  • Smaller storage
  • A clean model that is easy to understand
  • Constraints can protect each fact
โš ๏ธ Cons
  • More tables and more joins to read
  • Slower for read-heavy reports
  • Harder to shard across machines
  • Queries are longer to write
  • Over-normalizing adds complexity for little gain

Trade-offs

ChoiceWe gainWe lose
Fully normalized (3NF)Correctness, simple writesJoins on every read
Partly normalizedA balance of bothNeeds judgement about what to copy
DenormalizedFast readsCopies to keep in sync, risk of drift
Very high normal formsTiny theoretical gainsMany tiny tables, slow queries
Normalized + indexes on keysFast joins and correct dataExtra index storage and write cost
Normalized source + summary tablesCorrect data and fast reportsA refresh job to maintain

10Common Problems and Mistakes

Common mistakes

  1. Lists in a cell. Comma-separated tags or ids in one column cannot be indexed or joined cleanly.
  2. Repeating columns. Columns such as item1, item2, item3 limit you and make queries awkward. Use a child table.
  3. Copying a fact into many tables with no plan for keeping the copies in sync.
  4. Forgetting foreign keys. Without constraints, a row can point to something that no longer exists.
  5. Normalizing everything blindly. A report that joins ten tables on every page load may need a summary table.
  6. Denormalizing too early. Copies are easy to add and hard to keep correct. Measure first.
  7. Treating a natural value as a key. Emails and names change. Prefer a stable generated id as the primary key.

Things to watch

๐ŸงฎJoin cost
Many joins on big tables can be slow. Index the join columns and check query plans.
๐Ÿ”€Sharding
Joins across shards are expensive, so sharded systems often denormalize.
๐ŸงพHistory
If an old order must keep the price at that time, store the price on the order line on purpose.
๐ŸชžDrift
Any intentional copy needs a rule, a job or a trigger that keeps it in sync.

11Real-World Examples

๐Ÿ›’Online shops
Customers, orders, order lines, products and addresses are separate tables linked by keys.
๐ŸฆBanking
Accounts, customers and transactions are kept apart so each fact has one home.
๐ŸฅHealthcare records
Patients, visits and prescriptions are linked records, not one giant sheet.
๐Ÿ“ŠData warehouses
Often denormalized into wide tables (star schemas) for fast reports, fed from normalized source systems.
๐Ÿ“ฑSocial apps
Users and posts live in their own tables, with counts copied for speed.
๐ŸงพInvoices
The price at the time of sale is deliberately copied onto the invoice line, so later price changes do not rewrite history.
๐Ÿ“Note
Normal forms are guidelines for correctness, not laws. Real systems mix normalized core tables with a few deliberate copies.
Mini case: normalize the source, denormalize the report
๐Ÿ—„๏ธNormalized tablessource of truth
โ†’โ†“copy and join
๐Ÿ“‹Summary tabledenormalized
โ†’โ†“fast reads
๐Ÿ“ˆDashboard
Keep the source of truth tidy, and build fast read copies from it.

12Related Topics to Read Next

Denormalizationโ†’

The deliberate opposite, used when reads are too slow.

Relational Databasesโ†’

Where normalized tables and joins live.

Indexingโ†’

Makes the joins that normalization needs fast.

OLTP vs OLAPโ†’

Live apps favour normalized data, analytics often does not.

Materialized Viewsโ†’

A saved joined result, so reads do not repeat the joins.

Shardingโ†’

Why joins across shards push designs towards copies.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • โœ”What: store every fact once, split into linked tables.
  • โœ”Why: avoid update, insert and delete anomalies.
  • โœ”1NF: one value per cell, no lists, no repeating columns.
  • โœ”2NF: depend on the whole key, not part of it.
  • โœ”3NF: depend on the key and nothing but the key.
  • โœ”Cost: more joins on reads. Index foreign keys.
  • โœ”Then: denormalize on purpose, only for measured slow reads.
  • โœ”One line: "The key, the whole key, and nothing but the key."
โ† Previous
Locking and MVCC
Next โ†’
OLTP vs OLAP