Preview. Stack v4.0 has not been released, and what is documented here can still change before it does. The current release is v3.2, which covers this as Idempotency.Go to v3.2
Ledger

Errors and Retries

Classify Ledger failures and retry writes without creating duplicate financial operations.

This hidden page records the retry behavior visible in the Ledger 3.0 source snapshot. It is preparatory guidance, not a complete published error contract. The safe principle already applies: a timeout can occur after Ledger commits a write, so repeating an unprotected request can create another financial operation.

Error body#

Every error response carries the same two required fields:

json
{
  "errorCode": "IDEMPOTENCY_KEY_CONFLICT",
  "errorMessage": "idempotency key already used with different content"
}

Branch on errorCode, not on the status alone. One status covers several conditions with different correct responses: a 409 can be an idempotency conflict or an ordinary state conflict, and a 400 can be a validation failure or an insufficient-funds outcome. The status tells a client which class of handling applies; errorCode tells it what to do.

A bulk request is the one exception to the shape. A failure of the bulk request itself uses the standard body, while a per-element failure appears inside that element's result as errorCode and errorDescription.

HTTP error classes#

StatusMeaningClient action
400The request or business input is invalidCorrect the request; do not retry unchanged
401The token is missing, invalid, or expiredObtain a valid token
403The caller lacks the required scopeChange authorization, not the request body
404The requested ledger or resource does not existVerify the identifier and environment
405The route exists but does not accept this method, always as METHOD_NOT_ALLOWEDCorrect the method; do not retry unchanged
409The request conflicts with existing stateInspect the conflict before choosing a new identifier
413The request body exceeds 4 MB, as BODY_TOO_LARGE, or a bulk request exceeds 1000 elements, as BULK_SIZE_EXCEEDEDSplit the payload; retrying the same request cannot succeed
429A resource is exhausted. Disk protection also lands here: WRITES_BLOCKED_DISK_FULL means writes stay blocked until an operator reclaims storageNo Retry-After is sent. Apply bounded backoff with jitter, and check errorCode before retrying a write
503The cluster cannot currently serve the operation: commonly no leader, but also a read store still catching up, an index still building, or the clock-skew write gateEvery 503 carries Retry-After: 1. Honor it, then apply bounded backoff if the condition persists
500Ledger encountered an internal failureRecord the correlation ID when the response includes one, then involve the operator

These are the classes a client meets on the business routes, not a closed set. The snapshot has no single authoritative enumeration of statuses per operation, so handle an unlisted status by its class and branch on errorCode within a class.

The preview OpenAPI file attempts to define operation-specific responses, while the HTTP API design describes common error handling. The OpenAPI file is not a definitive contract yet: a duplicate response key prevents strict parsing, and its declared version is inconsistent with Ledger 3.0.

Protect write retries#

Send an idempotency key with every write that may be retried. In Ledger 3.0:

  • the key namespace is cluster-wide, not scoped to one ledger;
  • a key is limited to 256 bytes, not 256 characters, so a key using multibyte UTF-8 is rejected below 256 characters;
  • the same key and request content resolve to the original operation while the key remains valid;
  • the same key with different content returns a conflict;
  • successful results and definitive business failures are retained, while authentication and infrastructure failures are not replay records;
  • the default retention is 24 hours, but operators can configure it.

Build keys from a stable application operation identifier. Include enough context to prevent two ledgers or workflows from choosing the same value.

Do not assume an idempotency key remains available beyond the configured retention period. If the business operation requires permanent uniqueness, also use a stable transaction reference or enforce uniqueness in the calling system.

Retry decision#

SituationerrorCode to matchRetry?
Connection failed before a readNo response arrivedYes, with a deadline and bounded backoff
Read returned 503AnyYes; honor Retry-After: 1, then bounded exponential backoff with jitter
Read returned 429Any except WRITES_BLOCKED_DISK_FULLYes, with bounded exponential backoff and jitter; no header is sent
Writes blocked by disk protectionWRITES_BLOCKED_DISK_FULLNo; backoff cannot clear it, an operator must expand or reclaim storage
Protected write timed out or returned a retryable statusAnyYes, with the same idempotency key and identical body, bounded by the operation deadline
Unprotected write timed outNo response arrivedDetermine whether it committed before sending another operation
Validation errorVALIDATIONNo, unless the business input changes
Insufficient fundsINSUFFICIENT_FUNDSNo, unless the business input changes
Idempotency conflictIDEMPOTENCY_KEY_CONFLICTNo; investigate key reuse
Payload too largeBODY_TOO_LARGE, BULK_SIZE_EXCEEDEDNo; split the payload
Internal error with correlation IDINTERNAL_ERRORDo not loop; record the request and involve the operator

Always cap the number of attempts or total elapsed time. Repeated leader loss, overload, or storage pressure requires an operational response rather than an unlimited client loop.

Gates for publication#

Keep this page hidden until:

  1. the release OpenAPI parses and defines one error schema and response set for every published operation, including 405 and 413;
  2. regression tests pin Retry-After: 1 on every 503 path, including the bulk aggregator, and pin its absence on 429;
  3. idempotency tests cover replay, conflicting content, retention expiry, and the cluster-wide key namespace;
  4. SDK guidance implements bounded exponential backoff with jitter, a deadline, Retry-After handling on 503, and errorCode branching within each status;
  5. failure tests cover leader loss, overload, committed-but-timed-out writes, validation errors, and internal correlation IDs.