Bird
Raised Fist0
HLDsystem_design~12 mins

Database normalization vs denormalization in HLD - Architecture Patterns Compared

Choose your learning style10 modes available
System Overview - Database normalization vs denormalization

This system explains the difference between database normalization and denormalization. Normalization organizes data to reduce duplication and improve consistency. Denormalization combines data to speed up read operations at the cost of some duplication.

Key requirements include balancing data integrity, query speed, and storage efficiency depending on the use case.

Architecture Diagram
User
  |
  v
Load Balancer
  |
  v
API Gateway
  |
  +-------------------+
  |                   |
Cache (Normalized)   Cache (Denormalized)
  |                   |
Normalized DB      Denormalized DB
  |                   |
Response            Response
Components
User
user
Initiates requests to the system
Load Balancer
load_balancer
Distributes incoming requests evenly to API Gateway
API Gateway
api_gateway
Routes requests to either normalized or denormalized database services
Normalized DB
database
Stores data in normalized form to reduce duplication and maintain integrity
Denormalized DB
database
Stores data in denormalized form to optimize read performance
Cache (Normalized)
cache
Caches frequently accessed normalized data to reduce DB load
Cache (Denormalized)
cache
Caches frequently accessed denormalized data for faster reads
Response
response
Sends processed data back to the user
Request Flow - 8 Hops
User → Load Balancer
Load Balancer → API Gateway
API Gateway → Cache (Normalized or Denormalized)
Cache (Normalized or Denormalized) → API Gateway
API Gateway → Normalized DB or Denormalized DB
Normalized DB or Denormalized DB → API Gateway
API Gateway → Cache (Normalized or Denormalized)
API Gateway → Response
Failure Scenario
Component Fails:Cache (Normalized or Denormalized)
Impact:Cache misses increase, causing more direct database queries and higher latency
Mitigation:System falls back to database queries; cache is rebuilt over time; consider cache replication or failover
Architecture Quiz - 3 Questions
Test your understanding
Which component reduces database load by storing frequently accessed data?
ALoad Balancer
BCache
CAPI Gateway
DUser
Design Principle
This architecture demonstrates the trade-off between normalization and denormalization in databases. Normalization ensures data integrity and reduces duplication, while denormalization improves read speed by storing combined data. Caches are used to optimize performance by reducing database load. The system routes requests through load balancers and API gateways to maintain scalability and control.

Practice

(1/5)
1. What is the main goal of database normalization?
easy
A. To reduce data duplication and improve data accuracy
B. To combine tables for faster data retrieval
C. To increase storage space usage
D. To make queries more complex

Solution

  1. Step 1: Understand normalization purpose

    Normalization organizes data to minimize duplication and maintain consistency.
  2. Step 2: Compare with other options

    Combining tables and increasing storage are characteristics of denormalization, not normalization.
  3. Final Answer:

    To reduce data duplication and improve data accuracy -> Option A
  4. Quick Check:

    Normalization = reduce duplication [OK]
Hint: Normalization means less duplication, more accuracy [OK]
Common Mistakes:
  • Confusing normalization with denormalization
  • Thinking normalization increases storage
  • Believing normalization makes queries faster
2. Which of the following is a correct statement about denormalization?
easy
A. It always reduces data redundancy
B. It combines tables to speed up read queries
C. It enforces strict data integrity rules
D. It splits data into many small tables

Solution

  1. Step 1: Identify denormalization effect

    Denormalization merges tables to reduce joins and speed up reads.
  2. Step 2: Eliminate incorrect options

    Reducing redundancy and splitting tables are normalization traits; strict integrity is also normalization.
  3. Final Answer:

    It combines tables to speed up read queries -> Option B
  4. Quick Check:

    Denormalization = combine tables for speed [OK]
Hint: Denormalization speeds reads by merging tables [OK]
Common Mistakes:
  • Mixing up normalization and denormalization goals
  • Assuming denormalization reduces redundancy
  • Thinking denormalization splits tables
3. Consider a database where customer and order data are stored in separate tables (normalized). If we denormalize by combining them into one table, what is the likely effect on query performance?
medium
A. Write queries become faster, read queries become slower
B. Both read and write queries become slower
C. No change in query performance
D. Read queries become faster, write queries may slow down

Solution

  1. Step 1: Analyze denormalization impact on reads

    Combining tables reduces joins, so read queries speed up.
  2. Step 2: Analyze impact on writes

    More data in one table means writes may take longer due to larger rows and possible duplication.
  3. Final Answer:

    Read queries become faster, write queries may slow down -> Option D
  4. Quick Check:

    Denormalization = faster reads, slower writes [OK]
Hint: Denormalize to speed reads, but writes may slow [OK]
Common Mistakes:
  • Assuming writes always get faster
  • Ignoring join cost in normalized reads
  • Believing no performance change occurs
4. A developer denormalized a database by duplicating user address data in multiple tables but forgot to update all copies when the address changed. What problem does this cause?
medium
A. Data inconsistency due to redundant copies
B. Faster query performance without side effects
C. Reduced storage space usage
D. Improved data integrity

Solution

  1. Step 1: Understand denormalization risk

    Duplicating data can cause inconsistencies if updates are not synchronized.
  2. Step 2: Evaluate consequences

    Failing to update all copies leads to conflicting data, harming accuracy.
  3. Final Answer:

    Data inconsistency due to redundant copies -> Option A
  4. Quick Check:

    Denormalization risk = inconsistency if not managed [OK]
Hint: Duplicated data needs careful updates to avoid inconsistency [OK]
Common Mistakes:
  • Assuming denormalization always improves integrity
  • Ignoring update complexity in denormalized data
  • Thinking denormalization reduces storage
5. You are designing a high-traffic e-commerce system. You want to optimize for fast product search and order history retrieval. Which approach balances normalization and denormalization best?
hard
A. Normalize all data strictly to avoid any duplication
B. Normalize product data and denormalize order history
C. Denormalize product data for fast search, normalize order history for accuracy
D. Denormalize all tables to speed up all queries

Solution

  1. Step 1: Identify system needs

    Fast product search benefits from denormalization to reduce joins and speed reads.
  2. Step 2: Consider order history requirements

    Order history needs accuracy and consistency, so normalization is better.
  3. Step 3: Choose balanced approach

    Denormalize product data for speed, normalize order data for integrity.
  4. Final Answer:

    Denormalize product data for fast search, normalize order history for accuracy -> Option C
  5. Quick Check:

    Balance = denormalize for speed, normalize for accuracy [OK]
Hint: Denormalize for speed, normalize for accuracy in critical data [OK]
Common Mistakes:
  • Denormalizing everything causing data errors
  • Normalizing all data causing slow reads
  • Ignoring trade-offs between speed and accuracy
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard