Search code examples
firebasegoogle-cloud-firestoretransactionspessimistic-locking

How to run Firestore server-side pessimistic lock transactions in a project using Dart


I created a library in Dart based on the premise of running pessimistic lock transactions in the Firebase server client library, but I found that the Firebase Admin SDK required to run it does not support Dart.

And I found a library called Dartfire to use the Firebase Admin SDK with Dart, but as far as I could tell, server-side pessimistic lock transaction of Firestore seemed to be outside the scope of the support.(There's a possibility I'm wrong.)

For the Cloud Firestore REST API, I couldn't find any documentation that mentions server-side pessimistic locking.

Is there any way to use transactions with server-side pessimistic locks in a way that makes use of the library I have already created with Dart?

Or do I have to rewrite it all in another language that is supported by Firebase Admin SDK?


Solution

  • Looking at the RPC API docs here, I'd expect that:

    • the admin endpoints use pessimistic locking and
    • the non-admin endpoints use optimistic locking

    From searching the code, it seems that Firedart uses the non-admin endpoints - so indeed will use optimistic locking.

    A quick further search of the RPCAPI docs for the Admin RPC endpoint confirms that it defaults to pessimistic locking for transactions, but also shows that you can specify the concurrency mode.

    Since you're using Firedart, it seems that you're bound to optimistic locking. Considering filing a feature request (or even better: a PR) for adding admin bindings (as an option) to Firedart.