What You'll Master Here
Model the write workflow first, enforce invariant facts in the database, and make one business action commit atomically.
OLTP modeling designs the database behind operational workflows: create an order, reserve inventory, update status, issue a refund, and find the current answer quickly.
Step through the five defenses below. One checkout write has to survive all of them, and each one is a topic in this chapter. Chapter 5 gave you a normalized commerce model; this chapter asks whether concurrent applications can write to it safely.
primary key (order_id, line_no)Model the write workflow first, enforce invariant facts in the database, and make one business action commit atomically.
Operational data is the source of truth. A weak schema makes every API and service reimplement integrity rules inconsistently.
- OLTP
- Online transaction processing: many small, concurrent writes and current-state reads.
- constraint
- A database-enforced rule such as primary key, foreign key, unique, not null, or check.
- transaction
- A set of changes that commits together or rolls back together.
- access path
- The common lookup/filter pattern an index is designed to serve.
Designing tables from a dashboard instead of from operational writes. The source system cannot enforce correct state transitions or identities.
Write business events before DDL.
Map each invariant to enforcement.
Make transaction boundaries explicit.
I start from the write workflow, state the grain and identity of each table, enforce invariants with constraints, and wrap one business action in a transaction.
OLTP schemas are contracts for safe concurrent writes.
