Choosing a database: SQL, documents, graphs, and search
Document Databases
Each record carries its own structure β no shared column contract
A document store is like a smart filing cabinet where each folder can contain a completely different set of papers. A user profile might have 3 fields. A product listing might have 40. An event log might have 12. They all live in the same cabinet β no row needs to match any other row's layout.
Engineers invented document databases because relational tables punish evolution. Every time a product team adds a new field, someone has to run an ALTER TABLE migration that locks the table for minutes. Document stores say: every record carries its own schema. Add a field? Just put it in the document. No migrations, no NULL columns, no coordination.
MongoDB
The most popular document database in the world
MongoDB
The most popular document database in the world
Mental model
MongoDB stores data as JSON-like documents. Imagine storing a blog post with its author, tags, comments, and metadata all in a single document β rather than split across 5 different tables with JOINs connecting them. Reads are fast because everything you need is already in one place.
Why it exists
Created in 2009 after the founders built a web platform and hit constant schema migration pain with MySQL. They wanted a database that modelled objects the way developers actually think about them β as documents, not rows.
Shines at
- Content management & publishing platforms
- E-commerce product catalogs with variable attributes
- User profiles with different fields per user type
- REST API backends where payloads vary
- Rapid prototyping and early-stage products
Breaks down when
- Multi-document ACID transactions at scale
- Complex JOIN-heavy relational queries
- Strict data integrity and enforcement
- Heavily normalized, relational data models
Real-world use
Airbnb's listing catalog, Forbes content platform, and eBay's buyer-seller messaging platform all use MongoDB for flexible document storage.
Firestore
Google's serverless document DB with real-time sync
Firestore
Google's serverless document DB with real-time sync
Mental model
Firestore is like a document database that broadcasts updates live. When a user changes their profile, every connected device sees the update within milliseconds β without polling. It manages the infrastructure, scaling, and sync automatically.
Why it exists
Mobile apps needed a database that synced data in real time to millions of devices without backend engineers managing WebSocket infrastructure. Firestore gives you real-time listeners for free, at Google scale.
Shines at
- Mobile and web apps with real-time sync
- Collaborative tools (live document editing, shared todos)
- Applications where offline-first is important
- Serverless startups wanting zero infrastructure
Breaks down when
- Complex aggregation queries
- High-throughput write-heavy workloads
- Cost at very large scale (per-read pricing)
- Applications needing fine-grained SQL queries
Real-world use
The New York Times, Duolingo, and thousands of mobile startups use Firestore for their real-time data layer.
CouchDB
Built for offline-first, multi-master sync
CouchDB
Built for offline-first, multi-master sync
Mental model
CouchDB was designed for a world with unreliable connectivity. Data can be written to a local CouchDB instance when offline, then automatically synced and merged when connectivity returns β using conflict resolution rules to handle simultaneous edits.
Why it exists
Built for distributed systems where nodes go offline, get reconnected, and need to reconcile changes. Healthcare, logistics, and field operations β where connectivity is intermittent β need a database that works offline and syncs automatically.
Shines at
- Offline-first mobile and desktop applications
- Multi-master geo-distributed sync
- Scenarios with intermittent connectivity
- Use cases requiring built-in conflict resolution
Breaks down when
- High-throughput OLTP workloads
- Complex query performance vs MongoDB
- Large-scale analytical queries
Real-world use
NHS digital health records in the UK use CouchDB for offline-first data access in hospitals with intermittent connectivity.
Your Path
Key Traits
Pick When
- Product catalogs, CMS, user profiles
- Mobile app with variable schema
- Read-heavy with complex objects
Used By
Core Tradeoff
Developer velocity β referential integrity is your problem
Browse database families
Decision explanations
What operational model best fits this workload?
A platform records thousands of financial operations per minute. Each operation touches multiple tables β deducting from one account, crediting another, updating a balance ledger. Partial writes must never succeed. Queries need to join across user, account, and transaction tables in real time.
Transactional (OLTP)
OLTP = individual, frequent writes where every single transaction must be correct. OLAP is the opposite β it scans huge amounts of historical data to answer questions like 'what was total revenue last quarter?' When every write matters, you need OLTP.
Analytical (OLAP): OLAP databases are built for scanning large amounts of old data all at once (like monthly reports). They trade away per-row correctness for bulk scan speed β terrible for thousands of individual write operations per second.
What storage architecture optimises this workload?
You run nightly BI reports: total revenue by region, cohort retention, anomaly detection. Queries scan hundreds of millions of rows but nothing is ever updated after it's written. Tables have 80+ columns per row but queries only need a few at a time.
Data Warehouse (Columnar)
Columnar storage is a direct response to analytical query patterns. When you query 2 out of 80 columns across 500M rows, a row-store reads all 80 columns for every row β wasting 97% of disk I/O. A columnar store reads only those 2 columns, compresses them heavily, and aggregates them in a single scan pass.
RDBMS (Row Store): Row-oriented stores are fast at fetching complete records β but analytical queries scan billions of partial rows. An RDBMS touching 500M rows would deserialise all 80 columns per row even when you only need 2 β wasting enormous I/O bandwidth and making queries 10β100Γ slower than a columnar store.
Which transactional database family fits this workload?
Your app handles 8,000 transactions per second in a single region. Schema is stable. Queries join across 5β8 tables per request. No need to spread writes across multiple servers.
RDBMS
NewSQLβs distributed write scaling adds operational complexity only justified when you need to shard writes across regions β typically at 100k+ TPS or for global multi-master deployments. This workload fits well within primary-replica RDBMS capacity, making NewSQL overhead unnecessary.
NewSQL: NewSQL solves one problem: writing to multiple servers across regions simultaneously. Great at Google scale. But it adds latency overhead per write and is complex to operate. If one server handles your load, RDBMS is the simpler, faster choice.
What data organisation model fits a workload where every entity carries a different field set?
Your product catalog has 200M items. Electronics have wattage. Clothes have size and material. Furniture has dimensions. No two categories share the same fields. 40% of queries fetch a full item. 40% filter by attribute combinations. Schema changes every time a new category launches.
Document-Oriented
Document databases let each item carry exactly its own fields β no null columns for attributes a product doesn't have. You can add an index on any field and query it directly. Key-value stores can only look up by exact key β you'd need to build an entire query engine on top just to filter by attributes.
Key-Driven Access: Key-value = 'give me the item with key #12345'. That's the only query it supports. No 'show me all electronics under $100', no filtering by attributes. For a query-heavy product catalog you'd have to pre-compute every possible filter combination yourself β that's the application's job, not the database.
As multi-hop relationship traversal becomes the dominant query pattern, what architectural response is correct?
Your social app runs on MongoDB. A new feature needs: 'find friends-of-friends who bought the same product the user did' β that's 4 levels of relationships. These queries take 9β14 seconds and pin the CPU. The deeper the social graph grows, the worse it gets.
Graph Database
Graph databases store relationships as physical pointers. Each hop is O(1) β instant, no matter how big the database is. In MongoDB, every hop is another aggregation step that multiplies the work. At 4 hops on 10M users, that's billions of operations. Graph databases solve this in milliseconds.
Denormalised Documents: Embedding relationships in arrays works for simple things like 'a post's top 5 comments'. Social graphs are different β they're unbounded. A user's 3-hop network could be millions of people. Storing that as nested arrays uses gigabytes per user and the query is still slow. It doesn't fix the fundamental problem.
For this read-dominated, key-exact workload, which architecture serves the latency and access pattern?
A ride-hailing app tracks live GPS for 3M drivers (200k writes/sec, 1M reads/sec, must respond in under 2ms). Also serves surge pricing per city zone and manages session data per active ride. All lookups are exact key lookups β no filtering or joins needed.
In-Memory Key-Value Store
The bottleneck is read speed: under 2ms. In-memory key-value stores (like Redis) keep all data in RAM β reads are microseconds, not milliseconds. Column-family databases write to disk, so reads take 15β50ms. When you need blazing-fast reads, you need data in memory.
Distributed Column-Family: Cassandra excels at absorbing massive write storms β IoT sensors writing millions of events per second. The trade-off: reads hit disk, taking 15β40ms. Perfect for 'store everything and query later' data. Terrible for a live driver map that needs to respond in under 2ms.
When time is the organising dimension and every query is a time range, what database family is architecturally aligned?
80,000 connected vehicles each send 400 sensor readings per second (speed, battery, brakes, GPS...) = 32M data points per second. You need: 'plot battery over the last 4 hours for vehicle X', 'alert if brake pressure drops', 'fleet average fuel consumption over 7 days'. No text search. Every query is a time window.
Time-Series Database
Time-series databases are built exactly for sequential numeric measurements. They compress repeated similar values efficiently (battery at 80%, 81%, 80%... is stored as tiny deltas) and run time-window queries natively. Search engines index words β vehicle sensor data has no words. You'd pay enormous memory cost for indexes that are completely useless here.
Search / Log Analytics Engine: Search engines shine for text: log messages, error descriptions, user queries. They build word indexes. But vehicle telemetry is pure numbers β speed: 62, battery: 77%, brake: 94%. There's nothing to text-search. You'd waste memory on word indexes and miss the compression and time-range query features that time-series gives you.
