AlgoViz

Database internals on the critical path

hard 7 min

Many storage engines persist a description of a change before relying on the changed data pages.

Video lesson · Chapter 1 of 4

Commits stall while reads remain fast

0:00 / 2:10

Theory

Read or listen first. About 2 min.

What it is

Many storage engines persist a description of a change before relying on the changed data pages. With synchronous commit settings, acknowledgment waits for the configured durability condition. Group commit can amortize a flush over several transactions. Cached reads may remain fast while durable writes queue behind slow flushes.

Why it exists

An order service shows slow commits but normal indexed lookups. Split transaction time into lock wait, execution and commit. Correlate commit delay with WAL flush latency and competing device I/O. Disabling durability changes what a successful order means. Prefer reducing contention or batching compatible work while keeping the agreed acknowledgment guarantee.

If the application waits before commit starts, measure row locks, pool leases or query execution before changing storage.

Commits stall while reads remain fast

Transaction → WAL buffer (append record). WAL buffer → Durable storage (flush commit)
Transaction → WAL buffer (append record). WAL buffer → Durable storage (flush commit)

Inside this chapter

B-tree indexes and range reads
Balanced-tree indexes keep keys ordered and support selective lookups and ranges. PostgreSQL’s default B-tree is an implementation choice. SQL itself does not prescribe an index structure.
LSM Trees (Write-optimized, Cassandra/RocksDB)
An LSM engine buffers writes, flushes immutable runs and merges them over time. Compaction backlog can raise read amplification and eventually constrain writes.
Write-Ahead Logs (WAL) and durability
Write-ahead logging requires log records to reach the necessary durability boundary before related data-page changes can safely stand on their own. Recovery replays the log.
Bloom Filters for read efficiency
A Bloom filter can skip a run when a key is definitely absent under the filter’s assumptions. A positive result still requires checking the actual data.
MVCC (Multi-Version Concurrency Control)
MVCC stores or reconstructs multiple versions so a reader can view its snapshot. Old transactions can delay version reclamation and increase storage pressure.
Index Types: B+Tree, Hash, GIN, GiST
Ordered, hash, inverted and generalized indexes support different predicates and operators. Inspect the query plan and workload before accepting index storage and write costs.
Connection Pooling (PgBouncer, ProxySQL)
A connection pool multiplexes clients onto a bounded backend set. Pool mode influences session state. Count lease waiting separately from SQL execution time.

How it works

Step through the idea, or press Play.

Step 1 of 4

Modify state. A transaction generates a log record describing a change.

Understand it

Worked incident

Commits stall while reads remain fast

ObservationCommit flush p95 (ms)Interpretation
Baseline3WAL flushes complete promptly.
Incident84A competing sequential job stretches sync latency.
After intervention5Isolate or pace the competing work and verify commit acknowledgment under the same durability setting.
Illustrative measurements from the same workload at three checkpoints.

Choose the next investigation

If the application waits before commit starts, measure row locks, pool leases or query execution before changing storage.

Summary

The whole topic in one minute.

Acknowledging earlier can expose successful recent transactions to loss in a crash. Latency and durability describe different promises.

If the application waits before commit starts, measure row locks, pool leases or query execution before changing storage.

Sources