by javitury · 5y ago · 0 comments
This project is a "github clone" and a user has decided to delete a repository with all of its related objects. In postgres these related objects delete automatically in cascade. How can I do the same in SpiceDB to avoid leaving garbage tuples behind?
The simplest choice to get started with is to add it directly to your application logic. The main pro of this solution is that you can directly handle the semantics of when and how to add/remove permissions. For example, it's sometimes safe and idempotent to write permissions for data that may fail to commit, because permissions for the data will never be queried in the future. You can also directly control the management of ZedTokens and effectively eliminate the new enemy problem[0]. As far as I know, this is how Zanzibar is used within Google.
Solutions which tail a primary source of truth, such as the database logs, kafka topic, event queue, etc. may perform better in some applications where eventual consistency on permissions is ok. With these systems you are adding some delay in between writing the data and the permissions, which can open you up to new enemy or require UX compensation like adding data on the client side and hoping the permissions replicate before they are ever queried for real.
We will work to write a guide that talks about some of these architectures and their pros and cons.
In the case of deletions, for example, you would need to track what entities you are deleting and call the service to update/delete the related permissions.
You could do this with some worker subscribing to postgres NOTIFY if you wanted to keep it closer to your DB layer (but that is async, and you may end up losing changes in the case of worker outages), or you could do it in your app where you would have more control over the transaction.
EDIT: I'm not associated with SpiceDB/Authzed in any way.
Disclaimer: I work on Debezium, an open-source CDC solution