HELM
Ch 08 · Databases & Storage
Chapter 08 · Where state lives

Databases & Storage — the choice that defines the system

You pick a database once and live with it for years. This chapter is the matrix of when to pick which, plus the schema, transaction, and migration patterns you can't afford to get wrong.

8.1 · The nine database families

OLTP — Postgres, MySQL KV — Redis, Valkey Document — Mongo Wide-column — Scylla OLAP — ClickHouse, DuckDB Search — OpenSearch Vector — pgvector, Qdrant Time-series — Timescale Graph — Neo4j, AGE Object — S3, R2, MinIO Embedded — SQLite, DuckDB Newsql — Spanner, Yuga

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

FamilyExamplesSweet spot
KV / cacheRedis, Valkey, Dragonfly, KeyDB, Cloudflare KVSessions, hot lookups, rate limits, queues.
DocumentMongoDB, CouchDB, FirestoreFlexible schemas; one-doc reads at scale.
Wide-columnCassandra, ScyllaDB, BigTable, DynamoDBMassive 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).
  • 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

LevelPreventsExamples that allow
Read Uncommitted—Dirty reads possible
Read CommittedDirty readsNon-repeatable reads, phantoms
Repeatable Read+ Non-repeatable readsPhantoms (in classic; Postgres MVCC blocks these too)
SerializableAll anomalies—
Snapshot Isolation (Postgres "Repeatable Read")Dirty + non-repeatable + phantoms via MVCCWrite 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

  1. Migrations are code. Version them. Review them.
  2. Make every migration online + reversible: add nullable column → backfill → make NOT NULL.
  3. Never rename a column in one deploy. Add new → write to both → backfill → switch reads → drop old.
  4. Use CREATE INDEX CONCURRENTLY in Postgres. Watch out for lock-waits.
  5. Tools: sqlx, flyway, liquibase, atlas, prisma migrate, alembic, goose.

8.12 · Multi-tenant patterns

PatternIsolationCost
Shared schema, tenant_id columnLogicalCheap; risk of cross-tenant leak — enforce with RLS.
Schema per tenantStrongerMigration cost grows linearly.
DB per tenantStrongestOperationally heavy; "noisy neighbour" gone.
Hybrid (DB per shard of tenants)ConfigurableThe pragmatic large-scale choice.

8.13 · Self-check

Q1 · You need fast aggregations on 5 billion rows of analytics events. Best pick?
Postgres
ClickHouse
Redis
MongoDB