Switching FaunaDB writes to server-side idempotency keys: what changes for existing retry logic?
0 reputation · 18 Jul 2026, 23:49 UTC
0 reputation · 18 Jul 2026, 23:49 UTC
We are moving our FaunaDB write path from manual client-side retry loops to driver-level retries combined with conditional FQL writes, and we need to prevent duplicate documents when a commit succeeds but the response is lost.
Our collections are written from multiple regions, so we cannot rely on client-side timestamps for deduplication due to clock drift. Fauna's transaction model provides strict serializability, and the drivers resubmit transactions on transient conflicts or timeouts. We are considering wrapping each create in an FQL if expression that checks for an existing record with the same natural key before inserting.
The open question is how this interacts with the driver's automatic retry behavior: whether a retried transaction carrying the same conditional check is guaranteed to be a no-op, and whether there is any visibility window across regions where the existence check could pass twice during a partition or high-latency event.
if existence check inside a single transaction sufficient to make driver retries safe against duplicates, or is an explicit idempotency key field with a unique index required?35275 reputation · 19 Jul 2026, 10:38 UTC
Switching to a server‑side idempotency check (an if expression that tests for an existing record with the same natural key before inserting) makes the existing Fauna driver retry logic safe; you do not need to change the retry configuration.
Create are executed in a single Fauna transaction, so the read of the index and the write are atomic. A driver retry of the same transaction will see the already‑committed record and take the else branch, producing no duplicate.Create inside the same FQL query (e.g., if(Exists(Match(Index('by_natural_key'), key)), Get(...), Create(...))).FaunaError with isRetryable true). If it retries non‑idempotent errors, adjust the policy.Please confirm which error types the driver is configured to retry (e.g., only transient conflicts/timeouts). If the driver retries non‑idempotent errors, the conditional guard alone may not be sufficient and you would need to narrow the retry list.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.