What is a Database?
Variables die on refresh. Databases don’t.
▶ the lesson · narrated sketch video · tap for sound
the intro
A database is where your application remembers things: users, orders, posts. Data lives on disk, survives restarts, and can be queried in any shape you need. Learning one database well — and SQL with it — transfers to almost every app you will build.
fun fact ✦
SQLite — the most deployed database on earth — is in every phone, probably including the one in your pocket.
the docs
the deep dive
the ideas behind the video — concepts, diagrams, a walkthrough and the traps to avoid
Your app is born an amnesiac: every variable evaporates on restart, and a fresh deploy starts knowing nothing. A database is a separate program whose entire job is remembering — durably on disk, correctly under a thousand concurrent users, and answerable in any shape you ask. Learn one well and every later database is a variation on the same ideas.
your app forgets; the database remembers
key terms
table
A grid of rows and columns: one row per thing, one column per property.
users(id, email, created_at)query
A question written in SQL. The database parses it, plans it, and executes it.
SELECT * FROM usersschema
The blueprint of your tables, columns, and types. Checked before any write is accepted.
email is text and uniqueACID
The promise that a group of writes is all-or-nothing and survives a crash.
transfer: debit and credit, or neitherhow it works
- 1Open a connection
Your app logs into the database over the network. Real apps keep a small pool of connections and reuse them, because opening one per request is slow.
- 2Send the SQL text
The statement travels as plain text: INSERT, SELECT, whatever the moment needs.
- 3The database plans it
It parses the SQL, checks it against the schema, and picks the cheapest path: which indexes, in which order.
- 4Write, then confirm
Changes hit the write-ahead log before the table, so a committed write survives a crash a millisecond later.
- 5Rows come back
Results return as structured rows your code can loop over. Round trip done.
the code, explained
the same todo list, two levels of permanence
side by side
a database
- survives crashes and restarts
- queries any shape in milliseconds
- safe with 10,000 writers at once
- enforces types and rules itself
variables and files
- gone on refresh, gone on deploy
- grep is your only query tool
- corrupts with two writers
- no types, no rules, no regrets proof
Two requests read the same value, both add 1, both write 2 — a like silently vanishes. This lost-update race is exactly why databases have transactions and row locking. Any read-modify-write belongs inside a transaction, not spread across your app code.
quick answers
Do I need a database for a side project?
If the data must survive restarts or be shared between users, yes. SQLite counts: one file, zero setup, real SQL.
Which database should I learn first?
PostgreSQL. Relational, free, and its SQL transfers to MySQL, SQLite, and most analytics tools.
SQL or NoSQL?
SQL first. Most apps hold relational data. NoSQL wins at specific scale or shape problems, and you will recognize those when you hit them.
quick hits about What is a Database?
short answers · interviews, tips, trivia & hidden gems