What does each engine do when the same thing happens to it?
I keep coming back to four events when I compare engines, because each one exposes how an engine is built. Four everyday events: a write, a crash, a lagging replica, and a long transaction. For each, the three engines side by side, with the file names, the order of events, and a command to see it yourself.
Every engine on this site does the same four things in the same order: a client connects, the change lands in memory, the log records it first, and the data files catch up later. The three pictures are drawn the same way on purpose, so the comparison lands. The names inside them are the real file and memory names. The log box is the one that matters: COMMIT returns only after the log is on disk.
Follow one insert through these boxes, and watch it cross each one: Follow one insert, end to end →
The same INSERT in all three engines. Each one writes the log first and the data file later. They differ in how many logs there are and in what "acknowledged" means.
One commit, in four steps
Solid boxes happen before COMMIT returns. The dashed box happens later, on the engine's own schedule: the checkpointer in PostgreSQL, page cleaners through the doublewrite files in MySQL, a checkpoint about every 60 seconds in MongoDB.
Watch one commit happen
Pick an engine, then press Play or step through it. The dot is your change.
SHOW synchronous_commit; SELECT pg_current_wal_lsn(); -- run an INSERT, then the line above again. -- The position moved.
The priceAn UPDATE writes a whole new row version. The old one stays in the page until VACUUM removes it.
SHOW VARIABLES LIKE 'innodb_flush_log_at_trx_commit'; SHOW VARIABLES LIKE 'sync_binlog'; -- both 1 is the fully durable setting
The priceTwo logs mean two syncs per commit. Group commit shares them across concurrent transactions, which is why the cost is smaller than it sounds.
rs.conf().writeConcernMajorityJournalDefault
db.getSiblingDB('local').oplog.rs.find().sort({$natural: -1}).limit(1)The priceA write acknowledged at w: 1 but not yet replicated can be rolled back if the primary fails.
All three write the log first. The real difference is what the client was told, and when. Check the write concern or the commit setting before you trust an acknowledgment.
Measured: Notebook 2 times the durable setting against the fast one. Go deeper: follow one insert, end to end, or what a commit waits for.
A power cut or a kill -9. Memory is gone. What survives is the log and whatever the last checkpoint wrote. The restart is the log being replayed.
What a restart replays
The same idea in all three engines: start from the last checkpoint, replay the log, discard what never committed.
-- in the server log after a crash: -- database system was not properly shut down; automatic recovery in progress -- redo starts at ... -- redo done at ...
The priceRecovery time follows how much WAL sits after the last checkpoint. That is set by checkpoint_timeout and max_wal_size.
-- in the error log after a crash: -- InnoDB: Starting crash recovery. -- InnoDB: Applying a batch of ... redo log records
The priceRolling back one huge in-flight transaction can take a long time. A crash does not hide that cost. It moves it to startup.
rs.status().members.map(m => m.name + ' ' + m.stateStr)
The priceA write that only the old primary had acknowledged at w: 1 is the one that gets rolled back.
Recovery is the same idea three times: start from the last known good point, replay the log, and discard what never committed. What differs is where the unfinished work goes, and how much log you have to replay.
Try it: break a database in the crash lab.
Lag is a queue. Changes arrive faster than the replica applies them. Each engine has a different place where that queue builds up.
Usually the replica applying it. Shipping a log record takes milliseconds; the replica replaying it can wait behind a long query, a huge transaction or a single busy apply thread. Tick the box in the widget to see each engine's version.
-- on the primary SELECT client_addr, state, write_lag, flush_lag, replay_lag FROM pg_stat_replication; -- on the standby SELECT now() - pg_last_xact_replay_timestamp();
The priceThe standby holds WAL the primary cannot recycle if a replication slot is tied to it, so a stuck replica can fill the primary disk.
SHOW REPLICA STATUS\G -- read Seconds_Behind_Source, Replica_IO_Running, -- Replica_SQL_Running. Treat the seconds as a hint.
The priceThe binlog on the source must be kept long enough for a slow replica to catch up, or the replica needs a rebuild.
rs.printSecondaryReplicationInfo() rs.printReplicationInfo() // the oplog window
The priceSize the oplog for the longest outage you want a secondary to survive, not for the average day.
Lag is write rate minus apply rate, accumulated over time. Whatever the engine, the question is the same: what is the apply rate, and what is the limit on how far behind the log is kept?
Nothing is wrong with the transaction itself. The cost is everything the database must keep so that its snapshot still makes sense.
SELECT pid, state, now() - xact_start AS age FROM pg_stat_activity WHERE xact_start IS NOT NULL ORDER BY age DESC LIMIT 5;
The priceSet idle_in_transaction_session_timeout so a forgotten session cannot hold the cleanup back for hours.
SELECT trx_id, trx_started, trx_rows_modified FROM information_schema.innodb_trx ORDER BY trx_started LIMIT 5; SHOW ENGINE INNODB STATUS\G -- History list length
The priceUndo tablespaces are truncated only once they pass innodb_max_undo_log_size and purge has caught up, so the extra space can linger after the transaction ends.
db.currentOp({ active: true, secs_running: { $gt: 60 } })The priceMongoDB limits the problem with a hard timeout. The other two let it grow until you notice.
A long transaction is a debt: the database has to remember the past for as long as the transaction is open. PostgreSQL shows it as bloat, MySQL as undo, and MongoDB as cache pressure.
Measured: Notebook 1 runs this on all three engines. Related: the MVCC timeline lab shows why the snapshot is taken at the first query, not at BEGIN.
Most designs on this site put one of these next to the main database. Same questions as above, shorter answers; each has a full page.
| Redis | Cassandra | Vector search | |
|---|---|---|---|
| Where the data lives | Memory. Snapshots and the AOF only for restarts | Commit log, memtables, immutable SSTables | Vectors plus an index (HNSW or IVF), usually in memory |
| What COMMIT waits for | Memory only. appendfsync decides when the disk follows | The commit log write on enough replicas for the consistency level | Whatever the host database waits for: in pgvector, the WAL |
| Replication | Asynchronous; WAIT narrows the window | Every node equal; consistency chosen per query | From the host database, or the vector service's own |
| Queries it answers | By key, with commands per data type | By partition key, then clustering order | Nearest neighbours, approximate, plus filters |
| What breaks first | Big keys, hot keys, memory full, forks | Huge partitions, tombstones, skipped repair | Index outgrows memory, filtered search returns too few rows |
| Measured here | ZINCRBY 0.080 ms a round trip | One-partition read 3.3 ms | Recall 0.95 at ef_search 40, 0.65 ms |
Measured in Notebook 7 for Redis and Cassandra, and Notebook 8 for vector search. The transcripts are on the Notebooks page.
A new service does 2,000 small writes a second and must lose nothing on failover. In each engine, which settings make "lose nothing" true?
Write your answer down first. Then open mine.
PostgreSQL: synchronous_commit = on (the default) plus a synchronous standby in synchronous_standby_names, and a failover tool that only promotes a synchronous standby, such as Patroni in synchronous mode.
MySQL: innodb_flush_log_at_trx_commit = 1 and sync_binlog = 1, plus semi-synchronous replication with AFTER_SYNC, or Group Replication.
MongoDB: write concern w: "majority", the default since 5.0, with journaling.
The catch: in Notebook 2, one client doing fully durable commits managed about 4,200 a second on PostgreSQL, 1,770 on MySQL and about 1,100 on MongoDB. That run used one client and 2,000 commits per setting, run 2026-11-18; the numbers belong to that runner, not to your server. 2,000 a second needs several connections committing at once, so the engine can flush many commits together.
Pick an answer. You will see whether it is right, and why.
1. After a crash, where does recovery start?
The data files are correct as of the checkpoint. The log after it holds everything committed since.
2. In Notebook 6, 1,600 attempts tried to buy an item with 1,000 in stock by reading the stock and then writing the new value. How many sold?
All three engines oversold. A conditional update, WHERE available >= 1, sold exactly 1,000.
3. Which MySQL setting trades a short window of acknowledged commits for speed?
With 1, every commit flushes the redo log. With 0 or 2, the flush happens about once a second.
How do databases actually work? From one row on disk to transactions: the words you need, PostgreSQL, MySQL and MongoDB from the files up, then Redis, Cassandra and vector search, side by side, and the query and concurrency traps.