Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation about ZedTokens/Zookies and consistency #174

Merged
merged 1 commit into from
Oct 14, 2021

Conversation

josephschorr
Copy link
Member

Fixes #13

Consistency is provided via the [Consistency block] on API calls.

[V1 API]: https://buf.build/authzed/api/tree/main/authzed/api/v1
[Consistency block]: https://buf.build/authzed/api/file/main/authzed/api/v1/permission_service.proto#L50
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That URL is guaranteed to change, you probably meant this one: https://buf.build/authzed/api/docs/main/authzed.api.v1#authzed.api.v1.Consistency

docs/consistency-options.md Show resolved Hide resolved
@@ -0,0 +1,187 @@
# ZedTokens and Zookies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than the focus of this being documenting zed tokens / zookies, could we make this focused on "consistency and availability of spicedb" in general? Then we can answer questions like

  • where does SpiceDB fit into the CAP theorem?
  • what knobs for consistency are available to application developers?
  • what happens if SpiceDB is unavailable?

and also cover zed tokens/zookies in a way that people will discover them when they aren't familiar with the terms or how they relate to the system in general

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO most people will not care initially about reading about the CAP theorem, but rather how to effectively use the system. The consistency knobs are described in the other consistency document.

If we want a section on CAP guarantees, we can add that, but it is likely too technical for people trying to integrate effectively initially.

@josephschorr josephschorr force-pushed the zedtoken-docs branch 2 times, most recently from d84b79b to 63820a9 Compare October 5, 2021 20:47
@jzelinskie
Copy link
Member

I think this needs a rebase now that we have CI linting markdown.

@josephschorr
Copy link
Member Author

Rebased. Will fix lint issues as they appear.

@josephschorr josephschorr force-pushed the zedtoken-docs branch 2 times, most recently from 6a53838 to a91c78e Compare October 12, 2021 18:19
@josephschorr
Copy link
Member Author

Updated

@zarakay
Copy link

zarakay commented Oct 13, 2021

Was reading this PR to understand Zookies, found it very useful. I notice that the recommendations around storing/using zookies only covered the Read/Write endpoints.

Was curious which Zookie do you use for Expand/Lookup endpoints? eg. if you have a relationship between a User and their Notes, and you are using Expand, since you store a zookie against each Note resource, do you just pick one? Or always using the strongest consistency? Did I miss something?

@josephschorr
Copy link
Member Author

josephschorr commented Oct 13, 2021

Was reading this PR to understand Zookies, found it very useful. I notice that the recommendations around storing/using zookies only covered the Read/Write endpoints.

Was curious which Zookie do you use for Expand/Lookup endpoints? eg. if you have a relationship between a User and their Notes, and you are using Expand, since you store a zookie against each Note resource, do you just pick one? Or always using the strongest consistency? Did I miss something?

Generally, you always use the ZedToken for the resource on which you're performing the call. So if you previously issued a fully_consistent Check for that resource (and stored a ZedToken), you'd use the same ZedToken in Check, as well as Expand.

For Lookup or Read, it is less defined: if you are using Lookup or Read to, say, list things that a user can view, and you're concerned that a user might temporarily be able to see a change in this list (say the title of a resource was changed to have sensitive information), then the recommendation would be to store the result of the fully_consistent Check not just for the resource, but for its container as well (folder, namespace, organization, etc), and then use that ZedToken for Lookup or Read too. However, this is only necessary if sensitive information can somehow leak through your code that uses one of these calls. If it is cannot, just use the default consistency for the calls, and occasionally you'll get cached (but safe) information.

@@ -0,0 +1,70 @@
# Consistency Options

SpiceDB's [V1 API] provides the ability to specify the *consistency* level at which API calls are made.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use lowercase v everywhere else. This whole document needs to be updated for that.


SpiceDB's [V1 API] provides the ability to specify the *consistency* level at which API calls are made.

Consistency is provided via the [Consistency block] on API calls.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/block/message

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... on {adjective} API calls.

supported?
available?

[V1 API]: https://buf.build/authzed/api/tree/main/authzed/api/v1
[Consistency block]: https://buf.build/authzed/api/docs/main/authzed.api.v1#authzed.api.v1.Consistency

## Default Consistency: minimize_latency
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaults

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant we should just change this section title to be "Defaults" since it not only talks about minimize_latency, but also the fully consistent APIs like the schema APIs and write/delete.


## Default Consistency: minimize_latency

The default consistency level for all V1 API calls (except `WriteRelationships` and `DeleteRelationships`, which are always fully consistent) is `minimize_latency`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schema operations are also fully consistent


Note that the snapshot used will be loaded at the beginning of the API call, and that new data written *after* the API starts executing will be ignored.

**WARNING:** Use of `fully_consistent` means little caching will be available, which means performance will suffer. Only use if a [ZedToken/Zookie] is not available or absolutely latest information is required.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one sentence per line


**WARNING:** Use of `fully_consistent` means little caching will be available, which means performance will suffer. Only use if a [ZedToken/Zookie] is not available or absolutely latest information is required.

[ZedToken/Zookie]:zedtokens-and-zookies.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space between : and zedtokens-and-zookies.md


### What is a ZedToken or Zookie?

In simplest terms a `ZedToken` (or `Zookie`) is a token representing a **point-in-time** of the SpiceDB datastore, encoded for easy storage and transmission.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"ZedToken (v1) or Zookie (v0)" or maybe even link to the buf docs for each

[V1 API]: https://buf.build/authzed/api/tree/main/authzed/api/v1
[Consistency]: consistency-options.md

#### v0 API
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should de-emphasize v0 somehow. Either put it in a <details> or just get rid of it all together.


In V1, you can pass the `ZedToken` as `at_exact_snapshot` in the [Consistency] options to ensure the API result is computed at that exact point.

**WARNING:** SpiceDB will expire garbage and collect it over time. The above API call *can fail with a "Snapshot Expired" error*. This window is determined by the `--datastore-gc-window` when running SpiceDB.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one sentence per line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this probably needs one more sentence describing how you should basically only use this if you're paginating something over a very short amount of time and nothing else.

V1Zookie deprecated_v1_zookie = 2;
V1ZedToken v1 = 3;
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid of these codeblocks rotting. Maybe we should just link to the proto files?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

@josephschorr
Copy link
Member Author

Updated

@josephschorr josephschorr force-pushed the zedtoken-docs branch 2 times, most recently from 55f0248 to 7e9e3b5 Compare October 14, 2021 17:49
Fixes #13

Signed-off-by: Joseph Schorr <josephschorr@users.noreply.github.com>
@josephschorr josephschorr merged commit e264e9c into main Oct 14, 2021
@josephschorr josephschorr deleted the zedtoken-docs branch October 14, 2021 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document Zookies
3 participants