-
Notifications
You must be signed in to change notification settings - Fork 646
Description
What feature would you like to see?
When trying to read data from multiple documents, collections or queries, we'd like to perform those requests within a single transaction. The gRPC API allows for beginning a read-only transaction and passing an identifier to GetDocument, RunQuery, ListDocuments, etc.
How would you use it?
Our application makes use of state that exists in a global document per customer, and a few sub-collections. One of those sub-collections state is directly tied to the global document. Without a consistent read of both the document and sub-collection, we could end up with an inconsistent rendering of our UI. Since the current client just does BatchRead within a transaction for each .get() with no transaction identifier, we expect the values can drift. Similarly, we can't rely on listeners because it is not guaranteed that when we get listen events for both the sub-collection and document that we're at a consistent state.
The system during busy hours will have writes in a bursty behavior but will be close in time. Getting a consistent view when we go to fetch data is paramount for our customers to see the right rendering.
Exploratory work
Given the gRPC API is already stubbed into the SDK, I was able to add a top level method called readTransaction that operated very similar to the current write transaction. It first starts the transaction and provides methods like .get(), .list(), .query() that makes use of the Firestore objects. Given the existing Query object mimic/generates a similar form as the StructuredQuery object, it wasn't that difficult to use the same existing API and just use a different transform in the ReadTransaction class.
We're today using the REST API in conjunction with this SDK to solve our use case.
Thanks!