Why not just a file?
Four problems that appear the second a second user shows up.
Storing data in a file works perfectly until the moment two things touch it at once. Everything a database gives you is a solution to a problem that only exists when there is more than one of something: more than one user, more than one server, more than one write in flight.
- Concurrency
Two writes at the same instant do not corrupt each other. - Durability
A confirmed write survives the power going out. - Query speed
Find one row among ten million without reading ten million. - Integrity
Rules the data cannot violate, no matter which code path is buggy.
The fourth item, integrity, is the one people skip and later regret. A rule like "an order must belong to a customer that exists" enforced by the database is true forever. The same rule enforced only in your code is true until someone writes a second code path, or an admin script, or an AI-generated migration.
What to remember
- Databases solve problems caused by simultaneity, not by size.
- Rules enforced by the database survive your future bugs.
- Multi-step changes need transactions or they can half-happen.
Terms in this lesson
Field notes
Loaded from a deliberately slow source. The lesson above was already readable while this was still travelling. That is streaming, and it is the same trick a chat interface uses.
Fine at 500 rows, dead at 500,000
A list page loaded posts, then fetched each author separately. Development had eleven posts. The launch had four thousand, and every visitor issued four thousand queries. The database saturated eight minutes after the announcement.
The N+1 problem, at scale
The rename that took the site down
A column was renamed in a single migration during a deploy. For forty seconds the old code was still running and querying a column that no longer existed. Expand-then-contract exists precisely for those forty seconds.
Postmortem, e-commerce team
resolved in 901ms · region iad1
Hide field notes toggles a search param the loader reads. With it off, the slow promise is never created, so nothing streams.