Is there any way to perform rollback in firebase cloud functions?

48
December 04, 2021, at 02:40 AM

We are running a larger backend application in NodeJS/TS on Firebase with about 180 cloud functions and Firestore as database. Firebase has been good for our needs so far, but we are getting to a level of usage where even small amounts of down-time can cause a lot of damage. Due to the amount of cloud functions a full deploy could take up to 30 minutes, we therefore usually only do partial deploys of changed functions only, which still take about 10 minutes. I am trying to find a way to be able to do quick rollback to previous version of a given function in case a bug is discovered after a production deploy. Firebase does not seem to provide rollback functionality, so the only option is to re-deploy the code with the previous version. One issue is the deploy time (up to 10 min for a single function), and the other is git versioning when there are partial deploys. Normally there would be a branch reflecting exactly what is in prod that could be used, but with partial deploys this is no longer the case. The only alternative for maintaining good git versioning with one to one branch with prod is to do a full deploy every time, but this takes a prohibitive amount of time (30+ minutes not including retries). The firebase deploy usually fail or exceed deployment quota as well, which makes things like CI pipelines very difficult (it would have to automatically retry failed functions, and the time is still an issue since 30+ min to deploy is not acceptable in the case of down-time). Has anyone found a good solution for roll-back (versioning) and a git structure that works well with firebase at scale?

Answer 1

Cloud Functions for Firebase is based on Cloud Functions and their behavior are the same. And today, it's not possible to route the traffic to a previous version (and to perform a rollback). (And I can also told you that NodeJS16 is now GA, instead of Beta as still mentioned in the Cloud Functions for Firebase documentation)

The next Cloud Functions runtime is cooking (and available in preview). That runtime is based on Cloud Run under the hood, that allow traffic splitting/routing, and therefore accept rollback.

So, for now, you haven't solution to perform a simple rollback with Firebase functions. A great change could be to use Cloud Functions V2 runtime directly, or event Cloud Run, but it's a big change in your code base.

Another solution could be to use a load balancer in front of all your functions and to:

  • Deploy new function under new name (no update of the current deployment, create a new service each time that you deploy a new version)
  • Create a new serverless backend with the new functions
  • Update the URL map to take into account the new backend.

After a while, delete the old function versions.

That also requires a lot of work to put that in action. And the advertising delay when you update your URL map should be between 3 and 5 minutes, not a such great advantage compare to your current solution.

Answer 2

it looks like your not the only one. previous questions answered. I recommend setting up some version control.I would solve the failing deploy issues first which should reduce the deploy time and redeploy times specifically if its multiple . You could use a different deploy branch or setup a staging environment as well. I would invest the time in getting the GIT control setup/turnkey.

Per user Ariel:


Each time you make a deploy to a cloud function you get an output line like this:
sourceArchiveUrl: gs://my-store-bucket/us-central1-function_name-xxoxtdxvxaxx.zip
I entered my Google Cloud Platform Developer Console -> Cloud Functions -> function_name -> Source tab
and there almost at the bottom it says: Source location
my-store-bucket/us-central1-function_name-xxoxtdxvxaxx.zip
the same as it was shown in the CLI, but without gs:// that link lead me to the following: https://storage.cloud.google.com/my-store-bucket/us-central1-function_name-........
I removed from the link everything that came after
https://storage.cloud.google.com/my-store-bucket
and that lead me to a huge list of files that each one of them represented a an image of all my cloud functions at the time point of each time i have made a deploy, exactly what i needed!
The only thing left to do was to locate the file with the last date before my mistaken deploy

source: Retrieving an old version of a Google Cloud function source

as of 2019 Rolling back to an older version of a firebase function (google cloud function)

2021: Roll back Firebase hosting and functions deploy jointly?

You can roll back a Firebase Hosting deployment, but not the functions without using a GIT Version control etc. Using partials you can deploy multiple functions/Groups. You can checkout remote config templates to rollback and its kept for up to 90 days.

https://firebase.google.com/docs/remote-config/templates

Firebase partial deploy multiple grouped functions

https://firebase.google.com/docs/cli#roll_back_deploys

READ ALSO
PHP Post callback Failed

PHP Post callback Failed

i am not getting php post callback to my file

50
Retrieve Iframe Height with Ajax Call

Retrieve Iframe Height with Ajax Call

I have found many questions here about getting iframe's height and set it via Javascript or jQuery however in my case none have workedI've installed MailChimp Plugin on a wordpress website to load the newsletters within tabs based on years and months

66
I don't understand how ListView works in Flutter?

I don't understand how ListView works in Flutter?

I have at the data area I/II/III

88
Trying to make a table that scrolls vertically, with a static section and a section that scrolls horizontally

Trying to make a table that scrolls vertically, with a static section and a section that scrolls horizontally

I am trying to use CSS to create a table with some specific traitsI want the table to scroll vertically, as there might be a lot of rows and I want to keep it within the view of the client's screen

65