Serializable isolation

Also known as: serializable

On this page 7

Serializable isolation is the strictest isolation level defined by the SQL standard, guaranteeing that the outcome of concurrently executing transactions is equivalent to the outcome of running them one after another in some serial order. In databases, it is the only level that rules out every concurrency anomaly, including phantoms and write skew.

In the study of transactions, serializable isolation represents the full meaning of the I in ACID. Weaker levels trade correctness for throughput, while serializable execution lets developers reason about each transaction as if it ran alone, at the price of blocking or aborted transactions under contention.

What the serializability guarantee means

A schedule of interleaved operations is serializable when its effects on data and on returned results match at least one serial schedule of the same transactions. The guarantee does not specify which serial order applies, only that one exists, so two concurrent transfers may appear in either order.

Theory distinguishes conflict serializability, checked by building a precedence graph of conflicting reads and writes, from the broader view serializability. Practical engines enforce conflict serializability because it can be verified incrementally. A cycle in the precedence graph means no equivalent serial order exists, and one transaction must be blocked or aborted.

Serializability is distinct from linearizability, which concerns single objects and real-time order. A system offering both properties is said to provide strict serializability, a guarantee that matters for distributed databases spanning several nodes.

Anomalies prevented at each isolation level

The easiest way to understand serializable isolation is to compare which read and write anomalies each level permits. The following table reflects the SQL standard together with commonly observed behavior in modern engines.

Isolation levelDirty readNon-repeatable readPhantom readWrite skew
Read uncommittedPossiblePossiblePossiblePossible
Read committedPreventedPossiblePossiblePossible
Repeatable readPreventedPreventedEngine-dependentPossible
Snapshot isolationPreventedPreventedPreventedPossible
SerializablePreventedPreventedPreventedPrevented
Anomalies permitted by isolation level

Write skew is the anomaly that most often separates snapshot isolation from true serializability. Two transactions read an overlapping set of rows, each verifies an invariant, and each updates a different row. Neither sees the other’s write, so the invariant breaks even though no single row was modified twice.

How engines implement serializable execution

Database engines enforce serializability with one of three broad strategies. Each produces the same logical guarantee but behaves very differently under contention, long transactions and read-heavy workloads.

StrategyMechanismTypical behavior under conflictRepresentative systems
Strict two-phase lockingShared and exclusive locks held to commit, plus range or predicate locksWaiting and possible deadlocksSQL Server, MySQL InnoDB, Db2
Serializable snapshot isolationSnapshot reads plus tracking of read-write dependenciesAborts with a serialization failurePostgreSQL, CockroachDB
Actual serial executionSingle-threaded execution of short stored proceduresQueuing rather than conflictVoltDB, Redis scripts
Timestamp orderingOperations validated against transaction timestampsRestarts of late transactionsSpanner-style and research systems
Implementation strategies for serializable isolation

Serializable snapshot isolation (SSI) is now the dominant approach in MVCC engines. Readers never block writers; instead, the engine detects dangerous structures of rw-antidependencies and aborts one participant. PostgreSQL reports such aborts with SQLSTATE 40001, and the application must retry the whole transaction.

Using serializable isolation in applications

Serializable isolation is set per transaction or per session, for example with SET TRANSACTION ISOLATION LEVEL SERIALIZABLE. The decisive design rule is that every serializable transaction must be retryable, because both locking and optimistic engines may cancel it to preserve correctness.

  • Wrap transactions in a retry loop that catches serialization failures and deadlock errors, usually with exponential backoff.
  • Keep transactions short, since long transactions widen the window for conflicts and hold locks longer.
  • Avoid external side effects such as sending email inside the transaction, because a retry would repeat them.
  • Declare read-only transactions where possible, which lets some engines skip dependency tracking.
  • Index the predicates used in searches, because predicate locks on unindexed columns can escalate to whole tables.

The table below helps decide when the strictest level is justified and when a weaker level with targeted locking is the better engineering choice.

WorkloadRecommended levelReason
Financial ledgers with cross-row invariantsSerializablePrevents write skew on balances and limits
Scheduling with capacity rulesSerializableChecks across rows stay valid
High-volume reporting readsSnapshot or read committedConsistency without abort overhead
Simple single-row updatesRead committedRow locks already prevent lost updates
Hot counters under heavy contentionRead committed with explicit lockingAvoids frequent serialization failures
When to choose serializable isolation

Costs, limits and misconceptions

The main cost of serializable isolation is lower concurrency. Locking engines suffer from waits and deadlocks, while optimistic engines suffer from abort rates that grow with contention. Throughput loss ranges from negligible on low-conflict workloads to severe on hot rows, so benchmarks with realistic data are essential.

A frequent misconception is that a level named REPEATABLE READ or SERIALIZABLE behaves identically across products. Older Oracle releases, for instance, label snapshot isolation as serializable, which still allows write skew. Teams should verify the actual guarantee rather than relying on the name of the setting.

Another limit concerns scope. Serializable isolation protects only operations inside a single database transaction. Workflows that span several requests, message queues or separate services still need application-level safeguards such as idempotency keys, version columns or distributed transaction protocols, because no isolation level can serialize work the database never sees as one unit.

The idea in brief

Serializable isolation makes a busy database behave as if people took turns. Many customers may act at the same moment, but the final result always looks like each action happened in a neat queue, one after another.

When two actions would clash in a way no orderly queue could explain, the database cancels one of them and asks the application to try again. The benefit is that business rules never break silently, even under heavy traffic.

A practical scenario

A hospital scheduling system enforces a rule that at least one doctor stays on call for each ward overnight. Two doctors, both currently on call, open the app at the same minute and request leave. Under snapshot isolation, each transaction counts two doctors on call, approves the request and updates a different row, leaving the ward with nobody.

After the incident, the team switched the leave transaction to serializable isolation in PostgreSQL and added a retry loop with up to three attempts. When the same situation recurred, the engine detected the read-write dependency, committed the first request and returned a serialization failure for the second.

On retry, the second transaction saw only one doctor on call and rejected the leave request. The extra cost was a few milliseconds per conflicting request, and the on-call coverage rule held throughout the following year.