Deciding Between Cloud Run and Cloud Functions on GCP
📖 Scenario: You are working as a cloud engineer for a small company. Your team needs to deploy a new service that processes user requests. You want to choose the right Google Cloud service between Cloud Run and Cloud Functions.Cloud Run lets you run containerized applications that can handle many requests at once. Cloud Functions lets you run small pieces of code that respond to events.
🎯 Goal: Build a simple decision helper using Python that helps decide whether to use Cloud Run or Cloud Functions based on the service requirements.
📋 What You'll Learn
Create a dictionary with service requirements
Add a configuration variable for maximum concurrent requests
Write logic to decide between Cloud Run and Cloud Functions
Output the final decision as a string
💡 Why This Matters
🌍 Real World
Choosing the right cloud service helps optimize cost and performance for deploying applications.
💼 Career
Cloud engineers and developers often decide between serverless functions and containerized services based on workload characteristics.
Progress0 / 4 steps
1
Create service requirements dictionary
Create a dictionary called service_requirements with these exact entries: 'max_requests_per_second': 100, 'needs_container': True, 'event_driven': False
GCP
Hint
Use a Python dictionary with the exact keys and values given.
2
Add max concurrency configuration
Create a variable called max_concurrent_requests and set it to 80
GCP
Hint
This variable will help decide if Cloud Run can handle the load.
3
Write decision logic
Write an if statement that sets a variable decision to 'Cloud Run' if service_requirements['needs_container'] is True or service_requirements['max_requests_per_second'] is greater than max_concurrent_requests. Otherwise, set decision to 'Cloud Functions'
GCP
Hint
Use an if-else block with the exact variable names and conditions.
4
Output the final decision
Add a variable called final_decision and set it equal to the decision variable
GCP
Hint
This variable holds the final choice for deployment service.
Practice
(1/5)
1. Which Google Cloud service is best suited for running simple event-driven code without managing servers?
easy
A. Compute Engine
B. Cloud Run
C. Cloud Functions
D. App Engine
Solution
Step 1: Understand event-driven code needs
Simple event-driven code triggers automatically on events and requires minimal setup.
Step 2: Match service to event-driven model
Cloud Functions is designed for event-driven code without server management.
2. Which of the following is the correct way to deploy a container image to Cloud Run using gcloud CLI?
easy
A. gcloud run deploy SERVICE --image IMAGE_URL --platform managed
B. gcloud functions deploy SERVICE --image IMAGE_URL
C. gcloud compute instances create SERVICE --image IMAGE_URL
D. gcloud app deploy SERVICE --image IMAGE_URL
Solution
Step 1: Identify correct command for Cloud Run deployment
Cloud Run uses 'gcloud run deploy' with --image and --platform flags.
Step 2: Eliminate incorrect commands
Functions, Compute, and App Engine use different commands and flags.
Final Answer:
gcloud run deploy SERVICE --image IMAGE_URL --platform managed -> Option A
Quick Check:
Cloud Run deploy = gcloud run deploy [OK]
Hint: Cloud Run deploy uses 'gcloud run deploy' with --image [OK]
Common Mistakes:
Using 'gcloud functions deploy' for Cloud Run
Confusing Compute Engine commands with Cloud Run
Omitting --platform flag for Cloud Run
3. Given this scenario: You have a containerized app that needs to handle HTTP requests with custom runtime and environment variables. Which service will work correctly?
1. Deploy container to Cloud Run
2. Set environment variables in deployment
3. App handles HTTP requests
medium
A. Cloud Functions only
B. Cloud Run only
C. Both Cloud Run and Cloud Functions
D. Neither Cloud Run nor Cloud Functions
Solution
Step 1: Check container support and environment variables
Cloud Run supports containerized apps and environment variables; Cloud Functions has limited container support and environment variable use.
Step 2: Match HTTP handling with service capabilities
Cloud Run is designed for HTTP container apps with custom runtimes; Cloud Functions is for simpler functions.
Final Answer:
Cloud Run only -> Option B
Quick Check:
Container + env vars + HTTP = Cloud Run [OK]
Hint: Containerized HTTP app? Use Cloud Run [OK]
Common Mistakes:
Assuming Cloud Functions supports full container apps
Ignoring environment variable support differences
Thinking both services handle custom runtimes equally
4. You tried deploying a container to Cloud Functions but got an error. What is the likely cause?
medium
A. Cloud Functions requires source code, not containers
B. Cloud Functions requires container images from Container Registry
C. Cloud Functions supports containers but only with specific runtimes
D. Cloud Functions supports containers only in beta
Solution
Step 1: Understand Cloud Functions deployment model
Cloud Functions deploys source code or zipped code, not container images directly.
Step 2: Identify cause of deployment error
Trying to deploy a container image causes error because Cloud Functions expects source code.
Final Answer:
Cloud Functions requires source code, not containers -> Option A
Quick Check:
Cloud Functions deploys source code only [OK]
Hint: Cloud Functions deploys code, not containers [OK]
Assuming all serverless services accept containers
5. Your team needs to deploy a microservice that requires custom libraries, runs on HTTP, and must scale automatically. You want to avoid managing servers but need full control over the runtime environment. Which service should you choose and why?
hard
A. Compute Engine, because it offers full control and automatic scaling
B. Cloud Functions, because it scales automatically and supports custom runtimes
C. App Engine Standard, because it supports custom libraries and auto-scaling
D. Cloud Run, because it runs containerized apps with full runtime control and auto-scaling
Solution
Step 1: Analyze requirements for runtime control and scaling
Need full runtime control and automatic scaling without managing servers.
Step 2: Match service capabilities
Cloud Run runs containerized apps with full control and auto-scales; Cloud Functions has limited runtime control; App Engine Standard has restrictions; Compute Engine requires server management.
Final Answer:
Cloud Run, because it runs containerized apps with full runtime control and auto-scaling -> Option D
Quick Check:
Custom runtime + auto-scale + no servers = Cloud Run [OK]
Hint: Full control + auto-scale? Pick Cloud Run [OK]
Common Mistakes:
Choosing Cloud Functions for full runtime control
Confusing App Engine Standard with container support
Selecting Compute Engine despite server management needs
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.