When writing a relationship to spicedb,
# spicedb
r
When writing a relationship to spicedb, what is the point of specifying the operation: OPERATION_TOUCH instead of OPERATION_CREATE? Let's say i have a user 'John' that can access document X. Now i want to update this relationship and specify that John can instead access document Y. When using OPERATION_TOUCH, a new relation is created instead of updating the existing relation, which makes sense i guess because how would SpiceDB know if i want to add a new relation of update the existing one. The only situation when OPERATION_TOUCH would give a different result to OPERATION_CREATE is if i again try to add the relation: John can access document X. In which touch will not throw an exception but create will. But why would someone ever do this? The relation already exists
v
The point of TOUCH is making operations idempotent: if you run it several times, the outcome is the same. This is relevant when client applications need to rely in idempotency (for example when events come through Kafka and you rely on at-least-once delivery guarantees, hence events can be replayed). In you specific case, you are running a transaction that has TOUCH on the new resource and DELETE on the previous resource. If you ran that again, it would succeed, whereas doing it with CREATE wouldn't, because the document Y relationship already exists. You may have reasons to retry that operation: what if it timed out in its way back to the client? the transaction may have succeeded, but your client never got acknowledgement, so naturally it would retry it. TOUCH comes with disadvantages: it's more expensive to execute on the datastore.
also relationships against 2 different documents are 2 different relationships. The only way to "update a relationship" is by changing its caveat section.
r
Makes sense! Thanks for the quick reply!
45 Views