Module 03: Data And State
Understand what systems remember, how they remember it, and how bad state causes real incidents.
The Mental Model
Section titled “The Mental Model”State is memory. Data is not just values. Data has owner, shape, meaning, lifetime, permissions, and consequences.
event happens -> validate -> store state -> read state -> make decisionAnalogy
Section titled “Analogy”A database is like a bank ledger. You do not scribble random notes in it. You define what a valid entry looks like, who can write it, when it can change, and how to audit history.
Types Of State
Section titled “Types Of State”| State | Example | Storage |
|---|---|---|
| Durable | ticket, user, payment | database |
| Temporary | session, cache entry | cache |
| Derived | dashboard count | query or analytics table |
| External | payment status | third-party system |
| Local UI | open modal, typed text | browser memory |
| Audit | who approved what | append-only log/table |
Core Data Ideas
Section titled “Core Data Ideas”- Schema: allowed structure.
- Constraint: rule the database enforces.
- Index: speed helper for reads.
- Transaction: group of changes that succeed or fail together.
- Migration: controlled schema change.
- Backup: recovery copy.
- Restore: proof that backup works.
Visual: State Ownership
Section titled “Visual: State Ownership”Browser state: form draft, loading, selected tabAPI state: request context, auth userDatabase state: tickets, comments, users, audit eventsCache state: recent dashboard countsExternal state: payment or model job statusDesign Drill
Section titled “Design Drill”Design a support-ticket database:
- Users.
- Tickets.
- Comments.
- Attachments.
- Status history.
- Audit events.
Decide:
- What can be updated?
- What should be append-only?
- What must be unique?
- What must never be null?
- What should happen on delete?
Failure Cases
Section titled “Failure Cases”- Ticket points to a deleted user.
- Comment exists without a ticket.
- Status has an invalid value.
- Migration deploys before code is compatible.
- Dashboard reads stale derived data.
- Backup exists but restore has never been tested.
Agentic Angle
Section titled “Agentic Angle”Ask an agent:
Review this support-ticket schema for missing constraints, weak auditability,bad delete behavior, privacy risks, and queries that may need indexes.Questions
Section titled “Questions”- What is the source of truth for ticket status?
- Should status history be editable?
- Which table stores files versus file metadata?
- What data is personally identifiable?
- What query must be fast for support agents?
- What is the rollback plan for a failed migration?
- Create
portfolio/03-data-and-state/schema.md. - Write tables and fields.
- Add constraints.
- Write five common queries.
- Add index choices and explain why.
- Write one migration.
- Write a rollback plan.
- Write a restore drill: how would you prove backups work?
Done When
Section titled “Done When”- You can trace one ticket through its full lifecycle.
- You can explain what data is mutable versus append-only.
- You can identify sensitive data.
- You can explain migration risk.