Blog
AdvancedReferenceSQL Server Performance Internals

The write path and what a commit costs

What INSERT, UPDATE, and DELETE actually do - the write-ahead log first, the data pages at checkpoint - why COMMIT waits on WRITELOG, how batching amortises the flush, and when delayed durability is an honest trade.

Applies to
SQL Server2016-2025 (13.x-17.x)delayed durability exists from 2014 (12.x)
matureUpdated Reviewed
advancedAssumes production experience with the basics.

What you will be able to do

  • Describe the write-ahead-log contract and why COMMIT's latency is a storage property, not a query property.
  • Explain why one transaction of a thousand rows commits far faster than a thousand single-row transactions.
  • State exactly what delayed durability trades - last-moment commits can be lost - and the workload it suits.
  • Predict how UPDATE and DELETE differ from INSERT in the log and the lock space they occupy.

A committed write is durable because the log says so, not because the data file does. That single fact - write-ahead logging - is the entire cost model of the write path. Everything else in this lesson is a consequence of it.

The analogy is a despatch office where the rule is signature first, loading second. No parcel counts as sent until the duty manager has signed the manifest - the log flush - while the van is loaded and the bay swept out later, at leisure, because the signed manifest is enough to reconstruct the day’s work after a disaster. A clerk who demands a signature for every single envelope spends the day at the desk; one manifest covering a whole van-load pays the signature once. Commit latency is the speed of the manager’s pen, not the speed of the loaders.

The contract: log first, data later

When a transaction modifies a row, the engine writes a log record describing the change and dirties the data page in memory. On COMMIT, the log records up to the commit are hardened to the log device, and only then does commit return success. The dirty data pages flush to the data files lazily, at checkpoint.

One transaction from change to durable

  1. Modify page

    The change lands in the buffer pool

    In-memory only at this point - the data file still holds the old page

  2. Write log record

    A description of the change in the log buffer

    Sequential write - the log is an append-only stream, which is why it is fast

  3. COMMIT - flush log

    Log hardened to the log device; WRITELOG wait paid here

    Commit cannot return faster than this flush - this is the durability contract

  4. Checkpoint (later)

    Dirty data pages written to the data files

    Lazily, in the background - a crash before this is fine, the log replays

Durability is bought at the log flush, not at the data write - which is why the log device, not the data device, bounds commit latency.

Two properties follow. First, the log write is sequential append - the cheapest possible disk pattern, because there is no seeking. Second, COMMIT latency is a storage property of the log device, not a CPU property of the engine. When WRITELOG tops the wait profile, the diagnosis is “the log device cannot flush fast enough,” and no index tuning changes it.

Why batching wins - it amortises the flush

Every COMMIT pays one log flush. So:

  • A thousand single-row transactions = a thousand log flushes = a thousand WRITELOG waits. Write latency is bounded below by device flush latency × 1000.
  • One transaction of a thousand rows = one log flush. The log writes are slightly larger but still sequential, and the flush is paid once.

This is why micro-batching - grouping many writes per commit - is the highest-leverage write optimisation there is, and why “commit per row” loops are the most common write-side mistake. The throughput difference is not incremental; it is the difference between one flush per row and one flush per batch.

INSERT, UPDATE, DELETE - not symmetric

Operation In the log The contention it causes
INSERT Log the new row (and page split records if the key lands mid-page) On an ever-increasing key, every insert targets the last page - a latch hotspot under concurrency
UPDATE Log the before/after; an in-place change on a non-key column, a delete+insert on a key column Holds the row lock for the transaction duration; updating a key column is a move, not an edit
DELETE Log the delete; the row becomes a ghost record cleaned up later Same row locks as UPDATE; mass deletes are where lock escalation (next lesson) bites

The page-split and last-page details matter: an ever-increasing IDENTITY or datetime key sends every concurrent insert to the same physical last page, which serialises them on a buffer latch - PAGELATCH on the hot page, not I/O. That is a concurrency problem, covered with latches; the point here is that the write shape you choose determines the contention you get.

Delayed durability - the honest trade

From SQL Server 2014, a commit can be made delayed durable: the commit returns before the log record is hardened. The log flushes lazily, batched with other commits, so write latency drops and throughput climbs - exactly the batching benefit, without changing the application.

The price is stated plainly, not hedged: a delayed-durable commit acknowledged to the client can be lost if the system crashes before the log flushes. The window is small, but it is real - durability is traded for latency.

Mode Setting When it is honest
Fully durable DELAYED_DURABILITY = DISABLED (default) Financial, audit, anything where a lost acknowledged commit is a correctness failure
Delayed ALLOWED, then COMMIT ... WITH (DELAYED_DURABILITY = ON) per transaction, or FORCED for all High-throughput append workloads that tolerate a tiny loss window - telemetry, log-style ingest

FORCED is the dangerous one - it makes every commit delayed, including the ones that should not be. Use ALLOWED and mark the specific transactions; the blast radius stays where you put it.

What this means in practice

  • When WRITELOG is your top wait, the levers are: faster log storage, fewer and larger commits, or delayed durability - in roughly that order of honesty.
  • Never put the transaction log on storage shared with data or tempdb if you care about commit latency; sequential log writes and random data I/O fight for the same device.
  • The log file itself wants a single, pre-grown, right-sized file on its own fast device - growth events are blocking pauses on the write path, and VLF fragmentation from many small growths slows the flush itself.

Guided practice

A beginner exercise, worked in a scratch database. The scenario: prove the lesson’s central claim - that batching amortises the log flush - by measuring commit-per-row against one transaction. Work each step and check yourself before moving on.

  1. Build the target table. In a scratch database, create dbo.events with an IDENTITY key and a couple of payload columns. Check: the table is empty and ordinary - no tricks. The measurement only means something if the two runs write the same rows.
  2. Run commit-per-row. Time a loop that inserts a thousand rows, each in its own transaction - a WHILE loop of BEGIN TRAN; INSERT; COMMIT - and record how long it takes. Check: a thousand commits means a thousand log flushes - a thousand WRITELOG waits paid one by one. If you forgot the transaction wrapper, the implicit-commit behaviour is the same thing; the point is one flush per row.
  3. Run the same writes as one transaction. Truncate the table, then time a single transaction that inserts the same thousand rows. Check: the batched run finishes far faster - one log flush instead of a thousand, with the log writes still sequential. If the times were similar on your machine, the reason still stands from the write-path diagram: commit cannot return faster than its flush, and the flush is paid once per commit.
  4. Connect it to a wait. Which wait type did the slow run spend its time on? Check: WRITELOG - commit latency is a storage property of the log device, not a CPU property. If you answered CPU, revisit the contract: the engine was idle, waiting on the flush, and no index tuning changes a storage wait.
  5. Judge the delayed-durability option. If this insert loop were a telemetry feed that tolerates losing the last moments of acknowledged commits, which setting would you use, and which would you avoid? Check: DELAYED_DURABILITY = ALLOWED on the database with COMMIT ... WITH (DELAYED_DURABILITY = ON) on the specific transactions - never FORCED, which delays every commit including the ones that should not be. If you chose FORCED, revisit the honesty table: the blast radius stays where you put it only under ALLOWED.

Check your understanding

Ordered easy to hard. Answer each before reading the answer; a wrong answer names where to look.

  1. What makes a committed write durable - the data file or the log? The log. On COMMIT, the log records up to the commit are hardened to the log device; the dirty data pages flush lazily at checkpoint. A crash before checkpoint is fine because the log replays - durability is bought at the log flush, not the data write.
  2. Why is WRITELOG a storage problem rather than an engine problem? Commit cannot return faster than the log flush, so the wait is the log device’s latency, not the CPU’s or the plan’s. When WRITELOG tops the profile, the diagnosis is “the log device cannot flush fast enough” - faster log storage, fewer and larger commits, or delayed durability are the levers, in that order of honesty.
  3. Why does one transaction of a thousand rows commit far faster than a thousand single-row transactions? Every commit pays one flush; batching pays it once. The batched log writes are slightly larger but still sequential - the cheapest disk pattern there is - so the difference is one flush per batch versus one flush per row. If you attributed it to “overhead” generally, revisit the amortisation argument - the cost is specifically the flush.
  4. An ever-increasing IDENTITY key hurts concurrent inserts even though inserts only append. Why, and which wait shows it? Every insert targets the same physical last page of the index, so concurrent inserters serialise on a buffer latch - PAGELATCH on the hot page, not PAGEIOLATCH, because the page is already in memory. It is a concurrency problem, not storage; the write shape you choose determines the contention you get.
  5. What exactly does delayed durability risk, and how do ALLOWED and FORCED differ in blast radius? A delayed-durable commit acknowledged to the client can be lost if the system crashes before the log flushes - the window is small but real. ALLOWED lets you mark only the transactions that tolerate it; FORCED delays every commit including the ones that should not be. If you could not state the trade without hedging, reread the durability section - the price is stated plainly for a reason.

Where SQL Server sits

How this component relates to the rest of the stack. Items without a link are not covered here yet.

Deployed with

Commonly run alongside

  • Windows Failover Clustering

Alternatives

Solves a similar problem differently