9.1 · Ten families at a glance
| Family | Examples | Pick when |
|---|---|---|
| OLTP relational | Postgres, MySQL, Aurora, Neon, PlanetScale | Default for transactional apps. |
| KV / cache | Redis, Valkey, Dragonfly, KeyDB | 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 row reads. |
| OLAP / columnar | ClickHouse, DuckDB, Snowflake, BigQuery, Databricks | Fast aggregations on billions of rows. |
| Search | OpenSearch, Elasticsearch, Typesense, Meilisearch | Full-text + faceted search. |
| Vector | pgvector, Qdrant, Weaviate, Pinecone, Milvus | ANN search on embeddings. |
| Time-series | TimescaleDB, InfluxDB, VictoriaMetrics, QuestDB | Metrics, telemetry, sensor data. |
| Graph | Neo4j, Memgraph, Apache AGE, Amazon Neptune | Traversal-heavy queries. |
| Object / blob | S3, R2, GCS, Azure Blob, MinIO | Files, media, backups, lakehouse layer. |
9.2 · OLTP relational — Postgres is the default
- Postgres: extensions for JSON, full-text, geospatial (PostGIS), time-series (Timescale), vector (pgvector), graph (AGE), HLL. One DB, many superpowers.
- MySQL / MariaDB: simpler ops; PlanetScale / Vitess for horizontal sharding.
- Managed: Aurora (AWS), Cloud SQL (GCP), Neon (serverless branching), Supabase.
- SQLite: surprisingly fine for small apps; Litestream + Fly = edge SQLite.
9.3 · KV · document · wide-column
| Family | Read/write trade |
|---|---|
| KV (Redis/Memcached) | Sub-ms RW; in-memory; tiny payloads. |
| Document (Mongo) | Embed-or-reference design; rich queries; transactions per shard. |
| Wide-column (Cassandra/Scylla) | Heavy write throughput; design schema around query patterns (no joins). |
9.4 · OLAP / analytics
- ClickHouse — columnar, parallel, ridiculous aggregation speed.
- DuckDB — embedded; "SQLite for analytics"; query Parquet directly.
- Snowflake / BigQuery / Databricks SQL — managed warehouses.
- Iceberg / Delta / Hudi — open table formats on S3/Parquet (lakehouse).
9.5 · Search
- OpenSearch / Elasticsearch — full-featured; Lucene-based; powerful but heavy.
- Typesense / Meilisearch — typo-tolerant, fast, dev-friendly.
- Postgres FTS +
tsvector— surprisingly OK for < 10M docs. - Hybrid search: combine keyword (BM25) + vector with RRF (see AI Codex Ch 9).
9.6 · Vector — the ANN tier
| Index | Trade-off |
|---|---|
| Flat (brute-force) | Exact, slow at scale. |
| IVF | Cluster + probe nearest; fast, slight recall loss. |
| HNSW | Graph-based; sub-ms at huge scale. The default. |
| PQ / SQ | Compressed vectors; trades memory for accuracy. |
9.7 · Time-series
TimescaleDB, InfluxDB, VictoriaMetrics, QuestDB. Continuous aggregates, downsampling, retention policies. For metrics specifically — Prometheus, Mimir/Cortex/Thanos for long-term.
9.8 · Graph
Neo4j (Cypher), Memgraph, Apache AGE, Neptune (Gremlin + openCypher), TigerGraph. Use when traversal is the core query pattern (recommendations, fraud rings, knowledge graphs).
9.9 · Object & files
S3 / R2 / GCS / Azure Blob / MinIO. Plan for: lifecycle rules, presigned URLs, KMS encryption, replication, multi-part uploads. R2 has zero egress fees — material at scale.
9.10 · NewSQL & distributed SQL
| System | Notes |
|---|---|
| Google Spanner / AlloyDB | Global strong consistency via TrueTime. |
| CockroachDB | Spanner-style OSS; HLC clocks. |
| YugabyteDB | Postgres-compatible distributed. |
| TiDB | MySQL-compatible; row + columnar (TiFlash). |
| FoundationDB | Ordered KV; rock-solid; the substrate under Snowflake, Apple's iCloud. |
9.11 · ACID, MVCC, isolation levels
| Level | Prevents | Still allows |
|---|---|---|
| Read Uncommitted | — | Dirty reads possible |
| Read Committed | Dirty reads | Non-repeatable reads, phantoms |
| Repeatable Read | + Non-repeatable | Phantoms (classic); Postgres MVCC blocks these |
| Snapshot | Dirty, non-repeatable, phantoms via MVCC | Write skew (use SERIALIZABLE) |
| Serializable | All anomalies | — |
MVCC: each transaction sees a snapshot; Postgres tracks tuple versions, vacuum reclaims dead ones. Long-running transactions cause bloat — kill them.
9.12 · Schema & migrations
- Migrations are code. Version them, review them, test them.
- Every migration is online + reversible.
- Add nullable column → backfill → flip NOT NULL.
- Renames: add new → write to both → backfill → switch reads → drop old.
- Postgres:
CREATE INDEX CONCURRENTLY; watch lock_timeout, statement_timeout. - Tools: Atlas, Flyway, Liquibase, Prisma Migrate, Alembic, Goose, sqlx, golang-migrate.
9.13 · Multi-tenant patterns
| Pattern | Isolation |
|---|---|
| Shared schema, tenant_id column | Logical; enforce with row-level security (Postgres RLS). |
| Schema per tenant | Stronger; migration cost scales. |
| DB per tenant | Strongest; operationally heavy. |
| Hybrid (shards of tenants) | The pragmatic large-scale choice. |