FaunaDB FQL v10 UDFs and client driver: serializability guarantees across regions
0 reputation · 30 May 2022, 04:47 UTC
0 reputation · 30 May 2022, 04:47 UTC
Designing a multi-region read path that invokes server-side User Defined Functions through a client driver requires clarity on where consistency is enforced.
FaunaDB provides a distributed transactional model with strict serializability and exposes FQL via a REST-based API that language SDKs abstract. UDFs encapsulate logic on the server side, while the document and index model governs retrieval cost. FQL syntax differs between legacy v4 and v10, and index design affects compute usage.
For an integration that relies on the documented serializable guarantees, it is unclear how the driver surfaces transaction metadata and whether any client-side configuration can affect the consistency applied to a UDF invocation.
Does the REST response for a UDF call include headers or fields that indicate the serializability level applied? Is the consistency model for UDF execution fixed server-side in FQL v10, or can driver options influence it? How should index-based retrieval inside a UDF be reasoned about with respect to global read latency?
35775 reputation · 30 May 2022, 09:44 UTC
In Fauna FQL v10, a UDF invocation is executed server-side as part of the transaction that carries the query. Strict serializability is a property of that transaction. It is not reported as a REST header or response field, and official client drivers do not expose a per-request read-consistency or isolation-level option. If your code contains a consistency, readConcern, or isolation setting, treat it as custom or inherited from another database until proven otherwise.
FQL v10 sends the entire query—including the UDF call—over the HTTP query API. The response is primarily the query result. It may include telemetry such as a transaction timestamp or operation summary/stats, but these describe execution, not a negotiated isolation mode. A timestamp should be read as the transaction visibility point, not as evidence of a consistency level. Do not infer serializability from latency or stats; those are telemetry and may omit internal coordination details.
Official drivers are transport wrappers: they manage endpoint, credentials, timeouts, retries, and result decoding. They do not alter the consistency applied to a UDF. To confirm for your version, inspect the driver's exported options or type definitions for names like consistency, readConcern, isolation, or lastWrite. Their absence supports fixed server-side behavior.
Index access inside a UDF is transactional. Latency and compute scale with the number of entries scanned and pages fetched, not with a client-side consistency setting. Prefer exact ref/id lookups or bounded index pages. Push selection into index terms where possible, and avoid unbounded scans. Across regions, do not assume a local-replica read path: a read may still need to observe the latest committed serializable state, so global latency is transaction visibility plus index work.
grep -rE "consistency|readConcern|isolation|lastWrite" node_modules/fauna/dist/*.d.tscurl -s -D - -X POST "$FAUNA_DOMAIN" \
-H "Authorization: Bearer $FAUNA_SECRET" \
-H "Content-Type: application/json" \
-d '{"query":"MyUdf()"}' If none appears, treat serializability as implicit.FQL v4 and v10 are not interchangeable. Verify the driver major, UDF syntax, and query shape before generalizing behavior. Retries of UDF calls that write can duplicate side effects unless the operation is idempotent; prefer idempotent UDF design or client-side deduplication. If you are using a custom REST client rather than an official driver, response field names may be normalized or dropped—capture raw responses before relying on them. Because driver surfaces and response fields can vary by version, confirm the specifics in your environment before treating them as settled.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.