question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Firestore] Question: Recommendations for FirestoreClient / FirestoreDb lifecycle management for backend services

See original GitHub issue

Following @jskeet suggestion I have created separate issue.

Hi, I’m using Google.Cloud.Firestore package in version 1.0.0-beta22. What are current recommendations for lifecycle management of FirestoreDb / FirestoreClient especially for backend services?

I use Firestore in backend service to process telemetry data (intensive reads and writes are done there). Service is deployed in GCP GKE and I observe high latency there. I followed all best practices but still 99th percentile is over 200ms (for reads and writes). Such results were present when I had single FirestoreDb instance for each pod.

I achieved lower latency by using basic pool mechanism. Created specified number of FirestoreDbs and then fetch them in random way. All these FirebaseDbs are created using the same json credentials:

var client = new FirestoreClientBuilder { JsonCredentials = credentialsJson }.Build();
return FirestoreDb.Create(projectName, client);

Are there any other recommendations for backend services to achieve lower latency?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12

github_iconTop GitHub Comments

1reaction
jskeetcommented, Jul 25, 2019

Thanks for the extra detail. I probably won’t investigate this any further for now, but that will be useful if we ever come across this again.

Best of luck with your application, and I hope Bigtable works out well for you.

0reactions
pblachutcommented, Jul 26, 2019

Sorry for delay. We abandoned the idea of using Firestore in final solution, we have chosen to use Bigtable. Really appreciate your help and I think you have already answered my question.

I looked into the code which you have prepared and in comparision to ours there are few small differences.

  1. we used different api to add to batch document:
  • in our case: batch.Set(documentRef, document);
  • in your repro: batch.Create(documentRef, document);
  1. we measured time a little bit different (might not influence very much on results)
  1. Our pool was much more simpler:
EventHubClient GetEventHubClient()
        {
            var i = _rand.Next(0, _eventHubClients.Length);
            return _eventHubClients[i];
        }
  1. Each firestoredb was created differently in our case;
FirestoreDb CreateFirestoreDb()
            {
                var client = new FirestoreClientBuilder { JsonCredentials = credentialsJson }.Build();

                return FirestoreDb.Create(projectName, client);
            }

Please remember that we observed differences when the pooling was turned on. Higher latency was observed when we used single firestoredb.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Best practices for Cloud Firestore - Firebase
Use the best practices listed here as a quick reference when building an application that uses Cloud Firestore. Database location.
Read more >
Create a Firestore database by using a server client library
This quickstart shows you how to set up Firestore, add data, and read data by using the C#, Go, Java, Node.js, PHP, Python,...
Read more >
Server-side access to Firestore and security rules
"The server client libraries bypass all Cloud Firestore Security Rules and instead authenticate through Google Application Default Credentials.
Read more >
7 tips on Firebase security rules and the Admin SDK
The backend services use security rules to authorize and validate the requests made by client apps, and make sure they adhere to the...
Read more >
Why Firestore, Part III: 6 Things You Need to Know Before ...
This is the final article from a series where we comprehensively describe the pros and cons of using Firestore as the backend solution...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found