Kazi Rahamatullah
Kazi Rahamatullah
AboutProjectsBlogContact
UsesBooks
ResumeView CV
Kazi Rahamatullah

© Copyright 2026 Kazi Rahamatullah

AboutProjectsBlogBooksUses
Twitter/XGitHubProduct HuntCodeSandbox
Back to Blog
System DesignData ModelingDatabaseSQLIndexing

System Design: Data Modeling

How entities are stored, related, and indexed — with an interactive ER explorer, normalization trade-offs, and interview reasoning for scalable schemas.

Jul 8, 20263 min read

Introduction

Quote

If you cannot explain how entities are stored, how relations work, and where indexes belong — then scale is just noise.

Data modeling answers three questions before you shard, replicate, or cache anything:

  1. What are the core entities?
  2. How do they relate (1:1, 1:N, N:M)?
  3. Which queries must be fast — and therefore need indexes?

This guide walks through a practical e-commerce schema and lets you explore entities interactively.

← Back to System Design overview

Core concepts

Entities and keys

Every table needs a primary key — usually a surrogate id (UUID or bigint) even when a natural key exists (email, SKU). Surrogate keys keep joins stable when business identifiers change.

Relationships

TypeExampleStorage pattern
1:1User ↔ ProfileFK on one side, or shared PK
1:NUser → Ordersuser_id on orders
N:MOrders ↔ ProductsJunction table order_items

Indexes

Indexes speed up reads but slow writes. Add them for:

  • Foreign keys used in joins (user_id)
  • Filter columns (status, created_at)
  • Unique business keys (email, sku)

Warning

Over-indexing is real. Each index adds write amplification. Profile indexes against actual query plans, not assumptions.

Interactive ER explorer

Click each entity below to inspect fields, indexes, and relationships.

Interactive ER Explorer

Click an entity to inspect fields, indexes, and relationships.

Selected: users

Fields

  • • id (PK)
  • • email (unique)
  • • name
  • • created_at

Indexes

  • • PRIMARY (id)
  • • UNIQUE (email)
  • • INDEX (created_at)

Relationships

users → orders (1 : N)

Normalization vs denormalization

Normalized schemas reduce duplication and keep updates simple. Denormalized schemas duplicate data for faster reads — common in analytics, feeds, and search indexes.

Tip

Normalize first. Denormalize only when you measure a read bottleneck and can accept slower writes or eventual consistency for that slice of data.

Example: order totals

Normalized:

sql
SELECT o.id, SUM(oi.qty * p.price) AS total
FROM orders o
JOIN order_items oi ON oi.order_id = o.id
JOIN products p ON p.id = oi.product_id
WHERE o.id = 501
GROUP BY o.id;

Denormalized: store orders.total updated on write — faster read, more logic on insert/update.

Interview checklist

Interview Answer

When asked about data modeling: (1) list entities from use cases, (2) draw cardinalities, (3) name the hot queries, (4) propose indexes for those queries, (5) mention partition/shard key only if scale requires it. Skip sharding until single-DB limits are estimated.

StepQuestion to answer
1Who are the actors and what do they create/read?
2What is 1:N vs N:M?
3Read-heavy or write-heavy?
4Which columns appear in WHERE and ORDER BY?
5When does one DB stop being enough?

Back to index


Share this article

XLinkedInFacebook
Kazi Rahamatullah

Written by

Kazi Rahamatullah

FullStack Developer

X / TwitterGitHubLinkedIn

Subscribe to my newsletter

Stay up to date and get notified when I share new contents.

No spam ever, unsubscribe anytime