3. Data & Persistence
Database Modeling for Real Systems
Model relational data around invariants, ownership and access patterns rather than UI screens.
Lesson overview
A production schema encodes business invariants with keys, foreign keys, unique constraints, nullability and deliberate indexes. Design around access patterns while remembering that every index has write and storage cost.
Learning path
Theory → Example → Code → Practice → Quiz → Challenge → Completion
Step 1
Theory
A production schema encodes business invariants with keys, foreign keys, unique constraints, nullability and deliberate indexes. Design around access patterns while remembering that every index has write and storage cost.
Step 2
Example
A payment reference should be unique even if application code accidentally processes the same request twice. The database becomes a second line of defense.
Step 3
Code
sql
create table orders (
id uuid primary key,
customer_id uuid not null references customers(id),
payment_id text unique,
status text not null,
created_at timestamptz not null default now()
);
Step 4
Practice
Review your current application and apply Database Modeling for Real Systems. Document the current behavior, one production risk, the change you would make, and how you would verify it.
Step 5
Quiz
1. What is the central production concern in "Database Modeling for Real Systems"?
Step 6
Challenge
Design a production-ready implementation for Database Modeling for Real Systems. Include failure handling, security considerations, observability, testing and a rollback or recovery path where applicable.
Complete every stage
Work through every step in order, then the lesson will be marked complete.
Each chapter and subtopic has its own public URL under /full-stack-to-production.