Data Modeling Lab

Turn product requirements and access patterns into a correct, maintainable, performant data model. Not an ER-diagram editor: you start from requirements, discover entities, wire relationships and constraints, design from access patterns, plan indexes with their costs, and end with a senior-style schema review.

  1. Requirements
  2. Entities
  3. Relationships
  4. Constraints
  5. Access Patterns
  6. Normalization
  7. Indexes
  8. Schema
  9. Queries
  10. Review
Case studies — start from requirements
Challenge — requirements only
0 entities · 0 rels · 0 idx

What are the core entities?

Add them one at a time. For each candidate ask: is it an entity (has identity and a lifecycle), an attribute (describes an entity), or an event (something that happened)?

try:
Modeling decisions here are educational. Once a schema feels right, run its queries in the SQL playground and see how the index is stored.

Modeling concepts, four altitudes deep

Keys, time, money, lifecycle, tenancy, evolution — each explained beginner → internals, with the internals level linking into Database Internals.

Natural vs Surrogate Keys
Should the primary key be a real-world value or a meaningless generated id?
Two ways to name a row

A natural key is a value that already identifies the thing in the real world — an email, an ISBN, a country code. A surrogate key is a value the database invents just to be an id, like an auto-incrementing number, that means nothing outside the table.

UUIDs vs Integer IDs
bigint sequence, random UUIDv4, or time-ordered UUIDv7/ULID?
Counting up vs picking at random

An integer id counts up: 1, 2, 3. A UUID is a 128-bit value that looks random, so two machines can each mint ids without asking a central counter and (almost) never collide. UUIDs are bigger and unordered; integers are small and ordered.

Composite Keys
When is a multi-column primary key the right call?
A key made of two columns

Sometimes no single column identifies a row, but a pair does. A junction table linking students to courses is uniquely identified by (student_id, course_id) — that pair is the primary key.

What the Primary Key Decides
How far does the PK choice ripple beyond uniqueness?
More than just "no duplicates"

The primary key guarantees each row is unique and gives every other table a handle to reference. But it also quietly decides how rows are stored and how fast joins and lookups run.