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.
Concepts covered
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
Modify page
The change lands in the buffer pool
In-memory only at this point - the data file still holds the old page
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
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
Checkpoint (later)
Dirty data pages written to the data files
Lazily, in the background - a crash before this is fine, the log replays
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
WRITELOGwaits. 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
WRITELOGis 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.
- Build the target table. In a scratch database, create
dbo.eventswith anIDENTITYkey 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. - Run commit-per-row. Time a loop that inserts a thousand rows, each in its own transaction -
a
WHILEloop ofBEGIN TRAN; INSERT; COMMIT- and record how long it takes. Check: a thousand commits means a thousand log flushes - a thousandWRITELOGwaits 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. - 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.
- 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. - 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 = ALLOWEDon the database withCOMMIT ... WITH (DELAYED_DURABILITY = ON)on the specific transactions - neverFORCED, which delays every commit including the ones that should not be. If you choseFORCED, revisit the honesty table: the blast radius stays where you put it only underALLOWED.
Check your understanding
Ordered easy to hard. Answer each before reading the answer; a wrong answer names where to look.
- 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. - Why is
WRITELOGa 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. WhenWRITELOGtops 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. - 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.
- An ever-increasing
IDENTITYkey 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 -PAGELATCHon the hot page, notPAGEIOLATCH, because the page is already in memory. It is a concurrency problem, not storage; the write shape you choose determines the contention you get. - What exactly does delayed durability risk, and how do
ALLOWEDandFORCEDdiffer 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.ALLOWEDlets you mark only the transactions that tolerate it;FORCEDdelays 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