# Database

> An organized store of data that programs can search and update safely.

- Level: Basic
- Topics: Software, Data
- URL: https://tidbit.legios.com.ar/database/
- In Spanish: [Base de datos](https://tidbit.legios.com.ar/es/database/)

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.

## An analogy

A library with a catalog. Books (data) sit on numbered shelves (tables), the catalog (index) tells you where to look without walking every aisle, and the librarian (the database engine) makes sure two people do not rewrite the same card at the same time.

## 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.

## Go deeper

- [What is a database? (AWS)](https://aws.amazon.com/what-is/database/)
- [Database (Wikipedia)](https://en.wikipedia.org/wiki/Database)

## Related terms

- [Spreadsheet vs database](https://tidbit.legios.com.ar/spreadsheet-vs-database/): Why a company that runs on Excel eventually needs a real database.
- [SQL](https://tidbit.legios.com.ar/sql/): The language you use to ask a database questions.
- [Open source](https://tidbit.legios.com.ar/open-source/): Software whose code anyone can read, use, change and share.
- [Amazon RDS](https://tidbit.legios.com.ar/amazon-rds/): A ready-made relational database that AWS keeps patched, backed up and running.
- [Cloud computing](https://tidbit.legios.com.ar/cloud-computing/): Renting computers over the internet instead of buying your own.
- [NoSQL](https://tidbit.legios.com.ar/nosql/): Databases that store data in shapes other than tables with fixed columns.
- [Amazon DynamoDB](https://tidbit.legios.com.ar/amazon-dynamodb/): A key-value database that answers in milliseconds no matter how big the table gets.
- [Backup](https://tidbit.legios.com.ar/backup/): A separate copy of your data, kept so you can get it back when the original is lost.
