0

This is a design question about the handling of tasks during the shutdown of a firebase-queue based app running on Google Compute Engine.

The use case I am working with is automatically scaling queue-workers depending on the load at any given time. Specific to our project is the fact that our tasks are long-running.

In an ideal world, the queue worker would have an opportunity to finish its current tasks before the virtual machine running the worker is terminated. We are working with Google Compute Engine / instance groups to handle the scaling of our queue worker app. Firebase-queue does provide a promise based method to shutdown a queue worker (i.e. queue.shutdown()). This will stop the worker from accepting new tasks and will allow running tasks to finish prior to resolving the promise.

The problem I am facing is how to allow the queue worker to shutdown gracefully prior to instance termination (this problem would also occur during a rolling update). One way is to trigger the worker shutdown and have the worker trigger instance shutdown, but this does not seem like the best design because control is taken away from whatever service is triggering the scale down in the first place.

GCE does provide a service which will run a shutdown script prior to instance termination, however, it will forcefully shutdown an instance after about 90 seconds, which does not work for us.

I am interested in design ideas / patterns to follow here. Any help is much appreciated.

  • Consider replacing firebase-queue with Cloud Functions and offloading your long running work to GAE or Compute Engine via pubsub messages. – Doug Stevenson Mar 13 '18 at 18:12
  • Thanks @DougStevenson. Pub/Sub seems like a replacement for the firebase-queue that is more feature rich, seemingly because it is part of the Google Cloud Platform ecosystem. A few highlights after looking into it are: the ability to scale GAE / GCE instances based on pub/sub queue length, ability to verify whether an instance has a task (to avoid terminating an instance while a long running task is ongoing), and operational flexibility with topics (delegating specific tasks to different subscribers / instance types/groups). Is my understanding on the right track in your opinion? – Jamieson Bates Mar 13 '18 at 19:33
  • If you want to run some code in response to a change in the database, you'll need Cloud Functions. But if you can send messages directly to the backend, that's fine too. Whatever works for your architecture. – Doug Stevenson Mar 13 '18 at 19:36

0 Answers0