Choosing a database type
A practical map from workload to database: relational, document, key-value, wide-column, search, graph, time-series and vector stores.
On the roadmap:Software Architect · step 4: Data at scale
Lesson 5 of 5 · 13 min read · quiz · exercise
Start from the access pattern
There is no best database; there is a best database for a workload. Ask:
- What are the main queries (by key, by range, by search, by relationship)?
- How much data and how fast does it grow? Read/write ratio?
- What consistency and transaction guarantees are needed?
- What latency is required, and where are users?
- What can your team operate?
The families
Figure SDA-DDV-05-1 · Map from need to database family · © forcsguy.com
Relational (PostgreSQL, MySQL)
Tables, SQL, joins, constraints, ACID transactions. The default for most business data. PostgreSQL has rich features (JSON, full-text, extensions, many index types); MySQL is widely deployed and simple to operate. They scale vertically very far, and read replicas and sharding extend them. Choose when data is structured, relationships matter and correctness is critical.
Document (MongoDB and similar)
Stores JSON-like documents; flexible schema; related data can be embedded in one document so a single read gets everything. Good for content, catalogues and objects read whole. Watch for duplicated data, joins you must do in code, and weaker multi-document transaction habits.
Key-value (Redis, Memcached; DynamoDB as a key-value/wide hybrid)
Lookup by key at very low latency. Redis adds data structures (hashes, sorted sets, lists, bitmaps), persistence and clustering (see the Redis lesson). Ideal for caches, sessions, counters, rate limits, leaderboards. Not for ad-hoc queries.
Wide-column and partitioned key stores (Cassandra, DynamoDB, HBase)
Data is partitioned by a partition key across many nodes; you design tables around queries. Excellent write throughput, horizontal scale and availability. Cost: limited query flexibility, careful key design (hot partitions), eventual consistency by default. Good for event logs, messaging history, time-ordered user data.
Search engines (Elasticsearch, OpenSearch, Solr)
Build an inverted index (word to documents) for full-text search, relevance scoring, filters and facets. Usually a secondary copy of data from a primary database, kept in sync. Not a system of record: treat it as a derived index that can be rebuilt.
Graph (Neo4j and others)
Stores nodes and relationships and answers questions that follow connections: friends of friends, fraud rings, recommendations, dependency analysis. Where many-hop traversals would need expensive recursive joins in SQL, a graph database is natural.
Time-series (InfluxDB, TimescaleDB, Prometheus)
Optimised for append-heavy, timestamped data with time-range queries, downsampling and retention. Used for metrics, IoT and finance ticks (see the metrics monitoring lesson). Keep tag cardinality low.
Vector databases (and vector indexes in other databases)
Store embeddings (arrays of numbers representing meaning) and find the nearest neighbours, using approximate indexes (graph-based or clustering) for speed. Used for semantic search and retrieval for AI applications. Many general databases now offer vector indexes, which can be enough for moderate scale and avoids another system.
A quick chooser
| Need | First choice |
|---|---|
| Business data with relationships and transactions | Relational |
| Flexible, self-contained records | Document |
| Cache, session, counter, leaderboard | Redis |
| Massive write volume, simple access by key | Wide-column / DynamoDB-style |
| Full-text search and facets | Search engine |
| Many-hop relationship queries | Graph |
| Metrics and sensor data | Time-series |
| Semantic similarity | Vector index |
| Analytics on large history | Warehouse or lakehouse (see the big data course) |
Polyglot persistence and its price
Many systems use several stores, each for what it does best: a relational database as the source of truth, a cache, a search index and a metrics store fed from it. The cost is keeping them in sync (change events, outbox pattern, rebuild jobs), more to operate and more failure modes. Add a store only when a measured need justifies it.
SQL versus NoSQL, honestly
"NoSQL" is a family of different designs, not one thing. Relational databases scale further than many assume; NoSQL stores often give up joins and some consistency for scale and flexibility. Decide on requirements, not fashion. If in doubt, start relational and specialise later.
Questions before committing
- Can we model our top ten queries easily?
- What happens at 10 times the data? At a regional failure?
- How do we back up, restore, migrate and monitor it?
- Does the team know it, and is it supported well on our platform?
Real-world reading
Related reading
- Redis UniversityRedis · Redis Ltd.Courses
- RedisRedis · Redis Ltd.GitHub
- Redis DocumentationRedis · Redis Ltd.Documentation
- Build Your Own XCodeCrafters · GitHubGitHub
Show 6 moreShow fewer
- Redis persistenceRedis · Redis Ltd.Documentation
- Moving Food Feed from Redis to Cassandra at ZomatoZomato engineers · ZomatoCase Studies
- Scale with Redis ClusterRedis · Redis Ltd.Documentation
- Improving key expiration in Redis at TwitterTwitter engineers · TwitterCase Studies
- Migrating MySQL from 5.6 to 8.0 at FacebookFacebook engineers · FacebookCase Studies
- Decreasing RAM Usage by 40% Using jemalloc with Python & Celery at ZapierZapier engineers · ZapierCase Studies
Check your understanding
Question 1 of 3
0 correct so far
A feature needs 'find products similar in meaning to this description'. Which store type fits?
Go deeper
- Which database should I use? (cloud decision guides) by Cloud provider documentation: each major cloud publishes a decision tree for its own services
Topics covered in this lesson
Practise it: Pick the store for a write-heavy load
Everything below is already set up for this lesson: change the design, run the traffic, and see whether you meet the goal.
- 1The task
- 2Build and test
Half of 2,500 requests per second are writes. Some stores scale writes by sharding; a single primary does not.
Goal: Under 1% errors, database below 90% busy.
Select the Database part and look at its shards.
Try it yourself
For a social app, assign a store to each: user accounts and orders, a user's feed cache, full-text search of posts, 'friends of friends' suggestions, and per-minute usage metrics.
Click what a strong design here would need:
More in Building blocks
© 2026 forcsguy.com. Original lesson text and diagrams. Books and sites linked above belong to their authors.