Cloud run to Cloud Function

I am new to Google cloud. But here is what I want to accomplish.
I have a next.js app that I am running on cloud run. This is internet facing app.
I have a database Google Cloud SQL.
I want to have business logic between next.js app and Cloud SQL. Should I use Cloud Functions or Cloud run?
The business logic layer, in future, will be accessed by mobile app (flutter).
Where should I use VPCs? Any info/links are much appreciated.

0 4 155
4 REPLIES 4

Cloud Functions are great if what you want to deploy is literally a function. Cloud Functions make is easy to set up event-driven triggering. If you do go with Cloud Functions, I recommend starting on the V2 version.

Cloud Run is more flexible and will make it slightly easier to expand what your business logic can do.

The two are quite similar in many ways. One way to decide may be to look what is more natively supported with the products you are integrating with (e.g. Flutter). Given that your app is on Cloud Run already, I'd probably stay with Cloud Run if I were you unless there's a specific reason to use Functions.

W.r.t. VPC: Cloud SQL needs to run in a VPC network. So you'll want to connect the Cloud Function or the Cloud Run service to the VPC network where CLoud SQL is in order to access the database over private IPs.

Thank @knet Given that function is backed up by cloudrun, it makes sense to use cloud run. But cloudrun uses containerized apps. This means I have to package everything so I can expose RESTful APIs - even if the business logic layer is supposed to be lightweight. But my object model is complicated and I want to use JSON rather than Cloud SQL (to save on cost basically). Since I am working on a startup why should I not use a super heavy function with parameterized switch statements which should be functions themselves? Can function integrate with IAM for AAA? I am finding it hard to find enough tutorial that is recent online.

Hello CookieKing02020,

It sounds like you have good reasons to prefer a function - use whatever makes most sense for your situation. You're saying that Cloud Functions will let you avoid writing a lot of boilerplate code and let you go faster, which makes perfect sense and is a common reason people choose Functions.

"Can functions inegrate with IAM"? Yes: https://cloud.google.com/functions/docs/securing/authenticating

Cloud Run with SQL auth proxy connector.

Highly recommended creating a landing zone with terraform to follow 12 factor app rules.