Kayavak / Databases / DB·00 Start Here: What a Database Is / Deeper
Deeper · Databases
Start Here: What a Database Is
The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.
Why does this exist?
Before databases, every program kept its own files in its own format, and two programs that needed the same customers kept two copies that drifted apart. The first database systems (IBM's IMS, developed in the late 1960s partly for the Apollo programme's parts lists, and the CODASYL network model) put shared data in one place, but programs still navigated it record by record along fixed paths, so changing how data was stored broke the programs that read it.
In 1970 Edgar Codd at IBM proposed the relational model: describe data as tables and ask for what you want, and let the system work out how to fetch it. IBM's System R and Berkeley's Ingres proved it could be fast in the 1970s; Oracle shipped the first commercial SQL database in 1979; SQL became a standard in 1986. Fifty years later, the relational database is still the default place for an organisation's most important data.
The mental model
Try it yourself first: write your own model in the Mental Model Explorer, then compare.
A database is a shared, durable, consistent store that many programs and people use at once. You describe the data and the rules; it keeps them true through concurrent changes and crashes.
| Question | Answer |
|---|---|
| What is it? | A system that stores data durably and answers queries, enforcing rules and coordinating concurrent changes |
| Problem it solves | One trustworthy copy of shared data, safe under concurrency and failure |
| Parts | Tables (or other models), keys and constraints, a query language, an optimiser, indexes, transactions, a log for recovery |
| How it works | Queries are planned and executed against storage; changes happen in transactions recorded in a log before data pages |
| Assumptions | Applications let the database enforce constraints and use transactions properly |
| When they change | Rules enforced only in application code drift and get bypassed by the next script or service |
| Where it fails | Data too large or too write-heavy for one machine, which leads to replication and sharding (ch61) |
| Related ideas | Data structures (Foundations, ch03); filesystems and fsync (Foundations, ch08); persistence layers (The Backend, ch49) |
What if?
What if programs still navigated data by stored paths?
Reason it through, then open
Adding an index or reorganising storage for speed would break every program that followed the old paths, so physical design would freeze. Codd's data independence (programs say what, not how) is what lets a database add an index tomorrow and make yesterday's queries faster without changing them.
What if constraints lived only in the application?
Reason it through, then open
The first time someone ran a one-off script, a second service wrote to the same table, or two requests raced, invalid data would get in: orders for customers who don't exist, duplicate emails. A foreign key or unique constraint is checked by the database for every writer, every time, including concurrent ones.
Where the boundary is
| Aspect | A database | Files |
|---|---|---|
| Concurrent writers | Coordinated by transactions | Your problem |
| Crash in the middle of a change | Recovered from the log | Possibly a half-written file |
| Asking a new question | A new query | New code to read and filter |
| Shared rules | Constraints enforced for everyone | Conventions |
How sure are we?
| Claim | How it's known | Where from |
|---|---|---|
| Codd proposed the relational model in 1970 | Historical | A Relational Model of Data for Large Shared Data Banks |
| Oracle shipped the first commercial SQL database in 1979 | Historical | Company history |
| Database-enforced constraints are more reliable than application checks | Model | Follows from every writer passing through them |
Still open
Whether new workloads (AI applications, vectors, event streams) belong in relational databases with extensions or in specialised stores is argued case by case; so far, relational systems keep absorbing new capabilities.
What would change your mind? If the application were the only writer forever, with no concurrency, checks in code would be enough. That's rarely true for long.
Recall
What did the relational model's data independence make possible?
Changing storage and indexes without changing the programs that query the data.
Why enforce constraints in the database rather than only in code?
The database checks every writer, including scripts, other services and concurrent requests.
What came before relational databases?
Hierarchical and network databases (IMS, CODASYL) navigated along stored paths.
Reflect
Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.