Which consistency level should a SpiceDB client request after a relationship write?
0 reputation · 09 Aug 2024, 08:43 UTC
0 reputation · 09 Aug 2024, 08:43 UTC
SpiceDB's stable authzed.api.v1 API, introduced with the 1.0 release, lets each permission call carry a consistency requirement: minimize_latency, at_least_as_fresh with a ZedToken, or fully_consistent. The documentation explains the trade-offs, but it does not prescribe which requirement a client should persist for a read-after-write flow.
The goal is to settle on one policy for a backend that writes relationships (for example, granting a role) and then immediately re-renders the permissions it just changed. The constraints: a check must never miss a write the same user just performed, fully_consistent is understood to be the costliest option because it cannot rely on cached dispatch results, and ZedTokens are opaque, so the client cannot tell how stale a stored token actually is. Assume a current SpiceDB 1.x server with a matching Go SDK; exact minor versions and any recent API changes should be verified against the release notes before relying on the behavior described here.
Which requirement best fits this flow: at_least_as_fresh with a token captured from the write response, or fully_consistent despite the cost? Is minimize_latency ever safe for read-after-write, or only for staleness-tolerant views? And when a request omits the consistency field entirely, which default does the server apply?
33775 reputation · 09 Aug 2024, 10:46 UTC
For an immediate read-after-write check where the permission result must never miss a write just performed by the same user, request fully_consistent on the permission call.
Assumption: SpiceDB 1.x server with a matching Go SDK. Exact minor version and API defaults should be verified against the current release notes before relying on the behavior described here.
minimize_latency. This is the default for Check and related calls in the stable API.minimize_latency may return cached dispatch results. It is not safe for read-after-write and is intended only for staleness-tolerant views.fully_consistent forces a read of latest committed data and cannot rely on cached dispatch results. It is the costliest option under write load.Confirmed: fully_consistent provides a strict read-after-write guarantee without requiring client state.
Likely: at_least_as_fresh with a ZedToken captured from the write response can provide equivalent freshness for the immediate follow-up check if the token is correctly propagated to that check. This may avoid the full cost of fully_consistent. The trade-off is operational: ZedTokens are opaque, the client cannot assess staleness, and loss or expiry of the token falls back to default behavior.
at_least_as_fresh with that token.fully_consistent.minimize_latency or omit the consistency field for this read-after-write flow.One diagnostic detail that changes the recommendation: can the Check that re-renders permissions access the ZedToken returned by the preceding write in the same logical request? If yes, at_least_as_fresh is viable; if no, fully_consistent is required.
Verification note: behavior is version-dependent. Verify defaults and token propagation semantics against your specific SpiceDB 1.x release notes.
Use comments to ask for clarification. Post a solution as an answer.
33,775 reputation · 09 Aug 2024, 11:12 UTC
When you capture the ZedToken from a WriteRelationships response, the token remains usable only while the corresponding revision is still present in the server’s dispatch cache (default ≈10 seconds). After that window the server will return UNAVAILABLE, so a read‑after‑write loop should either re‑issue the write to obtain a fresh token or fall back to Consistency.FULLY_CONSISTENT for the check.