Database

On this page 7

A database is an organized, persistent collection of related data stored so that it can be queried, updated and protected efficiently, usually under the control of a database management system (DBMS). In the field of databases, the term refers to the data itself together with its structure, the schema, while the DBMS is the software that stores, retrieves and safeguards it; in everyday speech the two are often blurred.

What separates a database from a folder of files or a spreadsheet is a set of guarantees: declared structure, concurrent multi-user access, integrity rules, transactions and recovery after failure. These database fundamentals explain why almost every serious application, from a bank ledger to a mobile app’s offline cache, keeps its state in a database rather than in ad hoc files.

What a database provides beyond plain files

A database provides data independence: applications describe what data they need, and the DBMS decides how to store and retrieve it. This separation lets administrators add indexes, move storage or reorganize files without rewriting application code, which is impossible when programs parse their own file formats.

The table compares a database with the file-based storage it replaced.

CapabilityPlain files or spreadsheetsDatabase
StructureImplicit, defined by each programDeclared in a schema and enforced
Concurrent accessRisk of overwrites and corruptionControlled by locking or multiversioning
IntegrityChecked manually, if at allConstraints such as keys, types and checks
QueryingCustom code for each questionDeclarative query language such as SQL
RecoveryRestore from the last copyWrite-ahead log, backups and point-in-time restore
SecurityFile system permissionsUsers, roles and privileges per object
Database compared with file-based storage

These capabilities rest on the ACID properties of transactions in most relational and many non-relational systems: atomicity (all or nothing), consistency (rules hold before and after), isolation (concurrent transactions do not see each other’s partial work) and durability (committed data survives crashes).

How a database stores and retrieves data

Internally, a database organizes data into fixed-size pages, commonly 4 KB to 16 KB, which are the unit of transfer between disk and memory. A buffer pool caches frequently used pages in RAM, because reading memory is orders of magnitude faster than reading even a fast SSD.

Before a change is applied to the data pages, it is recorded in a write-ahead log. If the server crashes, the DBMS replays the log on restart so that committed transactions are kept and incomplete ones are rolled back, which is how durability is achieved without writing every page synchronously.

Fast retrieval depends on indexes, most often B-tree structures that locate a row among millions in a handful of page reads. A query optimizer chooses between scanning a table and using an index by estimating costs from statistics about the data, so the same query text can run very differently as data grows.

Main types of databases

Databases are classified mainly by their data model, the way they represent data and relationships. The relational database, which stores data in tables of rows and columns linked by primary and foreign keys, has been dominant since the 1980s, but several other models serve workloads where tables fit poorly.

The following table summarizes the principal types with typical uses.

TypeData modelTypical useExample systems
RelationalTables with rows, columns and keysTransactions, business recordsPostgreSQL, MySQL, Oracle Database, SQL Server
DocumentJSON-like documentsFlexible product catalogs, contentMongoDB, Couchbase
Key-valueUnique key mapped to a valueCaching, sessions, countersRedis, Amazon DynamoDB
Wide-columnRows with dynamic column familiesVery large write-heavy datasetsApache Cassandra, HBase
GraphNodes and edges with propertiesNetworks, recommendations, fraud detectionNeo4j
Time-seriesTimestamped measurementsMetrics, sensors, monitoringTimescaleDB, InfluxDB
VectorHigh-dimensional numeric vectorsSimilarity search for machine learningMilvus, pgvector extension
Database types by data model

Databases are also divided by workload into OLTP systems, optimized for many short read and write transactions, and OLAP systems or data warehouses, optimized for scanning and aggregating large volumes, often with columnar storage. Many organizations run both, copying data from operational databases into an analytical one.

Choosing a database for an application

The choice of a database should follow the shape of the data and the access patterns, not popularity. A relational database is the safe default for most business applications because it combines strong integrity guarantees with a mature query language, and specialized systems earn their place when a clear requirement exceeds what it does well.

The decision table maps common requirements to a suitable choice.

RequirementRecommended choiceReason
Money, orders or inventoryRelational databaseTransactions and constraints protect correctness
Embedded storage inside one applicationSQLite or similar embedded engineNo server; a single file with full SQL
Sub-millisecond cache in front of another storeKey-value storeData held in memory with simple access
Records with highly variable fieldsDocument database or JSON columnsSchema can evolve per record
Queries across many relationship hopsGraph databaseTraversals avoid repeated joins
Reports over billions of rowsColumnar analytical databaseReads only the needed columns, compresses well
Choosing a database by requirement

Operational factors matter as much as features: backup and restore procedures, replication, monitoring, team expertise and licensing. A database that the team cannot restore under pressure is a liability regardless of its benchmark results.

Common misconceptions and risks

Many database problems come from treating the database as a passive storage bucket rather than as a system with its own rules and limits. The following points correct frequent misunderstandings.

  • A backup is not proven until it is restored: untested backups regularly turn out to be incomplete or unusable.
  • Replication is not a backup: an accidental deletion is replicated to every copy within seconds.
  • Schemaless does not mean no schema: document databases move the schema into application code, where it is harder to enforce.
  • Missing indexes are the most common performance problem, while too many indexes slow down every write.
  • Default isolation levels are rarely serializable, so concurrent transactions can still produce anomalies the developer did not expect.

Security deserves the same attention: SQL injection, excessive privileges and unencrypted backups remain leading causes of data breaches. Parameterized queries, least-privilege accounts and encrypted storage address most of these risks.

In plain words

A database is like a very well-organized library with a strict librarian. Every book has a fixed place. A catalog tells you exactly where to find it. The librarian also makes sure that two people never write in the same book at the same moment.

Suppose the lights go out in the middle of a change. The librarian remembers what was finished and what was not, so nothing ends up half done. That is the real value of a database. Many people and programs can use the same information at once. They find it quickly, and they can trust that it is correct and will not vanish.

A real-world example

A regional chain of 40 pharmacies tracked stock in spreadsheets emailed to headquarters every evening by each branch. Orders were based on day-old numbers, copies conflicted, and a damaged file once erased a week of records for one branch.

The chain moved to a central relational database with tables for products, branches, stock levels and sales, linked by primary and foreign keys. Each sale at a till runs as a single transaction that records the sale and decreases stock, so both happen together or neither does. A constraint prevents stock from becoming negative, and nightly backups with continuous log archiving allow restoring to any minute of the last 14 days.

Headquarters now sees stock levels across all 40 branches in real time, automatic reorders trigger when an item drops below a threshold, and the weekly reconciliation that once took a full day of manual work has disappeared.