Skip to content

Strict serializability, and where it stops

Strict serializability orders committed transactions in real time. It does not make several of them one atomic operation, or give successive pages one snapshot. In fdyno, every item write and transaction API call is one FoundationDB transaction. That rules out lost updates and write skew. A paginated Query is not one transaction. If page 1 ends at sort key B and a writer then adds A and C, page 2 can return C and never A.

The guarantee in one paragraph

Serializable means the committed transactions have the same effect as if they ran one at a time, in some order. Strict adds real time: if A finished before B started, A comes first. So in the default read mode, a read that starts after a write returned sees that write, and no transaction sees half of another.

FoundationDB gets there with optimistic concurrency control. Each attempt reads at one read version and buffers its writes. At commit, FoundationDB compares the attempt's read-conflict ranges with the keys written by every transaction that committed after its read version. Any overlap rejects the commit. fdyno retries at a newer version while the request's context and budget allow. The consistency page lists which of fdyno's reads take part.

What it rules out

Two overlapping requests. Each reads at its own read version and buffers its writes. The first to commit wins. At the second commit, FoundationDB finds that a key or range it read was written after its read version. It rejects that commit. fdyno retries at a newer version, where the request sees the winner's write. Scenarios: lost update on a counter, claiming an absent key, a stale range read during an index build, and write skew between two items.

One rule covers all four scenarios: a conflict-checked read is a promise that the value will still be true at commit. A normal read, or an explicit read-conflict range, makes that promise. A snapshot read does not. FoundationDB refuses the commit when the promise is broken. fdyno's retry then re-runs the whole request, including the condition, at a newer snapshot. It never reuses an earlier condition result.

The protection covers only what the request reads. An invariant that spans items the request does not read is not protected. In DynamoDB terms, use ConditionCheck inside TransactWriteItems for it. It adds the other item to the read set.

Where it stops

Situation What happens What to use
Two requests Two transactions. Another write can land between them. TransactWriteItems or ExecuteTransaction for writes that must commit together
Query or Scan pages Each page is a new snapshot. LastEvaluatedKey is a key position, not a saved read version. BatchGetItem or TransactGetItems for one snapshot of a known set of keys; retrying UnprocessedKeys starts a new snapshot
BatchWriteItem Not atomic. A batch too large for one transaction commits in parts. A transaction API when all-or-nothing matters
A write whose reply is lost It may or may not have committed. Atomicity still holds. The retry rules below

Pagination is the edge people hit first. One page is one snapshot. Following LastEvaluatedKey is a new request with a new snapshot.

An ascending Query ends page 1 at sort key B. A writer then inserts A and C. Page 2 starts after B with a fresh snapshot: it can include C, but it does not go back for A.

Page 2 starts after B in a fresh snapshot, so it can include C but never goes back for A (consistency page). ConsistentRead=true does not change that. DynamoDB behaves the same way.

When the reply is lost

FoundationDB returns commit_unknown_result when it cannot tell whether a commit applied. A network cut can do the same to the HTTP reply. Isolation and atomicity still hold: all of the write applied, or none of it. The client does not know which.

A blind retry of SET n = n + 1 can then apply twice: two valid transactions, one wrong API result. fdyno closes this gap by not retrying such a write. After an unknown commit, it retries only a tokened transaction. Every other write returns HTTP 500 transaction outcome may be unknown (fdyno's own retries). Pre-v0.1 builds wrote an extra record in the same transaction as the effect. A guard protects only a commit that conflicts on it walks through that schedule.

That 500 means the write applied once or not at all. A new HTTP request, including an SDK's automatic retry, can apply it again.

The request budget (DYNODB_OPERATION_TIMEOUT, 30 s by default) can run out after a commit attempt. Then fdyno answers HTTP 500 with transaction outcome may be unknown, and the SDK's retry is a new request. Some client resends must not apply twice. For them, use TransactWriteItems or ExecuteTransaction with a stable ClientRequestToken. A resend with the same live token applies at most once. The retry rules list which other writes are safe to repeat.

What it costs

  • No service without a quorum. A part of the system cannot commit when it cannot reach the FoundationDB quorum it needs. fdyno returns errors rather than serve a stale copy.
  • Contention becomes retries. Two writers on one hot item conflict. fdyno queues same-item writes within a process. Different processes still conflict and retry, and a retry loop can run into the request deadline (hot items).
  • Every transaction has limits. It must fit FoundationDB's size and time limits, including index and stream data.

How we checked it on a real cluster

The guarantee comes from FoundationDB. The question for fdyno is whether its request mapping keeps it under faults. The EC2 concurrent-history campaign tested that on a FoundationDB 7.3.51 cluster across three Availability Zones.

Campaign detail Recorded scope
Workloads list-append and register, checked by Elle for strict serializability; register also by Knossos for per-key linearizability; bank, checked for a constant snapshot total and non-negative balances
Histories Three seeds × three workloads; all nine valid; about 100,000 operations and one hour each
Faults Kill and pause of fdyno and FoundationDB; minority, majority-ring and whole-AZ partitions of FoundationDB traffic; ±30 s clock steps on API hosts. 60 s hold, then 90 s between cycles
Controls A split read, a dropped write and a dropped credit each made the matching check fail
Limits One Region, FoundationDB ports only, API-host clocks only, one hour per history

The bank workload is an invariant check, not a strict-serializability proof. A 503 from the in-flight request limit or the cluster version check counted as a definite failure, because no read or write began. That was a pre-v0.1 build: in v0.1, the in-flight request limit answers 400 ThrottlingException instead. Other server errors, timeouts and resets counted as indeterminate. A passing history shows that no anomaly appeared in what was observed, not that none can.

What to do with this

List the places where work in your API spans more than one transaction. Also list the places where the client may not see an outcome. Examples are paginated reads, batch chunks, internal retries after an unknown result, and client resends. Each is an edge of your consistency guarantee.

Document each one next to the API. Write the idempotency record for internal retries in the same transaction as the effect. Give clients a token for resends that must not apply twice.