Cassandra vs PostgreSQL benchmarks: one node, two ideas of where the work goes
PostgreSQL and Cassandra are both called databases, but they put the work in different places. PostgreSQL keeps each table as a heap of 8 KB pages with B-tree indexes beside it, and changes a row on its page: to overwrite a row it has to have that page in memory, writes a new row version beside the old one and logs the change to its write-ahead log (WAL). Cassandra is a log-structured merge tree: a write goes to a commit log and an in-memory table (the memtable) and is acknowledged without reading anything; the memtable is later flushed to immutable sorted files (SSTables) that compaction merges in the background, and a read has to look in the memtable and in every SSTable that might hold the row. PostgreSQL answers any SQL over the whole table on one primary; Cassandra answers queries by partition key, and spreads partitions over as many nodes as you add.
So the question is less “which is faster” than “which work does each make cheap”. This benchmark puts both on one machine, single node each, on the same 4 cores, the same memory limit and the same disk, and measures each kind of work. Every value is derived from its key, and every value read back is compared byte for byte with what was written: 4,392,189,507 rows (point reads, slice rows, reads in the mixed test, rows read back after kill -9), 0 mismatches. On top of the 1,000,000,000 bulk-loaded rows, the tests wrote 408,476,297 rows.
| Setup | Details |
|---|---|
| Databases | PostgreSQL 18.6 · Cassandra 5.0.9 (OpenJDK 17, G1) · official images pinned by digest, one database running at a time, single node, no replication |
| Data | Time-series readings: (device bigint, ts bigint, v blob), primary key (device, ts); in Cassandra device is the partition key and ts the clustering column, newest first (CLUSTERING ORDER BY (ts DESC)). 100-byte values: 16 bytes repeat the key, 84 bytes come from a pseudo-random stream seeded by the key, so no two rows share filler and compression can only shrink the key bytes |
| Two scales | In memory: 10 M rows (20,000 devices × 500 readings), 16 GB memory limit: PostgreSQL’s table and index take 1.8 GB, Cassandra’s 0.96 GB · larger than memory: 40 M rows (100,000 × 400), 4 GB limit: PostgreSQL 7.2 GB against 1 GB of shared buffers and what is left of the 4 GB for the page cache; Cassandra 3.9 GB against the 2 GB left after its 2 GB heap. Every data file is dropped from the page cache before the first read |
| Settings | Defaults, except memory: PostgreSQL shared_buffers at 25 % of the limit (4 GB / 1 GB; the default is 128 MB) and max_connections=300; Cassandra’s heap at what its own cassandra-env.sh picks for a machine with that much memory (8 GB / 2 GB; the script reads the host’s RAM, not the container’s limit, so it has to be set). Cassandra runs the image’s backward-compatible cassandra.yaml: size-tiered compaction (STCS), the BIG SSTable format, LZ4, commitlog_sync: periodic every 10 s; the cassandra_latest.yaml that Cassandra 5 recommends for new clusters (unified compaction, trie-indexed SSTables) was not tested. PostgreSQL: synchronous_commit=on, max_wal_size 1 GB, checkpoint_timeout 5 min |
| Clients | One Go 1.26 program: pgx 5.12, one pooled connection per request in flight (256 in the mixed test) · Apache Cassandra Go driver 2.1.2, token-aware (each request goes straight to the node that owns its partition), consistency ONE, 2 connections (the driver’s default; each carries thousands of requests at once), its write coalescing switched off: its default 200 µs wait held every request about 1.1 ms on this machine. That is the one setting changed on a client; PostgreSQL’s side needed none · every statement prepared · every write an upsert: Cassandra’s INSERT always is one, PostgreSQL’s is INSERT … ON CONFLICT DO UPDATE |
| CPU | AMD Ryzen AI Max+ 395 · cores 0–7 and their SMT siblings reserved for the benchmark (system services and movable IRQs moved to the other CCD) · database on cores 0–3 (4 cores, 8 threads), client on cores 4–7 · CPU time of each side recorded for every test |
| Storage | One directory on an NVMe SSD (ext4), emptied before every server start, shared with other workloads on this machine · between groups of tests the database is settled, and the time it takes is recorded as deferred work: PostgreSQL VACUUM ANALYZE and CHECKPOINT; Cassandra nodetool flush and no pending compactions |
| Method | Every value is 10 runs, each a fresh client process, each on a freshly loaded server · reported value: median of the runs (mean of the two middle ones), with min–max · latency percentiles per run, then the median across runs · for every test, PostgreSQL’s “checkpoints are occurring too frequently” warnings and Cassandra’s garbage-collection pauses are counted |
Which one is for what
| PostgreSQL | Cassandra | |
|---|---|---|
| Data model | Tables, any number of indexes, joins, constraints, SQL | Tables queried by partition key; rows within a partition sorted by clustering columns; one table per query pattern |
| A write | Needs the row’s page in memory (reads it if it is not cached), writes a new row version, logs it to the WAL | Appends to the commit log and the memtable; never reads |
| A read | One index lookup, one heap page | The memtable and every SSTable whose Bloom filter (a compact “might contain” index) says it might hold the partition |
| Transactions | ACID across any rows and tables | Atomic per partition; lightweight transactions (Paxos) for compare-and-set |
| Scaling out | One primary takes the writes; replicas for reads; sharding is extra software | Add nodes: partitions spread by token, every node takes writes, replication factor and consistency per query |
| When a node fails | Failover to a replica | Nothing to fail over: other replicas answer |
The first four rows are what this benchmark measures on one node. The last two are why Cassandra exists, and a single node does not show them; they are the subject of ten ways to scale a database.
The scoreboard
| Measure | PostgreSQL | Cassandra | Leader |
|---|---|---|---|
| Point read · in memory | 585k | 184k | PostgreSQL, 3.2× |
| Point read · larger than memory | 133k | 91k | PostgreSQL, 1.5× |
| Newest 100 readings · in memory | 139k | 52k | PostgreSQL, 2.7× |
| Overwrite · in memory · both fsync first | 57k | 40k | PostgreSQL, 1.4× |
| Overwrite · in memory · both fsync later | 231k | 446k | Cassandra, 1.9× |
| Overwrite · larger than memory · both fsync first | 21k | 39k | Cassandra, 1.9× |
| Overwrite · larger than memory · both fsync later | 26k | 385k | Cassandra, 14.5× |
| New rows · both fsync first | 157k | 40k | PostgreSQL, 3.9× |
| New rows · both fsync later | 411k | 405k | level, within 5 % |
| Bulk load + settle · in memory | 1.53M | 545k | PostgreSQL, 2.8× |
| Bulk load + settle · larger than memory | 1.44M | 615k | PostgreSQL, 2.3× |
| Window across all devices · in memory | 147 ms | 890 ms | PostgreSQL, 6.1× |
| Window across all devices · larger than memory | 5.55 s | 3.33 s | Cassandra, 1.7× |
| Disk per row, table · in memory | 181 B | 96 B | Cassandra, 1.9× |
| Disk per row, table · larger than memory | 181 B | 97 B | Cassandra, 1.9× |
| p99 at 30k ops/s, 50/50 · in memory · defaults | 2.50 ms | 1.12 ms | Cassandra, 2.2× |
PostgreSQL leads on point read · in memory (3.2×); point read · larger than memory (1.5×); newest 100 readings · in memory (2.7×); overwrite · in memory · both fsync first (1.4×); new rows · both fsync first (3.9×); bulk load + settle · in memory (2.8×); bulk load + settle · larger than memory (2.3×); window across all devices · in memory (6.1×). Cassandra leads on overwrite · in memory · both fsync later (1.9×); overwrite · larger than memory · both fsync first (1.9×); overwrite · larger than memory · both fsync later (14.5×); window across all devices · larger than memory (1.7×); disk per row, table · in memory (1.9×); disk per row, table · larger than memory (1.9×); p99 at 30k ops/s, 50/50 · in memory · defaults (2.2×). Within 5 % of each other: new rows · both fsync later. The overwrite and new-row rows compare equal durability: both fsync before acknowledging, or both acknowledge first and fsync later. The defaults sit on opposite sides (PostgreSQL fsyncs first, Cassandra later), so a comparison at the defaults compares settings as much as databases; the 99th-percentile row is the one row at the defaults, because that is how each ships.
Reads: requests in flight decide the number
A closed loop keeps 16, 64 or 256 requests in flight: each sends the next request as soon as the previous answer arrives.
| Operation | Scale | Database | 16 in flight | 64 | 256 |
|---|---|---|---|---|---|
| Point read | in memory | PostgreSQL | 585k 568k–592k · p99 44 µs | 494k 480k–502k · p99 241 µs | 337k 327k–343k · p99 1.37 ms |
| Point read | in memory | Cassandra | 135k 132k–138k · p99 306 µs | 174k 170k–177k · p99 1.33 ms | 184k 178k–187k · p99 4.86 ms |
| Point read | larger than memory | PostgreSQL | 95k 11k–99k · p99 621 µs | 133k 23k–145k · p99 1.51 ms | 117k 12k–134k · p99 4.98 ms |
| Point read | larger than memory | Cassandra | 62k 8.2k–65k · p99 836 µs | 91k 64k–96k · p99 1.83 ms | 91k 65k–97k · p99 4.58 ms |
| Overwrite | in memory | PostgreSQL | 29k 26k–29k · p99 896 µs | 57k 12k–72k · p99 13.1 ms | 47k 18k–90k · p99 46.3 ms |
| Overwrite | in memory | Cassandra | 273k 227k–276k · p99 150 µs | 374k 325k–381k · p99 468 µs | 446k 366k–455k · p99 1.43 ms |
| Overwrite | larger than memory | PostgreSQL | 8.2k 5.6k–16k · p99 30.1 ms | 21k 2.8k–30k · p99 41.6 ms | 19k 10k–39k · p99 88.2 ms |
| Overwrite | larger than memory | Cassandra | 266k 233k–274k · p99 154 µs | 352k 249k–371k · p99 496 µs | 385k 341k–403k · p99 2.65 ms |
- In memory, a PostgreSQL point read is one B-tree descent and one heap page: 585k a second with 16 in flight, p50 26 µs, p99 44 µs. At 256 in flight it does 337k. Cassandra peaks at 184k with 256 in flight, 3.2× behind. At those peaks the database used 7.8 (PostgreSQL) and 8.0 (Cassandra) of its 8 hardware threads, the client 5.1 and 2.2 of its 8.
- Larger than memory, both read from the SSD, and the gap narrows: PostgreSQL 133k, Cassandra 91k a second at their best.
- A slice, the newest 100 readings of one device, is Cassandra’s model case: one partition, stored newest first. PostgreSQL returns 139k slices a second at its best, Cassandra 52k (13.85 M and 5.21 M rows a second). In PostgreSQL the 100 rows sit next to each other in the B-tree too.
Overwrites: durability first, then whether the page is in memory
An overwrite of a random existing row is where the two designs differ most, and where durability decides most of the number. Each database was measured at both of its settings on the same loaded data: PostgreSQL with synchronous_commit on and off per session, Cassandra restarted with commitlog_sync: batch.
| Best of 16 / 64 / 256 in flight | In memory | Larger than memory |
|---|---|---|
| PostgreSQL, fsync before the acknowledgement (default) | 57k | 21k |
Cassandra, fsync before the acknowledgement (batch) | 40k | 39k |
PostgreSQL, fsync later (synchronous_commit=off) | 231k | 26k |
| Cassandra, fsync later (default) | 446k | 385k |
- Both fsync first: PostgreSQL 57k and Cassandra 40k a second in memory; larger than memory 21k and 39k.
- Both fsync later: in memory PostgreSQL 231k, Cassandra 446k. Larger than memory PostgreSQL drops to 26k, 8.8× slower, because most pages it has to change are now on the SSD; Cassandra, which reads nothing, does 385k.
- The deferred work. Each overwrite test lasts 8 s, too short for either database to pay all of what it put off. Settling afterwards took PostgreSQL 4.71 s in memory and 37.7 s larger than memory (its checkpoint), and Cassandra 10.6 s and 6.71 s (flush and compactions), at the default settings.
- No request timed out in the 10 runs reported here. One earlier attempt at run 5, discarded and repeated, did time out: Cassandra, larger than memory, overwrites at 64 in flight with the default periodic commit log. 39 and then 37 of about 1.2 million requests hit the 2 s server write timeout, and the longest wait was 2.9 s. The tests were the same in that attempt; the repeated run had none.
- PostgreSQL logged “checkpoints are occurring too frequently” 445 times during the overwrite tests of all runs: at the default
max_wal_sizeof 1 GB, random overwrites fill the WAL in seconds, and the first change to each page after a checkpoint writes the whole 8 KB page into the WAL (a full-page image). A largermax_wal_size, a lowerfillfactor(room on the page for the new version) andsynchronous_commit=offper transaction are PostgreSQL’s usual levers for write-heavy tables; only the last was tested here.
A fixed rate: latency, half reads and half overwrites
An open loop schedules operations at a fixed rate, half point reads and half overwrites, and measures each from its scheduled time, so a server that falls behind is charged for the queue it causes. Both run at their defaults. A run kept up if it finished no more than 0.5 s behind the schedule.
| Scale | Rate | Database | p50 | p99 | p99.9 | Kept up |
|---|---|---|---|---|---|---|
| in memory | 10,000/s | PostgreSQL | 418 µs | 1.55 ms 1.53 ms–111 ms | 7.66 ms | 10/10 |
| in memory | 10,000/s | Cassandra | 540 µs | 1.19 ms 1.18 ms–12.8 ms | 21.7 ms | 10/10 |
| in memory | 30,000/s | PostgreSQL | 433 µs | 2.50 ms 1.13 ms–20,044 ms | 14.4 ms | 9/10 |
| in memory | 30,000/s | Cassandra | 100 µs | 1.12 ms 1.08 ms–5.08 ms | 17.6 ms | 10/10 |
| in memory | 60,000/s | PostgreSQL | 526 µs | 326 ms 19.8 ms–6,019 ms | 356 ms | 8/10 |
| in memory | 60,000/s | Cassandra | 92 µs | 896 µs 600 µs–10.1 ms | 15.8 ms | 10/10 |
| larger than memory | 10,000/s | PostgreSQL | 810 µs | 3.67 ms 2.94 ms–398 ms | 11.2 ms | 10/10 |
| larger than memory | 10,000/s | Cassandra | 360 µs | 1.97 ms 1.72 ms–1,056 ms | 12.4 ms | 10/10 |
| larger than memory | 30,000/s | PostgreSQL | 1,001 ms | 4,592 ms 15.7 ms–7,186 ms | 4,736 ms | 3/10 |
| larger than memory | 30,000/s | Cassandra | 162 µs | 7.64 ms 4.88 ms–13,635 ms | 18.4 ms | 9/10 |
At 30,000 operations a second in memory the medians are 433 µs (PostgreSQL) and 100 µs (Cassandra), and the 99th percentiles 2.50 ms and 1.12 ms. PostgreSQL’s 99th percentile varies widely from run to run: 1.13 ms to 20,044 ms at 30k, 19.8 ms to 6,019 ms at 60k, where it kept up in 8 of 10 runs. It logged 125 forced-checkpoint warnings during the mixed tests of all runs; which of them caused which stall was not isolated. Cassandra’s p99 stayed between 1.08 ms and 5.08 ms at 30k; its longest garbage-collection pause during a 30k test was 24 ms (median across runs), and its 99.9th percentile there was 17.6 ms.
Durability: what each setting acknowledges
Both databases offer a setting that fsyncs before acknowledging and one that fsyncs later. Their defaults sit on opposite sides:
| fsync before the acknowledgement | fsync later, in the background | |
|---|---|---|
| PostgreSQL | synchronous_commit=on · the default · commits waiting at the same moment share one WAL fsync | synchronous_commit=off · the WAL writer flushes every wal_writer_delay (200 ms) |
| Cassandra | commitlog_sync: batch · fsync, then acknowledge | commitlog_sync: periodic · the default · fsync every 10 s |
New rows go into an empty table for 8 s at 64 and 256 in flight. Then, on a fresh server, rows are written at 10,000 a second, the server is killed with SIGKILL about a second in, restarted, and every acknowledged row is read back.
| Setting | New rows/s, 64 in flight | 256 in flight | Acked rows lost to kill -9 | Kills with a loss | Lost per kill |
|---|---|---|---|---|---|
| PostgreSQL, fsync at commit (default) | 126k 13k–127k | 157k 151k–167k | 0 of 105,673 | 0/10 | 0–0 (median 0) |
| Cassandra, commit log batch (fsync first) | 40k 31k–42k | 40k 26k–41k | 0 of 100,747 | 0/10 | 0–0 (median 0) |
| PostgreSQL, synchronous_commit off | 411k 381k–415k | 305k 288k–318k | 14,876 of 106,422 | 10/10 | 128–2,090 (median 1,575) |
| Cassandra, commit log periodic (default) | 405k 353k–417k | 405k 389k–435k | 6,244 of 106,323 | 10/10 | 72–911 (median 746) |
- With an fsync before every acknowledgement, PostgreSQL writes 157k new rows a second and Cassandra 40k.
- With the fsync later, PostgreSQL writes 411k and Cassandra 405k.
- A process kill does not lose what the operating system already holds, so a setting can only lose what the process still had in its own memory. The two fsync-first settings lost nothing (0 and 0 acknowledged rows). PostgreSQL with
synchronous_commit=offlost 14,876 acknowledged rows over 10 kills, a median of 1,575 per kill; Cassandra’s default lost 6,244, a median of 746 per kill. At 10,000 rows a second that is about 158 ms and 75 ms of writes. - A power cut, which this does not test, can lose more: PostgreSQL’s documentation puts the worst case for
synchronous_commit=offat three timeswal_writer_delay, 600 ms of commits; Cassandra’s periodic mode can lose up to its 10 s sync period.
Bulk load, disk and a query across every partition
| Scale | Database | Bulk load, rows/s | Load + settle, rows/s | Disk per row, table | All files | Window query | PostgreSQL, 8 workers | One server-side statement |
|---|---|---|---|---|---|---|---|---|
| in memory | PostgreSQL | 2.54M 2.47M–2.70M | 1.53M | 181 B | 290 B | 223 ms 208 ms–229 ms | 147 ms | 311 ms |
| in memory | Cassandra | 1.03M 753k–1.15M | 545k | 96 B | 110 B | 890 ms 816 ms–1.06 s | – | 2.97 s |
| larger than memory | PostgreSQL | 1.54M 662k–2.48M | 1.44M | 181 B | 208 B | 8.88 s 7.12 s–10.2 s | 5.55 s | 17.4 s |
| larger than memory | Cassandra | 1.24M 614k–1.48M | 615k | 97 B | 104 B | 3.33 s 3.14 s–4.49 s | – | failed |
- Bulk load: PostgreSQL’s
COPYon 8 connections loads 2.54 M rows a second; Cassandra, through CQL in unlogged batches of 100 rows of one partition with 64 in flight, 1.03 M. Counting the settle afterwards (PostgreSQL 2.62 s, Cassandra 8.68 s in memory), that is 1.53 M and 545k. Cassandra’s own bulk path, SSTables written offline and streamed in withsstableloader, was not tested. - Disk: the table alone takes 96 bytes a row in Cassandra and 181 in PostgreSQL with its index. 84 bytes of each value cannot be compressed, so Cassandra’s figure is close to its floor: it writes the rows of one partition one after another and LZ4 shrinks the repeated key bytes. PostgreSQL adds 23 bytes of header and a 4-byte pointer to every row, stores the key again in the index, and fills pages only as far as rows fit. The WAL and the commit log add a fixed amount on top (the “all files” column), not an amount per row.
- A question across all partitions, how many readings fall into one 100-second window across all devices and the sum of one byte of each, is one SQL statement for PostgreSQL. Without an index on time alone it scans the table: 223 ms in memory and 8.88 s from the SSD with the default 2 parallel workers, 147 ms and 5.55 s with 8. In Cassandra the same question needs
ALLOW FILTERING, a full scan the documentation warns against. Split into 32 token ranges, 16 scanned at once and added up in the client (the way Spark and similar tools query Cassandra), it took 890 ms and 3.33 s. In every run each way of asking runs 3 times on a settled server and the median counts. As onecount(*) … ALLOW FILTERINGstatement Cassandra took 2.97 s in memory, and larger than memory it answered in 0 of 10 runs (6 hit the server’s 10 s range-read timeout, 4 ended with a read failure reported by the node itself).
When to pick which
- PostgreSQL when one machine can hold the data and the writes: it reads 3.2× faster in memory, answers any question in SQL, including ones across every partition, keeps transactions across rows and tables, and at its default it does not acknowledge what it has not fsynced.
- Cassandra when writes dominate and keep coming, when data grows past what one machine holds, or when no single node may be a point of failure. Acknowledging before the fsync, as both do at their fast setting, it overwrites random rows 15× faster than PostgreSQL once the data no longer fits in memory, and it stores a row in about half the bytes. Its real strength, adding nodes, is the part a one-node benchmark cannot show. Design every table for its query; a question across partitions works, as a client-side scan, but it is not what the model is for.
What the numbers say
- Durability moves a write number as much as the choice of database does: in memory, PostgreSQL overwrites 4.0× faster with the fsync later than with it first, Cassandra 11×.
- A Cassandra write never reads: at its default, its overwrite rate goes from 446k to 385k a second when the data outgrows memory. PostgreSQL’s, with the fsync also later, falls 8.8×, to the speed of fetching pages from the SSD.
- Reads by key are PostgreSQL’s: 3.2× in memory, 1.5× larger than memory, and 2.7× for a slice of one partition.
- Both put work off. 8-second tests do not show all of it; the settle times above are the bill.
What this does not show
- More than one node. Cassandra’s replication, tunable consistency and linear scale-out, and PostgreSQL’s streaming replicas, are not measured. On one node Cassandra still pays for machinery built for many.
- A power cut. kill -9 leaves the page cache intact; losing power does not. Only the fsync-first settings are safe against it.
- Tuning. Both run at defaults apart from memory. PostgreSQL’s
max_wal_size, checkpoints andfillfactor, Cassandra’scassandra_latest.yaml, compaction strategy (unified or leveled instead of size-tiered), heap and GC, and the drivers’ pools all move these numbers. - Long-running steady state. Each test lasts seconds. Hours of overwrites bring autovacuum and table bloat to PostgreSQL, and compaction backlog and tombstones to Cassandra.
- A dedicated disk. The SSD is shared with other workloads on this machine; a disk that is busy elsewhere shows up in the tails.
- Other shapes of data. Wide rows, secondary indexes, counters, collections, TTLs and lightweight transactions are not tested.
Reproduce it
The harness is one Go program with both drivers and a few shell scripts that start the client container and one database per configuration:
docker build -t cpb . # Go 1.26 build, runs a self-test of the payload checks
./net.sh 4-7,20-23 # client container, no network; the database joins its namespace
./db.sh cas-periodic 0-3,16-19 "" 16g # empty data dir, Cassandra with the default commit log, 16 GB limit
docker exec cp-net cp ready -db cas
docker exec cp-net cp load -db cas -devs 20000 -per 500
./settle.sh cas # flush, wait for compactions
docker exec cp-net cp get -db cas -devs 20000 -per 500 -c 64 -dur 8s
docker exec cp-net cp mix -db cas -devs 20000 -per 500 -rate 30000 -dur 10s
Each test prints one JSON line: operations, errors, mismatched values, the rate, the latency percentiles and each side’s CPU time; run.sh runs the full matrix and figs/ turns results.jsonl into the figures and tables above.