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

[FR] Admin version of the Firestore Lite SDK

Open GriffinJohnston opened this issue 2 years ago • 11 comments

The problem There is a longstanding issue with extremely slow cold-start times when using the official Nodejs Firestore library in serverless environments: https://issuetracker.google.com/issues/158014637. It appears that the underlying issue is very difficult to address (hence the unresolved years-old P1/S1 issue), and a proper interim fix is long overdue.

One solution is to use the Firestore REST API directly. This dramatically improves cold start times, but at the cost of a seriously degraded developer experience. There has been at least one attempt by a Firestore user to create an unofficial wrapper library (https://github.com/bountyrush/nodejs-firestore). This library works, but is maintained by a single developer, and is not a replacement for an official library for obvious reasons.

The solution A lightweight wrapper library that adds a friendly interface to the Firestore REST API for simple CRUD operations would do a lot to ameliorate the three year old cold start bug. Essentially a Nodejs equivalent of the Firestore Lite SDK. A Google employee has suggested that this library might even be able to share significant code with Firestore Lite: https://issuetracker.google.com/issues/158014637#comment183

GriffinJohnston avatar Aug 18 '22 20:08 GriffinJohnston

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 Aug 18 '22 20:08 google-oss-bot

As a note, this issue does not just affect cloud functions, but rather affects anything that needs to be cold-started. Reproduction samples work the same way on Docker containers hosted virtually anywhere, or when rebuilding an application during a live reload - the library itself appears to be the culprit, not the hosting environment.

bsplosion avatar Aug 18 '22 20:08 bsplosion

This would definitely help a lot of developers, however in our case we use a lot of transactions which seem to potentially be beyond the scope of a "lite" SDK. If we could get, either in addition to or instead of this, an official Google-maintained equivalent of https://github.com/bountyrush/nodejs-firestore it could help with that case. We really just want the speed of REST with the DX of the Admin SDK.

willbattel avatar Aug 18 '22 20:08 willbattel

Thanks for creating the issue, indeed it would definitely help a lot of us !

rodneyrd avatar Aug 18 '22 20:08 rodneyrd

I'm also interested in this, parsing an access token and calling firestore in a single request can take ages when cold on AWS lambda

ganey avatar Aug 18 '22 20:08 ganey

Much needed. Thank you.

nth-child avatar Aug 18 '22 20:08 nth-child

I'm the developer for REST api implementation - https://github.com/bountyrush/nodejs-firestore

I thought of giving a try with lite web js sdk but the links are broken for source code. Can someone point at the right link? https://cloud.google.com/firestore/docs/reference/libraries

manwithsteelnerves avatar Aug 19 '22 03:08 manwithsteelnerves

@manwithsteelnerves I think it's this? https://github.com/firebase/firebase-js-sdk/tree/master/packages/firestore/lite

ganey avatar Aug 19 '22 12:08 ganey

This was posted to the public issue but repeating here for visibility.

@google-cloud/firestore has begun experimenting with a preferRest option (@6.1.0-pre.0). Folks should give that a spin. I'm sure once it lands we'll look at exposing that option in firebase-admin, as this library wraps @google-cloud/firestore.

jamesdaniels avatar Sep 02 '22 17:09 jamesdaniels

I'm seeing a significant performance boost from this, which is very exciting. It will be even better if it ends up in firebase-admin, which will simplify usage and help prevent problems like this: https://github.com/googleapis/nodejs-firestore/issues/760

GriffinJohnston avatar Sep 03 '22 13:09 GriffinJohnston

@jamesdaniels now that preferRest is in google-cloud/firestore v6.2, can we get an update on exposing that option in firebase-admin? Should I open a new ticket for that, since this has evolved a bit?

GriffinJohnston avatar Sep 15 '22 01:09 GriffinJohnston

This feature is now available in firebase-admin v11.4.0. Thank you everyone for your patience!

lahirumaramba avatar Dec 15 '22 23:12 lahirumaramba

Amazing ;)

rodneyrd avatar Dec 15 '22 23:12 rodneyrd

We need to reopen this again. Now that Edge Functions are popular, we need Firebase Admin Lite SDK to be allowed to handle session variables and fetch calls with the admin key on the server.

J

jdgamble555 avatar Apr 20 '24 01:04 jdgamble555

PSA: Please continue discussion on this topic at https://github.com/firebase/firebase-admin-node/issues/2572

dconeybe avatar May 30 '24 20:05 dconeybe

+1

Rizzist avatar Jun 05 '24 15:06 Rizzist