A table with rules

Think of it when state must be shared by many people, searched, or kept safe through a crash.

In everyday life

A file is like one whiteboard: whoever wipes it and rewrites it last wins. A database is like a bank teller who updates one account at a time and refuses a slip with no signature.

One case

A clinic keeps its appointments in one shared spreadsheet. At 09:02 two receptionists save it within seconds of each other, and the second save wipes out the 3 bookings the first one just added. The next morning, 3 patients arrive for appointments the clinic has no record of.

A table with rules
The ideaHow data is stored
A table with rules

A program that keeps state on disk in tables, answers questions about it fast, and refuses data that breaks its rules.

How data is stored, Foundations

Every case

A file is saved whole, so the last save replaces everything. A database stores each record as its own rowOne record in a database table, such as one order. Columns are its fields. and changes only the rows a write touches, so two people who edit different appointments do not erase each other. For two writes to the same row, it offers transactions, locks and one-step updates; used well, they stop one change from silently erasing the other. It also checks every write against rules: this fieldOne named value inside a record, such as the total of an order. is a time, this id is unique, this booking points to a real patient.

The word

Engineers call this

databaseA program that keeps state on disk in tables, answers questions about it fast, and refuses data that breaks its rules.

Put shared, important state in a database, and let the database enforce every rule you can state.

Where this idea leads

Skills that encode it

  • principle-foundational-thinking pstackTraces every access pattern first, and asks “what happens if another actor modifies this concurrently?”