Background
When querying OpenFGA using Read or any of the query APIs like Check, Expand, ListObjects and ListUsers, you can specify a query consistency parameter that can have one of the following values:
If you write a tuple and you immediately make a Check on a relation affected by that tuple using
MINIMIZE_LATENCY, the tuple change might not be taken in consideration if OpenFGA serves the result from the cache.
When to use higher consistency
When specifyingHIGHER_CONSISTENCY you are trading off consistency for latency and system performance. Always specifying HIGHER_CONSISTENCY will have a significant impact in performance.
If you have a use case where higher consistency is needed, it’s recommended that whenever possible, you decide in runtime the consistency level you need. If you are storing a timestamp indicating when a resource was last modified in your database, you can use that to decide the kind of request you do.
For example, if you share document:readme with a user:anne and you update a modified_date field in the document table when that happens, you can write code like the below when calling check("user:anne", "can_view", "document:readme") to avoid paying the price of additional latency when calling the API.
Cache expiration
OpenFGA caching is disabled by default. When caching is disabled, all queries will have strong consistency regardless of the consistency mode specified. When caching is enabled, the cache will be used for queries withMINIMIZE_LATENCY consistency mode.
You can use the following command line parameters to configure OpenFGA’s cache. To see the default value of each parameter, please run openfga run --help.
Learn how to configure OpenFGA.
Currently, the cache is used by Check and partially in ListObjects. It will be implemented for other query endpoints in the future.
Future work
The Zanzibar paper has a feature calledZookies, which is a consistency token that is returned from Write operation. You can store that token in you resource table, and specify it in subsequent calls to query APIs.
OpenFGA is considering a similar feature in future releases.
Related Sections
Check the following sections for more on how to check, read and expand.Relationship Queries
Comparison Between Check, Read And Expand API Calls.