firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

[Firestore] Very slow GET requests

Open spock123 opened this issue 6 months ago • 6 comments

[REQUIRED] Step 2: Describe your environment

  • Operating System version: Linux
  • Firebase SDK version: 13.4.0
  • Firebase Product: Firestore
  • Node.js version: 22
  • NPM version: 10.9.2

[REQUIRED] Step 3: Describe the problem

We have simple Firestore queries, filtering on simple properties. When fetching from backend (nodejs), it takes a very very long time. Same query using frontend libraries takes 1% of the time.

Explain query shows that the backend query is fast, but the result takes forever to download.

If we use Firebase frontend client libraries, the same query result is loaded 50x faster.

As an example, a query with result set of 100 documents took 4 seconds to fetch with firebase-admin 1000 documents took 21 seconds to fetch with firebase-admin

This is not a network issue, as we can run the same queries on backend and frontend from same hardware, and get 50x faster results in the client libary, compared to firebase-admin.

Any idea what it could be?

It is NOT the query that is the issue, using tools we can see that correct index is used. We can also see that result set is streamed right away.

But the actual fetching of result data takes forever with this library.

Thanks in advance

Here is a snippet from a query with result set of 1000. We can see that result is immediately starting to download.

Firestore (7.11.0) 2025-06-09T14:36:33.255Z CNebO [ClientPool.acquire]: Creating a new client (requiresGrpc: false)
Firestore (7.11.0) 2025-06-09T14:36:33.310Z ##### [clientFactory]: Initialized Firestore GAPIC Client (useFallback: rest)
Firestore (7.11.0) 2025-06-09T14:36:33.311Z CNebO [Firestore.requestStream]: Sending request: {"parent":"projects/fastorder-prod/databases/(default)/documents/company/gorilla","structuredQuery":{"from":[{"collectionId":"orders"}],"where":{"fieldFilter":{"field":{"fieldPath":"orderStatus"},"op":"NOT_EQUAL","value":{"stringValue":"ARCHIVED"}}},"limit":{"value":2}}}
Firestore (7.11.0) 2025-06-09T14:36:34.856Z CNebO [Firestore.requestStream]: Received response: {"document":{"fiel.... rest of result set

spock123 avatar Jun 09 '25 14:06 spock123

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Jun 09 '25 14:06 google-oss-bot

Hi @spock123 , thanks for reporting. The only thing that comes to mind is that we had an inefficient UTF-8 string comparison logic. We have implemented a fix (https://github.com/googleapis/nodejs-firestore/pull/2380), which hasn't been released yet (https://github.com/googleapis/nodejs-firestore/pull/2381). Once this is released, you can update the @google-cloud/firestore dependency in your project to make sure you get the fix.

I'll leave this issue open until we release the fix (work in progress)

ehsannas avatar Jul 15 '25 04:07 ehsannas

The fix has been released (https://github.com/googleapis/nodejs-firestore/releases/tag/v7.11.3). Please update your @google-cloud/firestore dependency and let us know if that resolves the issue for you. Thanks

ehsannas avatar Jul 16 '25 16:07 ehsannas

I am facing this exact same issue, using a simple db.collection('users').doc(uid).get() will take 2 seconds from firebase-admin from my node server, but just 50ms if I do the same from the client (react-native-firebase)

@ehsannas I am using firebase-admin v13.4.0 (latest one), is your fix already implemented in that one?

pierroo avatar Aug 04 '25 07:08 pierroo

This package (firebase-admin) package has an optional dependency on @google-cloud/firestore which hasn't been updated yet. But I think if you npm install @google-cloud/firestore in your project to the latest version, you should get the fix. (the fix was in 7.11.3)

ehsannas avatar Aug 04 '25 20:08 ehsannas

Unfortunately no luck @ehsannas , still crazy slow (~1 second for a simple db.collection('users').doc(uid).get()) and still taking just 50ms when done from the client...

and I can confirm firebase-admin is using @google-cloud/[email protected] as per npm list @google-cloud/firestore

pierroo avatar Aug 05 '25 07:08 pierroo