spicedb icon indicating copy to clipboard operation
spicedb copied to clipboard

Proper handling of incompatible zedtokens

Open josephschorr opened this issue 1 year ago • 9 comments

NOTE: ZedTokens are a bit longer now as a result of this change, but should still be well within the 1024 limit previously defined

Fixes #1541

josephschorr avatar Jan 29 '24 21:01 josephschorr

Rebased

josephschorr avatar Mar 13 '24 19:03 josephschorr

Rebased

josephschorr avatar Apr 01 '24 13:04 josephschorr

Updated

josephschorr avatar Jul 01 '24 18:07 josephschorr

Some early feedback, I'll continue tomorrow. Please describe in the PR body what problems are you trying to solve and design choices you took to come up with this solution. It helps folks reviewing the PR with the right context 🙏🏻

I added the fixes; it was on the commit but not the PR

josephschorr avatar Jul 09 '24 20:07 josephschorr

We are transferring UUIDs in every API call for no reason other than to prevent an eventual migration within the same datastore type. That's extremely wasteful.

Is it really? We could reduce the size of the ID to just a small prefix if we wish to save some bytes.

It's still within the zedtoken spec limit, but it is a very high price to pay for an incredible rare event (a legit one, don't get me wrong). We are storing UUIDs in the datastore as strings, which is the least compact way of storing them and transferring them over the wire. And we are forcing everybody to see the data transferred increase significantly (and latency!) to prevent a scenario that the system will not be subjected to in, I'll dare to say, practically 100% of its lifespan.

Except users have already been subject to it - this was spurred by two, different reports: one where a user moved between datastore types, but another where they moved between datastores of the same type (but accidentally)

We need to rethink this. I get the zedtoken is a stateless token and that it needs to self-contain this information, but I think we can get 99% there by defining the datastore type as a small attribute in the token. I understand migrating from different instances of the same datastore can be problematic, but no one asked for this,

It has happened before, sadly.

and we could find alternative ways for it (e.g. a flag that forces SpiceDB to ignore requested consistency and fallback to full_consistency all the time, or minimize_latency if the customer can take the hit of ignoring the new enemy problem during the migration). I'd argue that by adding such a flag we could completely avoid having to add the datastore type too.

This PR does add that flag, but we need a means of tracking to ensure that zedtokens are not used across instances of a datastore. The fact that we allow it now is, technically speaking, a small but real risk.

josephschorr avatar Jul 10 '24 20:07 josephschorr

Updated to only store 8 bytes of prefix of the datastore ID. Since datastores are rarely updated, this should be fine for detecting changes.

josephschorr avatar Jul 11 '24 19:07 josephschorr

Rebased

josephschorr avatar Jul 30 '24 20:07 josephschorr

Rebased

josephschorr avatar Aug 06 '24 17:08 josephschorr