I am currently evaluating different Google Cloud products in trying to set up an API for developers to use in a mobile app.
How should I evaluate thinking between:
- A single Cloud Function using Express.js to create multiple routes in an API (accessed via API Gateway), vs.
- A single Cloud Function per API endpoint (accessed via API Gateway)
Best answer by yuvalView original
Cloud Functions are based on Cloud Run. I like Cloud Run because you can build and run your own containers instead of having to think about supported environments in Cloud Functions.
Read “Getting started with API Gateway and Cloud Run”.
Regarding single Cloud Run service for multiple methods vs multiple Cloud Run services - consider resources usage by different methods, if you have a method that uses more memory or it is CPU intensive you might want to separate it to a different Cloud Run service with larger container size. You might want different scaling for different methods. You can also run each Cloud Run service using a separate service account with different roles - one service needs only permission to write to a specific GCS bucket and another needs permission to read a secret from Google Secret Manager.
have you checked
@yuval’s answer? What do you think? Does it answer to your question?
In case you need to better understand read the following post and watch the recording
There are a few considerations for a single service vs multiple services:
Scaling independently / permissions to access Google Cloud APIs from different services / implementing services with different languages or frameworks / segmenting ingress type - services that are accessed externally vs internally / authenticated services vs unauthenticated services / services egrees through VPC seeverless connector vs services that egress directly to the internet.