3

So I am developing a Firebase function that accepts requests from users and updates few nodes under a branch these users are listening to.

My issue is if the function receives two client requests at the same time, that triggers two functions to execute and update the data at the same time.

I know this is typically solved by a transaction, but my updates are done on various nodes not only one value (i.e counter).

In a traditional multi-threading programming, this problems is solved by locking the code from executing so it can only be executed by one thread, where the next one resumes when the current one finishes.

Is this an option in Firebase Functions? If so, how can it be done?

masood elsad
  • 396
  • 1
  • 4
  • 18

1 Answers1

3

There is currently no threading in Cloud Functions in any environment, both node and python included. You should not be depending on process level locking in Cloud Function - use a database transaction to ensure that updates are atomic and consistent. Each of your function invocations is going to be completely isolated from each other.

Doug Stevenson
  • 236,239
  • 27
  • 275
  • 302