DB Choice Matrix — Workload → Pick

Ngắn gọn cho lúc đang spec dự án mới.

Tags: attachment cheatsheet decision Liên quan: Tuan-10-Redis-Mastery · Tuan-11-DynamoDB-Cassandra · Tuan-14-OLAP-Columnar-ClickHouse


1. Master Decision

flowchart TD
    A[Workload?] --> B{OLTP / OLAP / KV / Search / Vector?}

    B -->|OLTP transactional| C{Single region?}
    C -->|Yes <10TB| C1[Postgres]
    C -->|Multi-region / >10TB| C2[CockroachDB / TiDB / Aurora DSQL]

    B -->|OLAP analytics| D{Latency sensitive?}
    D -->|Sub-second dashboards| D1[ClickHouse]
    D -->|Minutes OK| D2[BigQuery / Snowflake / Iceberg+Trino]
    D -->|Local embedded| D3[DuckDB]

    B -->|KV / cache / session| E{Persistence?}
    E -->|In-memory OK lose| E1[Redis / Valkey]
    E -->|Durable| E2[DynamoDB / Cassandra / FoundationDB]

    B -->|Document flexible| F{Cardinality + access pattern?}
    F -->|Predictable| F1[Postgres JSONB]
    F -->|Truly polymorphic| F2[MongoDB]

    B -->|Search keyword + fuzzy| G[Elasticsearch / OpenSearch]

    B -->|Vector AI / RAG| H{Vector count?}
    H -->|<10M| H1[pgvector]
    H -->|>10M| H2[Qdrant / Pinecone / Milvus]

    B -->|Graph traversal >3 hops| I[Neo4j / Memgraph]

    B -->|Time-series sensor / metrics| J{Cardinality?}
    J -->|Low| J1[Prometheus / VictoriaMetrics]
    J -->|High| J2[TimescaleDB / InfluxDB v3]

    style C1 fill:#c8e6c9
    style H1 fill:#c8e6c9
    style F1 fill:#c8e6c9

2. By Use Case

Use CasePickReason
Web app, <10TB, single regionPostgresBoring tech, ACID, ecosystem
SaaS multi-tenant 100-10K tenantsPostgres + RLSPool + isolation
Multi-region active-activeAurora DSQL / CockroachDBStrong consistency global
Massive write throughput >100K/sCassandra / ScyllaDB / TiKVSharded writes
Cache, session, leaderboardRedis / Valkeyµs latency, atomic ops
Queue with at-least-onceRedis Streams / KafkaPersisted log
Job queue lightweightPostgres SKIP LOCKEDNo new system
Full-text search >1M docsElasticsearch / OpenSearchInverted index, ranking
Full-text search <1M docsPostgres FTS + GINSaves a system
Real-time analytics dashboardsClickHouseSub-second OLAP
Data warehouse / BIBigQuery / SnowflakeServerless, SQL
Open lakehouseIceberg + Trino / SparkMulti-engine, cheap S3
Local notebook analyticsDuckDBEmbedded, fast
Time-series metricsVictoriaMetrics / PrometheusCompressed, native PromQL
Time-series business (IoT)TimescaleDBSQL + retention + downsample
RAG <10M vectorspgvectorReuse Postgres
RAG enterprise scaleQdrant / PineconeFiltered search at scale
Knowledge graph / fraudNeo4jGraph traversal
Edge / mobile / localSQLite (+ Litestream)In-process, simple
Document store flexible schemaMongoDBNative doc
Polyglot persistenceMultiple via CDC (Debezium)Postgres as source of truth

3. Common Stacks 2024-2026

Startup MVP

Postgres (primary) + Redis (cache) + S3 (files) + Stripe

SaaS B2B at scale

Postgres (per-tier pools, RLS for small) + PgBouncer + Redis + ES + Kafka (CDC)

Real-time analytics product

App → Kafka → Flink → ClickHouse + Iceberg (cold) → BI tools
       └─→ Postgres (OLTP)

AI / RAG product

Postgres (source of truth) + Qdrant (vectors) + ES (BM25) +
Redis (semantic cache) + LLM API

Multi-region e-commerce

Aurora DSQL OR CockroachDB (primary) + ElastiCache + ES global cluster +
DynamoDB Global Tables (carts) + S3 multi-region

4. Cost Sanity Check (2024 ballpark)

WorkloadSelf-hostManaged (AWS)
100GB Postgres OLTP$200/mo (EC2 + EBS)$300/mo RDS
1TB ClickHouse$500/mo$1500/mo Aiven
10M Redis cache$100/mo$400/mo ElastiCache
100GB ES$400/mo$1000/mo OpenSearch Service
1TB DynamoDB on-demandN/A$250/mo + IO
10M vectors Qdrant$200/mo$400-2000/mo Qdrant Cloud
1TB Iceberg S3$25/mo storage$25/mo storage + compute

5. Defaults — When in Doubt

graph LR
    Default[Don't know yet?] --> Postgres[Use Postgres]
    Postgres --> Pain[Production pain]
    Pain --> Specific[Add specific tool for specific reason]

    style Postgres fill:#c8e6c9

Postgres handles: OLTP, JSONB, full-text, geo (PostGIS), time-series (decent), vector (pgvector), graph (recursive CTE), queue (SKIP LOCKED), pub/sub (LISTEN/NOTIFY).

When to leave Postgres:

  • Specific scale/latency need PROVEN
  • Specific feature mandatory (e.g., true distributed transactions)
  • Team capable of operating extra system

Default to Postgres is rarely wrong for <10 engineers + <1TB.

6. Migration Cost Reality

graph LR
    A[Add new DB] --> B[Code: 2-4 weeks]
    A --> C[Migration: 1-3 months]
    A --> D[Operational: ongoing]
    A --> E[Team learning: ongoing]

    F[Total cost] -.->|easily 6-12 months engineer time| Final

→ Always evaluate: “can current DB handle this with optimization?” before adding new one.


Cập nhật: 2026-05-16