8.1 · The nine database families
8.2 · OLTP relational — Postgres is the default
- Postgres: extensions for JSON, full-text search, geospatial (PostGIS), time-series (Timescale), vector (pgvector), graph (AGE). One database, many superpowers.
- MySQL / MariaDB: simpler ops; PlanetScale-style serverless ecosystems.
- Aurora / Cloud SQL / Neon: managed Postgres or MySQL with replicas, branching, scale-to-zero.
- SQLite: surprisingly fine for small apps; Litestream + Fly = edge SQLite.
- NewSQL: Spanner, CockroachDB, YugabyteDB — distributed SQL with strong consistency.
8.3 · KV, document, wide-column
| Family | Examples | Sweet spot |
|---|---|---|
| KV / cache | Redis, Valkey, Dragonfly, KeyDB, Cloudflare KV | Sessions, hot lookups, rate limits, queues. |
| Document | MongoDB, CouchDB, Firestore | Flexible schemas; one-doc reads at scale. |
| Wide-column | Cassandra, ScyllaDB, BigTable, DynamoDB | Massive write throughput; predictable single-row reads. |
8.4 · OLAP / analytics
- ClickHouse — columnar, ridiculously fast aggregations on billions of rows.
- DuckDB — embedded OLAP; perfect for analysis inside services or notebooks.
- Snowflake / BigQuery / Databricks — managed warehouses for org-wide analytics.
- Apache Iceberg / Delta Lake / Hudi — open table formats over S3/parquet (the modern data-lake stack).
8.5 · Search
- OpenSearch / Elasticsearch — full-featured but heavy.
- Typesense / Meilisearch — typo-tolerant, very fast, dev-friendly.
- Postgres full-text — surprisingly good for < 10M docs.
8.6 · Vector
- pgvector — first choice if you already use Postgres.
- Qdrant / Weaviate / Milvus — purpose-built; richer filters, scale.
- Pinecone — managed, hands-off.
- Index types: Flat (exact), IVF, HNSW (default), PQ (compressed). See AI Codex Ch 9.
8.7 · Time-series
TimescaleDB, InfluxDB, VictoriaMetrics, QuestDB. Continuous aggregates, downsampling, retention policies. For metrics specifically — Prometheus (with Mimir/Cortex for long-term).
8.8 · Graph
Neo4j, Memgraph, Apache AGE (Postgres extension), Amazon Neptune. Use when traversal is the core query pattern (recommendations, fraud rings, knowledge graphs).
8.9 · Object & files
S3 / R2 / GCS / Azure Blob / MinIO. Always plan for: lifecycle rules, presigned URLs, KMS encryption, replication. R2 = zero egress.
8.10 · ACID, MVCC, isolation levels
| Level | Prevents | Examples that allow |
|---|---|---|
| Read Uncommitted | — | Dirty reads possible |
| Read Committed | Dirty reads | Non-repeatable reads, phantoms |
| Repeatable Read | + Non-repeatable reads | Phantoms (in classic; Postgres MVCC blocks these too) |
| Serializable | All anomalies | — |
| Snapshot Isolation (Postgres "Repeatable Read") | Dirty + non-repeatable + phantoms via MVCC | Write skew (use SERIALIZABLE) |
MVCC = each transaction sees a consistent snapshot. Postgres uses tuple versions + vacuum. Long transactions = table bloat — kill them.
8.11 · Schema & migrations
- Migrations are code. Version them. Review them.
- Make every migration online + reversible: add nullable column → backfill → make NOT NULL.
- Never rename a column in one deploy. Add new → write to both → backfill → switch reads → drop old.
- Use
CREATE INDEX CONCURRENTLYin Postgres. Watch out for lock-waits. - Tools:
sqlx,flyway,liquibase,atlas,prisma migrate,alembic,goose.
8.12 · Multi-tenant patterns
| Pattern | Isolation | Cost |
|---|---|---|
| Shared schema, tenant_id column | Logical | Cheap; risk of cross-tenant leak — enforce with RLS. |
| Schema per tenant | Stronger | Migration cost grows linearly. |
| DB per tenant | Strongest | Operationally heavy; "noisy neighbour" gone. |
| Hybrid (DB per shard of tenants) | Configurable | The pragmatic large-scale choice. |