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

user actionyour appthe database
every user action is written somewhere it survives restarts

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 users

schema

The blueprint of your tables, columns, and types. Checked before any write is accepted.

email is text and unique

ACID

The promise that a group of writes is all-or-nothing and survives a crash.

transfer: debit and credit, or neither

how it works

  1. 1
    Open 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.

  2. 2
    Send the SQL text

    The statement travels as plain text: INSERT, SELECT, whatever the moment needs.

  3. 3
    The database plans it

    It parses the SQL, checks it against the schema, and picks the cheapest path: which indexes, in which order.

  4. 4
    Write, then confirm

    Changes hit the write-ahead log before the table, so a committed write survives a crash a millisecond later.

  5. 5
    Rows 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

1-- this array dies with the process
2const todos = []
3
4-- this survives restarts, crashes, deploys
5INSERT INTO todos (task, done)
a real write: straight to disk
6VALUES ('learn indexes', false);
7SELECT * FROM todos WHERE done = false;
any question, in any shape you like

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
VS

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
relationaldocumentkey-valuevector
the four families — most apps start with the first
🪤 gotcha

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

🎤 interview

Why not just save to files?watch ↗

🎤 interview

When do you actually need a database?watch ↗

📚 tutorial

The database familieswatch ↗

🧠 trivia

The most deployed database on earthwatch ↗