Hi all, is there any suggestion how to
# spicedb
r
Hi all, is there any suggestion how to handle race condition when writing relationship to spice db. I'm using java..when relationship is missing, user wont able to see the document. and I want my system able to recover before user find out the issue. For now Im thinking to create scheduler to check if relationship failed to create, then create for them. Thanks
v
👋 you refer to "race condition", but I think you are discussing more generally integrity here, where SpiceDB does not reflect the state of your main database? Is the problem that your application is failing to write in certain occasions to SpiceDB? This is typically a problem that happens more often when folks do dual-writes: write to main DB + write to SpiceDB. This approach is, by definition, not atomic, so there is always a chance you end up with a situation where one of the writes succeeded and the other failed. There are various was to address this. One is to adopt a Durable Workflow engine. A durable workflow engine makes sure that a multi-transaction business operation eventually completes or completely rollsback. For example, we've successfully used https://github.com/cschleiden/go-workflows in some internal projects to write to two systems of record and maintain integrity. https://www.golem.cloud/post/the-emerging-landscape-of-durable-computing is also a good write up. Another option folks like is transaction log tailing, where you read the WAL from your database and issue SpiceDB writes from them. There are myriads of projects to support this, a popular project here is Debezium. Othe folks have done what you suggest, an "anti-entropy repair", which is essentially a job that goes over the origin database and repairs any inconsistencies on the application. We have customers doing this too.
r
hi @vroldanbet , thanks for your reply. yes, I use two DBs. first, save the document metadata to mainDB, and then write the document relationship in spicedb. thanks also for your reference links.I'm going to have a look at it
b
Another option if you're ok with eventual consistency is to use something like kafka, have one consumer write to the DB and another write to SpiceDB
v
Yes, if you are in an Event Driven Architecture, that works! It's similar to transaction log tailing, except the events are business events, instead of database events