ecomplus / application-starter

Serverless boilerplate for E-Com Plus apps (integrations) with Firebase Cloud Functions and GitHub Actions
MIT License
2 stars 3 forks source link

Concurrency with Cloud Functions for Firebase V2 #138

Open leomp12 opened 2 years ago

leomp12 commented 2 years ago

Is your feature request related to a problem? Please describe. Concurrency sometimes is important... E-Com Plus and integrated solutions webhooks may occur almost at the same time, and it comes with some problems to process status changes and other flows. Also, we like to be fast and cold starts are not cool 😛

Describe the solution you'd like

Our upcoming version of Cloud Functions uses Cloud Run as its underlying infrastructure. You'll see fewer cold starts because each function instance will now be able to handle 80 concurrent requests by default, as opposed to the current Cloud Functions for Firebase limit of 1.

With Cloud Functions 2nd gen we can enable concurrency, then receive many webhooks at the same execution to be able to control with easy "duplicated" webhooks:

const handlingIds = [];
if (!handlingIds.includes(resourceId)) {
  handlingIds.push(resourceId)
  /* await do stuff */
  const handlingIndex = handlingIds.indexOf(resourceId)
  handlingIds.splice(handlingIndex, -1)
}
// skip handling current webhook if same resource id already being treated

Describe alternatives you've considered https://github.com/ecomplus/application-starter/issues/137

Additional context Cloud Run seems to be the best of both Worlds, but we can deal with Firebase Alpha (private) features? It is still very important that partners can use this starter template with easy.

Update: public beta

leomp12 commented 2 years ago

Public beta now!

wisley7l commented 2 years ago

References

https://firebase.google.com/docs/functions/beta/get-started https://firebase.google.com/docs/functions/beta/config-env