Lesson 1 of 32 beginner 6 min read

What a database is (and why not just files)

Key takeaways A database is software built to store data so it can be queried, shared by many readers and writers at once, and trusted to survive a crash. The engine that does this is a DBMS (like Postgres or SQLite). You could hand-roll files instead — but you’d end up rebuilding concurrency, fast lookups, integrity, and durability yourself, badly. This module builds from here; the sibling path covers the same ground from a different angle in databases & persistence.

Almost every program eventually needs to remember something — a user, a setting, a log of decoded calls. The naive answer is “write it to a file.” That works right up until a second user shows up, or the data grows past what you can scan, or the power cuts out mid-write. A database is the accumulated answer to all the ways that plain files let you down, packaged so you can lean on it instead of rebuilding it.

The file approach, and where it breaks

Say you’re storing a list of radio systems your scanner has seen. You could keep them in a text file, one per line, and append a new line each time. For a quick script on your own laptop, that’s genuinely fine — don’t over-engineer a toy.

The cracks appear as soon as the program grows up:

  • Finding one record is slow. To pull “the system on 851.0125 MHz” you read the whole file and check every line. At a thousand rows that’s instant; at ten million it’s a real wait, every time.
  • Two writers collide. If two parts of your program (or two users) append at the same moment, their writes interleave and you get a garbled line — or one overwrites the other. Files have no idea the two are happening at once.
  • A crash corrupts everything. If the machine dies halfway through rewriting the file, you can be left with a truncated, unreadable mess — and no clean version to fall back to.
  • There are no rules. Nothing stops you writing a system with no name, or the same one twice, or a frequency that’s actually the word “banana.” The file stores whatever bytes you hand it.

Each of these is solvable. Solving all of them, correctly, is a large amount of careful engineering — and it has already been done, many times over, inside a database.

What a database gives you instead

A database is purpose-built software that stores data and answers questions about it. The engine itself is called a database management system, or DBMS — Postgres, MySQL, SQLite, and others. In everyday speech “database” means both the software and the data it holds; the DBMS is the part doing the work. What you get for handing your data to one:

  • Querying. You ask for the data you want — “every call on talkgroup 101 yesterday, newest first” — and the database figures out how to fetch it. That language is SQL, and it’s most of this module.
  • Fast lookups. With an index, the database jumps straight to matching rows instead of scanning everything — the difference between a millisecond and a minute.
  • Concurrency. Many readers and writers can work at once without stepping on each other, coordinated by the DBMS so nobody sees a half-written mess.
  • Integrity. You can declare rules — this column can’t be empty, this value must be unique, this row must point at a real one in another table — and the database refuses to store data that breaks them.
  • Durability. Once the database confirms a write, it’s on disk to stay, even if the power dies a millisecond later. Getting this right underlies transactions and the guarantees behind them.

Structured storage, not a magic box

A database isn’t magic — it’s structured. Most databases you’ll meet are relational: they organise data into tables of rows and columns, a shape we unpack in the relational model. You decide the schema — what columns exist and what type each holds — up front, and the database enforces it. That structure is why it can query, index, and validate so well: it knows exactly what your data looks like.

Here’s the whole idea in miniature. Instead of appended text lines, a system table might look like this, and you’d ask for one row by name rather than reading the file:

SELECT frequency_hz
FROM systems
WHERE name = 'Metro P25';

The database reads only the matching row, using an index, no matter how many million rows sit alongside it. You described what you wanted; it worked out how.

When a plain file really is fine

The honest counterpoint: databases aren’t always the answer. A config file a program reads once at startup, a handful of settings, a scratch log you’ll delete tomorrow — reach for a file and move on. The moment you need to query that data, share it between writers, or trust it to survive a crash, that’s the signal to put it in a database. Most of software development is knowing which situation you’re in.

Quick check: what's the main reason to use a database instead of a plain file?

Recap

  • A database is software built to store data so it can be queried, shared, and trusted — the engine is a DBMS like Postgres or SQLite.
  • Plain files break down on fast lookups, concurrent writers, crash safety, and enforcing rules — a database solves all four.
  • Databases give you querying (via SQL), indexes for speed, concurrency, integrity rules, and durability.
  • Most databases are relational: data lives in tables with a defined schema, which is what makes querying and validation possible.
  • A plain file is still fine for tiny, single-user, throwaway data — reach for a database when you need to query, share, or protect the data.

Next up: Data, state & persistence.

Frequently asked questions

Can't I just save my data to a file?

For a tiny, single-user program, yes — a file is fine. The trouble starts when more than one thing reads or writes at once, when you need to find one record among millions without scanning the whole file, or when a crash mid-write must not corrupt everything. A database exists to handle exactly those situations so you don’t have to reinvent them.

What does DBMS mean?

A database management system is the actual software — Postgres, SQLite, MySQL — that stores the data and answers queries. People usually say “database” for both the software and the data it holds; the DBMS is the engine doing the work.

Is a spreadsheet a database?

Not really. A spreadsheet holds rows and columns, but it has no query language, weak types, no real concurrency, and no guarantees against corruption. It’s great for a human eyeballing numbers; a database is built for programs storing and querying data at scale.