Skip to main content

Databases

What is a Database?

Definition

A database is an organised collection of data managed by software that handles storing, querying, concurrent access and durability on the application's behalf.

Also known as: DB, DBMS

Database in more detail

Strictly, the database is the data and the database management system is the software around it, though everyday usage merges the two. What that software gives you is hard to reproduce by hand: durable writes that survive a power cut, many clients reading and writing at once without corrupting each other, indexes that find one row among billions, constraints that reject impossible data, and a query language that describes what you want rather than how to fetch it.

The families differ in the shape they impose. Relational databases such as PostgreSQL, MySQL and SQLite store rows in typed tables with relationships and are queried with SQL; they are the sensible default for most applications. Document stores such as MongoDB keep semi-structured records. Key-value stores such as Redis and DynamoDB trade query flexibility for speed and scale. Wide-column, graph, time-series, search and vector databases each optimise for one access pattern that the others handle awkwardly.

The guarantees matter as much as the model. ACID — atomicity, consistency, isolation, durability — means a transaction either fully happens or does not, and committed data stays committed. Isolation levels decide which concurrency anomalies you can still observe, and defaults vary between engines, which is a common source of surprise. Distributed databases add the CAP trade-off: when the network partitions, a system must choose between refusing requests and serving possibly stale data.

Database example

-- Relational: typed columns, constraints, relationships
CREATE TABLE users (
  id         BIGSERIAL PRIMARY KEY,
  email      TEXT NOT NULL UNIQUE,
  created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

CREATE TABLE orders (
  id      BIGSERIAL PRIMARY KEY,
  user_id BIGINT NOT NULL REFERENCES users(id),
  total   NUMERIC(10,2) NOT NULL CHECK (total >= 0)
);

-- A transaction is all-or-nothing
BEGIN;
  UPDATE accounts SET balance = balance - 100 WHERE id = 1;
  UPDATE accounts SET balance = balance + 100 WHERE id = 2;
COMMIT;   -- a crash before this leaves both rows untouched

-- Document store, same idea without a fixed schema
{ "_id": "8842", "user": { "email": "a@b.com" }, "total": 49.00 }

Database — common questions

What is the difference between a database and a DBMS?
The database is the stored data; the database management system is the software that stores, protects and queries it — PostgreSQL, MySQL, MongoDB. In casual use 'database' means both, which is harmless until documentation depends on the distinction.
What does ACID mean?
Atomicity: a transaction completes fully or not at all. Consistency: constraints hold before and after. Isolation: concurrent transactions do not observe each other's partial work. Durability: once committed, data survives a crash.
Which database should I choose?
Start with a relational one such as PostgreSQL unless you have a specific reason not to. It handles structured data, flexible JSON documents, full-text search and strong transactions well, which covers the overwhelming majority of applications.

Keep reading

Every definition in the set is indexed A-Z in the developer glossary, and the cheat sheets cover the syntax once you know what you are looking for.

Browse the A-Z glossary