Database
A system for storing, querying, and managing structured data. Every app needs one. Relational databases (PostgreSQL, MySQL) use tables and SQL. NoSQL databases (MongoDB, DynamoDB) use documents or key-value. The foundation of any backend.
- Any app that stores data persistently.
- When you need queries, relationships, or transactions.
- Ephemeral data (use memory/cache).
- Blob storage (use object storage).
Definition
A database stores data persistently and lets you query, insert, update, and delete it. Relational (SQL) databases enforce schemas and relationships. NoSQL databases are more flexible (document, key-value, graph, column). ACID properties guarantee transaction safety.
Why it exists
To store data persistently, query it efficiently, handle concurrent access, and ensure consistency — things you can't do reliably with files.
How it works
You define a schema (tables/collections), insert data, and query it (SQL or API). The database manages storage, indexing, concurrency, and transactions. Indexes speed up queries. A connection pool manages client connections. Backups and replication ensure durability.
Scaling limits
Single-server databases hit CPU/memory/disk limits. Vertical scaling (bigger machine) is easy but finite. Horizontal scaling (sharding, replication) is complex. Connection limits. Query performance on large tables.
Cost shape
Self-hosted (free, you manage) or managed (RDS, PlanetScale — pay per usage/storage/IO).
Alternatives
- Files — Simple but no queries, concurrency, or consistency.
- In-memory cache — Fast but volatile — data lost on restart.
Failure modes
- Data loss from no backups.
- Slow queries from missing indexes.
- Lock contention.
- Schema drift.