Database
An organized store of data that programs can search and update safely.
A database is a program whose whole job is to store data and answer questions about it quickly and safely: every user of an app, every order, every message. Unlike a spreadsheet, it is built to be used by many programs at once, to hold millions of rows, and to never lose or half-save a change, even if the power goes out in the middle of a write.
The most common kind is relational: data lives in tables with rows and columns (a customers table, an orders table), tables point to each other by ids, and you ask questions in SQL. PostgreSQL, MySQL and SQLite are relational and open source; Amazon RDS runs them for you in the cloud. NoSQL databases drop the strict tables for flexible documents (MongoDB), key-value pairs (Redis, Amazon DynamoDB) or graphs, trading some guarantees for speed or scale.
Almost every app you use is a thin layer over a database. Open Instagram and a query fetches your feed; pay someone and a transaction moves money between two accounts as a single all-or-nothing step. Backups, indexes (so a row can be found without scanning the whole table) and permissions are the daily work of keeping one healthy.
Keep in mind
- Relational databases store tables and speak SQL; NoSQL ones store documents, key-value pairs or graphs.
- A transaction is a group of changes that either all happen or none do.
- An index makes searches fast at the cost of some space and slightly slower writes.
- The database is usually the hardest part of a system to scale and the most important to back up.