Default consistency level for SpiceDB cached permission checks
0 reputation · 12 May 2020, 06:01 UTC
0 reputation · 12 May 2020, 06:01 UTC
SpiceDB maintains a caching layer for relationship tuples and permission checks to reduce latency for repeated access patterns. When a read request omits a consistency token, the server may return a result retrieved from this cache, which can represent a permission state that does not include recent write operations. This behavior enables the fastest possible response but may produce stale results.
The platform offers the at_least_as_fresh_as consistency level, which accepts a Zookie or ZedToken to enforce that returned data is not older than a specified causal point. However, the default freshness guarantee when no token is supplied -- specifically how the server decides between cached and freshly computed results -- is not explicitly documented, creating ambiguity for operators seeking predictable freshness behavior.
35275 reputation · 12 May 2020, 06:38 UTC
When a CheckPermission request is issued without a consistency token (ZedToken), SpiceDB defaults to a minimize-latency mode. In this mode, the server may serve results from its internal in-memory caches rather than guaranteeing that the result includes the most recent write operations.
The decision to serve a cached result versus performing a fresh computation is governed by internal cache validity windows. If a permission check matches an entry in the dispatch or relationship cache that has not yet expired or been invalidated, the server returns that cached value. If the entry is missing or has passed its internal TTL (Time-to-Live), the server triggers a fresh read from the datastore and re-evaluates the permission.
| Aspect | Confirmed Behavior | Likely/Assumed Behavior |
|---|---|---|
| Consistency | Omitting a token allows stale reads. | Default staleness is bound by internal TTLs. |
| Control | at_least_as_fresh_as enforces a causal point. |
No global "minimum freshness" toggle exists. |
| Scaling | High write volume increases cache misses. | Freshness improves as hit rates drop. |
Under high-frequency update workloads, the default freshness behavior scales inversely with cache efficiency. Because frequent writes invalidate related cached entries, the server is forced to perform more fresh computations. While this increases datastore load and latency, it implicitly reduces the window of staleness for those specific permissions.
To determine the actual staleness window in your specific environment and version, use the following scoped verification method:
CheckPermission call without a consistency token.Note: Because cache defaults can vary between SpiceDB releases, you should measure this behavior on your deployed version rather than relying on a fixed theoretical threshold.
To provide a more precise recommendation on cache tuning, please specify the SpiceDB version currently in use, as cache invalidation logic and configuration flags have evolved across releases.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.