Hello everyone. I found this place as I
# spicedb
a
Hello everyone. I found this place as I wanted to clear some doubts on postgres database backend for spicedb. In the blog post https://authzed.com/blog/spicedb-architecture it is mentioned that for maintaining causal ordering, something similar to MVCC was manually implemented. This raises eye brow (slightly) since not a lot of detail is provided and why a serializable isolation level (strictest offered by postgres) is not sufficient ? One reason I can think of would be to not fail a ACL change if a causally related tx is happening parallely, but rather handle it during ACL check process ?
v
The MVCC is used to support the bounded staleness of Zanzibar. Spanner supports snapshot reads, while Postgres does not. It's the foundation to a lot of the optimizations Zanzibar does to minimize, as much as possible, database access.
a
Thank you, appreciate your response. In the Zanzibar paper, they have mentioned bounded staleness as one of the key property for consistency. So, if it helps in optimization is only secondary side effect (?).
I am still not getting how it is relevant in postgres case.
j
all datastores using SpiceDB must support the concepts of snapshot reads
since Postgres does not do so natively, we built our own MVCC model on top of the tables, using some of Postgres's own MVCC machinery to make it more efficient
v
and FWIW, same for MySQL
j
although MySQL does not use the internal MVCC stuff
a
hmm..ok. I understand why a snapshot read would be beneficial for a distributed database. You do not have to pay for creating a transaction which is in theory heavier than a postgres transaction on a single node.
j
its not just beneficial - its required
a
So, the manual MVCC implementation is only for the feature impedance matching ? OR does it solve any real consistency issue ?
Ok. Would be helpful if you can explain it a bit.
j
the fundamental insight that Zanzibar made was that most permissions checks do not need the most up-to-date information, but rather can have some staleness
to have effective and efficient caching, the system needs to be able to ask the question "what was the permission at this point in time?"
otherwise, it can return inconsistent results because each subproblem is computed on a different node
a
But there is no other node for postgres. Atleast in my deployment, there is only primary node.
j
SpiceDB nodes
for example, take a simple schema
Copy code
definition user {}

definition document {
  relation viewer: user
  relation editor: user
  permission view = viewer + editor
}
check permission document:somedoc view user:someuser
will result in 3 dispatches:
document:somedoc view user:someuser
,
document:somedoc viewer user:someuser
,
document:somedoc editor user:someuser
the
viewer
and
editor
will be computed independently
now imagine
editor
is updated after
viewer
is checked but before
editor
is checked; the result won't reflect a single point in time
which means its inconsistent
so SpiceDB will pick a point-in-time
and then instruct
viewer
and
editor
to both be computed at that specific point
even if something is added to
editor
while the computation is going on, it won't be reflected in the answer
the answer is then cached at that point in time, so the cache can be sure to not return too-stale answers if requested
a
Thanks for taking the time to provide the detailed answer Joey. Really appreciate it.
Postgres serializable isolation avoids this by throwing an error. In which case client musty retry AFAIK.
j
that prevents the writes from overlapping
but it doesn't prevent the reads unless we fully transactioned them serializable as well
but that would make reads very, very slow
a
Yes. For the usecase that I am having, it is not that slow. Hence these questions.
It is not a planet scale app and I was just trying to play around with this model
But it helped a lot. Thank you Joey
j
sure
but we handle that for you
you just point SpiceDB to postgres
and it handles all the MVCCing and consistency
and then there is a consistency block on the API requests to allow you to choose what level you need
we recommend
minimize_latency
for most checks unless you need read-after-write
a
Interesting. I have not gotten that far. Will definitely check it out.
8 Views