Writes¶
Most requests use one atomic, strictly serializable FoundationDB transaction.
A write can commit even when its client sees a timeout or loses the response.
For client retries that must apply once, use TransactWriteItems with a stable
ClientRequestToken.
With a configured client and an Orders table:
client.transact_write_items(
ClientRequestToken="order-018f6b8d",
TransactItems=[{
"Put": {
"TableName": "Orders",
"Item": {"pk": {"S": "order-42"}, "status": {"S": "created"}},
"ConditionExpression": "attribute_not_exists(pk)",
}
}],
)
Transaction APIs¶
See the action and size limits.
A write reads the metadata and the item at one snapshot. It checks its condition and builds the new item. Then it commits these together: the item and its chunks, the deletion of old index entries, the new index entries and the stream record. A reader sees all effects or none. A failed condition writes nothing. Read-only calls finish after their snapshot reads, without a commit.
| API | Transactions | Notes |
|---|---|---|
PutItem, Update, Delete |
One | Condition, item, LSI entries, GSI change records and stream record. |
Transact |
One | Up to 100 Put, Update, Delete and Condition actions, across tables, plus the token record. |
Transact |
One read | Up to 100 items, across tables, at one read version. |
Execute |
One | Up to 100 PartiQL statements, all reads or all writes. Write transactions accept a token. |
GetItem, Batch |
One read | A batch reads every key at one read version. |
Query, Scan |
One read per page | Each page is a new snapshot. |
Batch |
One, or several if too large | Not atomic. |
TransactWriteItems validates the request before it checks for a live token.
Then, if the request has no token or no live token record exists, fdyno checks
for duplicate targets. It evaluates the stored-item conditions in the same
transaction. Reads can start early, so this is the order of the checks, not of
the reads.
A cancelled transaction writes nothing. TransactionCanceledException
contains one reason per action, in request order. Some transaction Update
actions fail on the stored item, such as arithmetic on a string or a missing
parent map. Each returns ValidationError at that action's position, also
when the condition of another action failed. An Update whose result is over
the item size limit does the same. Invalid expression syntax or input types
still return a request-level ValidationException. fdyno retries conflicts
within the request time budget. If conflicts use up the budget, the
transaction is canceled with reason TransactionConflict.
What a failed TransactWriteItems returns¶
A failure returns either a request-level error or a
TransactionCanceledException with one CancellationReasons entry per action,
in request order. Neither writes anything, except that an InternalServerError
during a commit may leave the outcome unknown (see the last row).
| Step | Check | Outcome |
|---|---|---|
| 1 | Validate the request | Invalid: Validation (whole request) |
| 2 | Token running on this process, if one is supplied | Another request with the token is still running on this fdyno process: Transaction (whole request), nothing written |
| 3 | Same-item queue | Refused: Provisioned (whole request) |
| 4 | Check the token, if one is supplied | A live token with the same request parameters: replay (HTTP 200), nothing written. A live token with changed parameters: Idempotent |
| 5 | Two actions on one item | Found: Validation (whole request) |
| 6 | Plan each action | First invalid action: Validation at i, the rest None |
| 7 | Read the items, check every condition | Each failing action: Conditional at i |
| 8 | Apply the actions | First action that fails on the stored item: Validation at i |
| 9 | Write the token record (with a token), commit |
The same-item queue step runs only when the same-item
queue is on and the
request has no more items than its multi-key bound. The token, planning,
condition and apply steps stop at the first request-level error or
cancellation. They run again on each retry attempt, in the same transaction
as the commit. The apply step has its own request-level errors: an empty index
key value, an invalid finished Update item and a Put item over 48,000 bytes.
These come after the condition step. So if a condition in the same request
fails, the request returns the cancellation instead.
| Failure | Response |
|---|---|
Too many actions, not exactly one action kind per entry, a Client over 36 bytes, a payload over 4 MiB (4,194,304 bytes), a Put item nested deeper than 32 levels, expression syntax or limits |
Request-level Validation, before the token check. |
| Two actions on one item | Request-level Validation Transaction request cannot include multiple operations on one item, after the token check. |
| A table does not exist | Request-level Resource Requested resource not found. |
A table is still CREATING |
Request-level Resource Table is being restored: <table>. |
A key attribute, or an index key attribute written by a Put or Update, is an empty string or empty binary |
Request-level Validation, not a cancellation. |
A finished Update item has an invalid attribute value |
Request-level Validation, not a cancellation. |
A Put item over 48,000 bytes |
Request-level Validation Item size has exceeded the maximum allowed size, from the apply step, not a cancellation. |
An action's key does not match its table's schema, a Put item value or key type is invalid, or an Update expression names a key attribute |
Canceled. Validation at the first such action; every other action is None. No condition is evaluated. |
| One or more conditions fail on the stored items | Canceled. Conditional at every failing action, with the old item under Item when that action asks for Return and the item exists. Other actions are None. An expired item counts as absent. |
| A condition cannot be evaluated against the stored item | Canceled. Validation at that action; evaluation stops there. Conditional reasons of earlier actions stay. |
An Update fails on the stored item: arithmetic on a string, a missing parent map, or a finished item over 48,000 bytes |
Canceled. Validation at that action. |
A Put or Update writes an index key attribute with the wrong type |
Canceled. Validation Type mismatch for Index Key at that action. |
| A write conflict | No error while fdyno's retries succeed within the request time budget. If conflicts use up the budget: canceled, with Transaction "Transaction is ongoing for the item" at every action (FoundationDB reports the conflict for the whole transaction, not per item). Nothing is applied. |
| Same-item contention or FoundationDB throttling | Request-level Provisioned (contention) or Throttling (FoundationDB); no Cancellation. |
The whole transaction does not fit one FoundationDB transaction (FoundationDB error 2101) |
Request-level Validation. The message gives the request's item and value size in MB and, per table, how many copies of each item one write can store: the item, each ALL or INCLUDE index entry, the stream images and the PITR old image. If fdyno cannot read the table metadata for that message, it returns a shorter message without the counts. A key or value over FoundationDB's size limits (2102, 2103) also returns the shorter message. |
| The time budget runs out | Before a commit: request-level Provisioned when the budget went to contention, else Throttling. During a commit: Internal, and the outcome may be unknown. See when the outcome is unknown. |
See txn_ops.go
(planTransactWrites, checkTransactWriteConditions, mapTxErrorMsg) and
what a client gets at a limit.
What one write commits¶
Take a table orders with the key pk, an index named status on the
status attribute, and a stream created with the table (one shard). A
PutItem of {"pk": "order#1", "status": "paid"} runs as one
FoundationDB transaction. This is a successful first attempt with the
table metadata cached and PITR and TTL off:
- fdyno gets a read version, or reuses a recent one (read modes). Every read in the transaction sees the database at that version.
- It reads the table's metadata revision and the old item in one round trip. Each read adds a read-conflict range. The old item tells fdyno which index entry to clear. For a stream view with old images, it is also the old image. Here there is no old item.
- It checks the condition, if there is one, and builds the new item. A
failed condition ends the request with
ConditionalCheckFailedException, and nothing is written. - It buffers the three keys below in the transaction. Nothing is in the database yet.
- It commits once. FoundationDB checks the read-conflict ranges against
the commits after the read version. It applies all three keys at one
commit version, or none of them, and fills the stream key's
versionstamp. After a conflict (
1020), nothing was written. fdyno then retries at a newer snapshot if the budget allows. - fdyno sends a success reply only after the commit completes.
| Directory | Key (tuple) | Mutation | What it is |
|---|---|---|---|
dynodb/ |
("i", |
Set | The item, in the binary codec. |
dynodb/ |
("x", |
Set | The index entry, with the projected item. The table key at the end keeps items with equal index values apart. An item without status gets no entry. |
dynodb/ |
("vg", |
Set with a versionstamped key | The stream record, in the stream's current generation, epoch and shard (stream layout). FoundationDB writes the commit's 10-byte versionstamp into the key, so stream order is commit order within a shard. |
An UpdateItem that changes status from paid to shipped reads the
old item, then also clears ("x", "status", "paid", "order#1") and sets
("x", "status", "shipped", "order#1"): four mutations. With TTL on, fdyno takes the item's expiry bucket from a
valid numeric TTL value. A write that changes the bucket clears the old
expiry-index entry, if any, and sets the new one, if any. A write that keeps
the bucket changes neither.
See the full key inventory.
The directory layer maps each directory path to a short prefix, and the
tuple is packed after it. A tuple string is 02, its UTF-8 bytes with
each 00 written as 00 ff, then 00:
| Tuple | Packed bytes |
|---|---|
("i", |
02 69 00 02 6f 72 64 65 72 23 31 00 |
("x", |
02 78 00 02 73 74 61 74 75 73 00 02 70 61 69 64 00 02 6f 72 64 65 72 23 31 00 |
A number key is stored as a tuple byte string of an order-preserving
encoding
(number.go).
For 100.5, that is 1.005 × 10^2:
| Bytes | Meaning |
|---|---|
02 |
Sign: 02 positive, 01 zero, 00 negative |
40 00 00 02 |
Exponent 2, plus 2^30, big-endian |
31 30 30 35 |
Significant digits "1005" |
00 |
End |
A negative number inverts the exponent and digit bytes and ends with ff.
In the tuple, a byte string is 01, the bytes with each 00 written as
00 ff, then 00:
01 02 40 00 ff 00 ff 02 31 30 30 35 00 ff 00. So 2 (exponent 0) sorts
before 100 (exponent 2), although the text "100" sorts before "2".
When the outcome is unknown¶
Before commit, a failure changes nothing. During commit or after a lost
response, the client cannot tell whether all effects committed or none did
(FoundationDB's commit_unknown_result). Atomicity still holds.
fdyno retries until the request budget ends (DYNODB_OPERATION_TIMEOUT,
30 s by default). If a sent commit's outcome is still unknown when the
budget ends, fdyno returns HTTP 500 InternalServerError with the message The write
may or may not have been applied. Read the item before you retry, or retry
with a condition expression. TransactWriteItems with a ClientRequestToken is
safe to retry. Every write path uses that one message
(Errors). A commit that failed definitely, such as a
conflict (1020), does not make the outcome unknown; see
the retry loop. SDKs may retry the
500 under their retry policy, as a new request. Client or load-balancer timeouts leave the same doubt
without that message.
How the retry loop spends the budget¶
| Step | What happens | FoundationDB timeout | Time left |
|---|---|---|---|
| Attempt 1 | The transaction is created. Its FoundationDB timeout is set once, to the whole span from creation to the deadline. Pictured: three attempts; the loop has no fixed attempt count. | set once: the whole span | more than the margin |
| Backoff | FoundationDB's OnError wait, randomised up to a bound that doubles from 10 ms to the maximum retry delay: 100 ms after a conflict (1020), 1 s after another retryable error. |
set once: the whole span | more than the margin |
| Attempt 2 | A retry neither restarts nor clears the timeout. | set once: the whole span | more than the margin |
| Backoff | The same rule, with the doubled bound. | set once: the whole span | more than the margin |
| Attempt 3 | It starts with more than the margin left. | set once: the whole span | more than the margin |
| Pre-submit check | Before it sends a commit, a write checks the time left. Pictured: the check finds less than the margin, so the write sends no commit. A refusal sends nothing, so the write fails definitely, unless an earlier attempt's commit outcome is already unknown. A check that passes is not repeated at the send, so a pause after it can still put the send inside the margin. After a conflict, a write also starts no new attempt with less than the margin left. | set once: the whole span | less than the margin |
| Rule | Behavior |
|---|---|
| Budget | The loop has no fixed attempt count. The operation deadline, the context and the commit margin bound it. |
| Timeout | The FoundationDB timeout option is set once, to the whole span from the transaction's creation to the deadline. FoundationDB measures it from creation, and a retry neither restarts nor clears it. Setting it to the time left at each retry ended retried transactions early, at about half the budget. |
| Margin | The smaller of the commit safety margin and 1/20 of the transaction's span. The commit safety margin is 1/20 of DYNODB_, at least 5 ms and at most 1 s. Before it sends a commit, a write checks the time left and refuses with less than the margin. The send call does not check again, so a pause after the check can still put the send inside the margin. After a conflict, a write does not start a new attempt with less than the margin left. A refusal sends nothing, so the write fails definitely, unless an earlier attempt's commit outcome is already unknown. |
| Backoff | FoundationDB's OnError wait, randomised up to a bound that doubles from 10 ms to the maximum retry delay. After a conflict (1020) the maximum retry delay is 100 ms; after another retryable error it is FoundationDB's default of 1 s. With the default, when several processes conflict on one key, the one that lost a few rounds could sleep up to a second per retry while the others commit. |
| Throttles | 1213 (tag_) and 1051 (batch_) end the loop at once; they are not retried. If an earlier commit's outcome is unknown, the error keeps that unknown outcome. |
| Timeout error | 1031 (transaction_), or the deadline during a backoff wait, ends the loop. |
When a write's loop ends at the deadline, the response depends on its state:
| State when the loop ends | Response |
|---|---|
| A sent commit has an unknown outcome | 500 Internal, The write may or may not have been applied |
| No unknown outcome; the write had a conflict or waited in the same-item queue | 400 Provisioned: definitely not committed; SDKs may retry it under their retry policy |
| No unknown outcome and no contention | 400 Throttling, Foundation (Account): definitely not committed. Usually FoundationDB held the transaction back (ratekeeper); SDKs retry it |
See the transaction runner.
Errors and what they mean¶
HTTP 400 needs a request change or backoff; HTTP 500/503 come from the server. SDKs retry the rows marked SDK retries automatically.
| Error | HTTP | Committed? | What to do |
|---|---|---|---|
Conditional |
400 | No | Read the item; do not resend unchanged. |
Transaction |
400 | No | Read Cancellation. For Transaction, retry with backoff: nothing was applied. |
Validation |
400 | No | Fix the request. Also returned when a write does not fit one FoundationDB transaction. |
Provisioned |
400 | No | Back off; SDK retries. Comes from a key's rate limit or same-item contention, including a time budget spent in the same-item queue. |
Throttling |
400 | No | Back off; SDK retries. The process is at DYNODB_ or its request-body budget, FoundationDB throttled the request (also a time budget spent before the commit), or a GSI is behind. |
Request |
408 | No | The request body did not arrive within 60 s; nothing from it ran. The standard and adaptive SDK retry modes treat it as retryable; botocore's legacy mode does not. |
Idempotent |
400 | No | A live token was reused with a different request. Use a new token. |
Transaction |
400 | Yes | A request with the same token is still running. Retry with backoff; the retry replays its outcome. Nothing was applied by this request. |
Internal with The write may or may not have been applied |
500 | Unknown | SDK retries, as a new request. Follow the retry rules. |
Access |
400 | No | The key's policy denies the table or action. |
Unsupported |
400 | No | The production profile refuses a setting fdyno cannot honor: KMS, on-demand throughput limits, resource policies, Kinesis destinations or Contributor Insights. |
Signature errors have their own rules.
fdyno's own retries¶
A conflict or retryable error reruns the write at a newer snapshot within the
budget. Of two conflicting read-modify-write updates, one commits; the other
retries on that value. A deadline before the commit means nothing committed.
Table operations bind retries to the original table, so a retried
DeleteTable cannot delete a replacement of the same name.
After fdyno sends a commit, only these FoundationDB errors show that the
attempt did not commit
(transaction_runner.go):
1020(conflict);1007(transaction too old);1038(database locked);1042and1078(proxy memory limits);1051and1213(throttling);2101,2102and2103(size limits).
Any other error after fdyno sends the commit makes the outcome unknown, such
as 1021 (commit_unknown_result). A deadline while fdyno waits for the reply
does the same. The write then applied once or not at all. What fdyno
does next depends on the write:
| Write | After an unknown commit |
|---|---|
Transact or write Execute with a Client |
fdyno retries inside the request. The token record replays an attempt that committed. |
Every other write: PutItem, Update, Delete, Batch, PartiQL INSERT, UPDATE and DELETE, and a transaction without a token |
fdyno does not retry. It returns Internal (HTTP 500) with The write may or may not have been applied. |
A second application of SET n = n + 1 would add twice. fdyno does not
retry a blind PutItem either. Suppose the first commit applied and another
client then wrote the item. A retry inside the same request would bring the
first value back and undo the other write. No single application can do that.
DynamoDB also returns InternalServerError when it cannot tell; the client
decides, with the retry rules. A split
BatchWriteItem keeps the chunks that committed before the unknown one and
does not attempt later chunks.
Which writes are safe to repeat¶
| Write | If it runs twice | Retry rule |
|---|---|---|
PutItem of a full item |
Same final value | Safe, unless it overwrites a newer write from another client. |
Delete |
The second finds nothing | Safe, unless another client re-created the item. |
SET a =, REMOVE a |
Same final value | Safe, with the same caveat. |
ADD n :d, SET n = |
Adds twice | Not safe. Read first, or use a token. |
list_, list index REMOVE, append by index |
Changes the list again | Not safe. |
| Add or delete fixed set members | Same final set | Safe. |
Create with attribute_ |
At most one create | Safe, but the retry can fail its condition after the first succeeded. |
Batch |
Can commit in parts | Retry only Unprocessed. |
Transact without a token |
Runs again | Add a token. |
Transact with a token |
Applies at most once under the client procedure | Retry the identical request and leave time for the server to check the token. A retry that newer expression limits reject cannot replay; see tokened transactions. |
Tokened transactions¶
TransactWriteItems and write ExecuteTransaction store the token and a
request hash in the writes' transaction. Uncommitted writes have no token.
A valid call that finds a live token returns a successful replay without
another write if its request hash matches. The replay rebuilds the response;
its consumed capacity is reported as reads, not the original writes. If the request hashes differ, the call fails with
IdempotentParameterMismatchException, even if only ReturnConsumedCapacity
changed. An invalid request can be rejected before either check, as below.
While a tokened request runs, another request with the same token on the
same fdyno process fails with TransactionInProgressException
("Transaction from previous request is still in progress"), as in
DynamoDB, and writes nothing. The AWS SDKs retry it; the retry replays the
first request's outcome. A request with the token on another process is not
refused: there the first commit binds the token, and the other request
replays it or fails with IdempotentParameterMismatchException.
Request-level validation of a tokened TransactWriteItems request runs
before fdyno looks up its token. It includes the expression limits: 300 operators and functions,
4,096 bytes per condition or update expression, and 2 MiB of substitutions
per expression (limits). If an identical retry passes validation and finds a live token
record with a matching request hash, it replays without another write.
Tokens work across processes and restarts. See the token validation and retention code.
The 10-minute window starts at the timestamp that fdyno records immediately before the write commits. The process that checks the token compares that timestamp with its own clock. After it reads an age of more than 10 minutes, it treats the request as new. If its clock is ahead of the writer's, the window is shorter by the difference. Cleanup via DYNODB_TXN_TOKEN_GC_INTERVAL frees storage; it applies the same test with its own clock.
Client procedure¶
- Create a token of 1 to 36 UTF-8 bytes before the first attempt. Omit the field, not an empty string, for no token.
- Durably store the token, exact request and intent. Never create a token per attempt.
- Put dependent writes in one tokened
TransactWriteItems. - After timeout, connection error or unknown outcome, resend the identical request and token.
- Send the last retry early, so that fdyno can start it in time. The limit
is 9 minutes minus
DYNODB_OPERATION_TIMEOUTafter the first send. Allow for network and proxy delays. At the default 30-second timeout, fdyno must start the retry within 8 minutes 30 seconds of the first send.
This rule assumes the one-minute clock bound with no clock step or host suspend. It leaves time for fdyno to check the token within 9 minutes of the first send. It does not guarantee a response by then. For longer recovery, store an idempotency key in your data.
Conditional writes¶
A version/operation-ID condition protects one item: “update if version 7” stops an old retry overwriting version 8. After unknown outcome, a failed condition can mean the first attempt succeeded or another client wrote. Read to distinguish them; use a tokened transaction for multi-item invariants.
Batches¶
BatchWriteItem is not atomic. It first tries one transaction. If the batch
is too large, it validates the whole batch, then commits groups of about 4 MiB.
Invalid input writes nothing. Chunks that did not commit return in
UnprocessedItems; retry only those.
If every chunk was throttled, nothing is written and the
request fails with the throttle, as ProvisionedThroughputExceededException
(HTTP 400); back off and resend it. An unknown chunk returns InternalServerError:
earlier chunks remain committed, later chunks do not run. Read affected
items before resending.
BatchExecuteStatement returns HTTP 200 with an InternalServerError entry
for an unknown-outcome statement. Others may have committed.
Size¶
Both limits apply: 100 actions/4 MiB request data and 10,000,000 FoundationDB
bytes after chunks, indexes, streams and token. Large copies can exceed the
second within DynamoDB's limit: ValidationException, nothing written.
See exact limits.
Workflows that use several transactions¶
None exposes a partial result:
| Workflow | How it stays consistent |
|---|---|
| New GSI | The index is registered as CREATING; new writes update it at once. A background job copies old items in pages, each page committing with its cursor. The last page marks the index ACTIVE. Queries on it fail until then. |
| Backup | Pages are read at one pinned read version and staged. The backup becomes visible only when complete. If the read version expires, the backup is labelled ROLLING. |
| Restore | The target stays CREATING while batches commit with their progress; only the complete copy publishes ACTIVE. A crashed restore resumes on another process. PITR runs in the background. |
| TTL deletion | Reads use TTL plus DYNODB_ (one minute) by the local clock. The sweeper re-checks expiry in its deleting transaction, so it never deletes a refreshed item. |
Streams and recovery¶
Streams record committed changes, not requests. A retry writing the same value adds no record; a repeated increment does. Consumers can reread after a crash and need checkpoints/idempotent processing.
Table backups omit tokens; whole-database FoundationDB backups include them. Table restore forgets old tokens.
Not guaranteed¶
fdyno has no interactive or multi-request transactions and no atomic large batch. APIs that have no token in DynamoDB have no token in fdyno. fdyno retries an unknown commit only for tokened transactions. Token protection ends when the token expires. Consistency defines each transaction's isolation.
Request and background unknown outcomes have separate
counters.
How we know: the ambiguity contract matrix runs every write with injected
unknown commits (ambiguity_contract.json).
The split batch model checks how a
split BatchWriteItem reports chunk outcomes.