No technology is the best one. Each choice gives you something and costs you something. Compare 8 common choices: change the numbers and watch both sides.
The choice. Where do the writes go? To one main server that keeps every rule, or to many servers that share the load by key.
Try both under load
Move a slider and watch both sides. These numbers come from a small model of how each system behaves, not from a real test.
Slow requests ( (The time within which 99 out of 100 requests finish. The slowest 1% take longer.)) as requests a second grow
PostgreSQL (SQL)Cassandra (NoSQL)
Show data table
Time
PostgreSQL (SQL)
Cassandra (NoSQL)
1k
8.5 ms
3.5 ms
3.5k
8.5 ms
3.6 ms
6k
8.5 ms
3.6 ms
8.4k
8.5 ms
3.7 ms
11k
8.5 ms
3.8 ms
13k
9.7 ms
3.8 ms
15k
11.4 ms
3.9 ms
18k
15.4 ms
3.9 ms
21k
19.1 ms
4 ms
23k
23.3 ms
4.1 ms
26k
28.1 ms
4.1 ms
28k
33.5 ms
4.2 ms
31k
39.5 ms
4.2 ms
33k
46.2 ms
4.3 ms
36k
53.4 ms
4.4 ms
38k
61.2 ms
4.4 ms
41k
69.7 ms
4.5 ms
43k
78.9 ms
4.5 ms
46k
88.7 ms
4.6 ms
48k
99.1 ms
4.7 ms
51k
110 ms
4.7 ms
53k
122 ms
4.8 ms
55k
135 ms
4.8 ms
58k
148 ms
4.9 ms
60k
162 ms
4.9 ms
63k
176 ms
5 ms
65k
191 ms
5.1 ms
68k
207 ms
5.1 ms
70k
224 ms
5.2 ms
73k
241 ms
5.2 ms
75k
260 ms
5.3 ms
78k
278 ms
5.4 ms
80k
298 ms
5.4 ms
83k
318 ms
5.5 ms
85k
339 ms
5.5 ms
88k
361 ms
5.6 ms
90k
384 ms
5.7 ms
93k
407 ms
5.7 ms
95k
431 ms
5.8 ms
98k
456 ms
5.8 ms
100k
482 ms
5.9 ms
The shaded band is where you are now: 15,000 requests a second. p99 is the time the slowest 1 in 100 requests take.
Turn this on for money or stock, where a half-done write is not allowed.
Side by side at this load
A shorter bar is better.
Slow requests (p99)scale 0 to 20 ms
PostgreSQL (SQL)
11.4 ms
Cassandra (NoSQL)
3.9 ms
Cassandra (NoSQL) is 2.9× lower.
CPU loadscale 0 to 100%
PostgreSQL (SQL)
49%
Cassandra (NoSQL)
14%
Cassandra (NoSQL) is 3.5× lower.
Cost a monthscale 0 to $1,000
PostgreSQL (SQL)
$840
Cassandra (NoSQL)
$681
Cassandra (NoSQL) is 1.2× lower.
The numbers at this load
PostgreSQL (SQL)
Cassandra (NoSQL)
Typical request (p50)
4.2 ms
1.3 ms
Slow request (p99)
11.4 ms
3.9 ms
CPU load
49%
14%
Cost a month
$840
$681
State
Healthy
Healthy
What to pick at this load
PostgreSQL is enough
At 15,000 requests a second, PostgreSQL keeps up. It also gives you joins and transactions, which are hard to add later.
SQL or NoSQL database: how each one is built
SQL database (PostgreSQL, MySQL)
Application — healthy
Primary — takes every write — healthy
Replica — reads only — healthy
Replica — reads only — healthy
Request/response
Replication link
Data lives in tables with fixed columns. A transaction changes several rows together, or none of them.
Good at
Money and stock stay correct, because a transaction never half-finishes.
One query can join many tables, such as orders with customers.
Most engineers and tools already speak SQL.
What it costs you
All writes go to one main server, so writes are hard to scale.
Splitting the data across servers (sharding) is hard work.
Changing a big table can need planned downtime.
Typical latency
1 to 10 ms with an index
Work to run it
Low to medium
Best for
Payments, orders, user accounts
NoSQL store (Cassandra, DynamoDB, MongoDB)
ApplicationApplicationNode 1, a third of the keysNode 1a third of the keysNode 2, a third of the keysNode 2a third of the keysNode 3, a third of the keysNode 3a third of the keys
Application — healthy
Node 1 — a third of the keys — healthy
Node 2 — a third of the keys — healthy
Node 3 — a third of the keys — healthy
Request/response
Data is stored by key, with no fixed columns. The store spreads the keys across many servers by itself.
Good at
Add servers to handle more writes. There is no single main server.
Each record can have its own fields, so the shape can change fast.
It stays up when a server or a network link fails.
What it costs you
No joins: the app must fetch records and combine them itself.
A read can return old data for a short time.
You often store the same data twice, once for each way of reading it.
Typical latency
Under 5 ms for a key lookup
Work to run it
Medium to high
Best for
Sensor data, click streams, chat messages
Point by point
PostgreSQL (SQL) is better on 3 of these 5 points, and Cassandra (NoSQL) on 2. Count the points that matter to your system, not the total.
PostgreSQL (SQL)
Cassandra (NoSQL)
Writes that must stay exact
A transaction can change many rows and tables together. Better here
A transaction is often limited to one record or one partition.
Growing the write load
One main server takes the writes. Past its limit you must shard.
Add a server, and the store moves some keys to it. Better here
Asking new questions of the data
Joins and indexes answer queries nobody planned for. Better here
It is fast only for the lookups its tables were designed for.
Reading right after a write
The main server returns the new value. A replica may lag. Better here
It depends on settings. A read may see the old value for a moment.
A server fails
A replica must be promoted, and writes wait until it is.
Other servers hold copies and keep answering. Better here