I have experience deploying new projects to Google Cloud Platform (GCP). We chose GCP because of regulations requiring our cloud services to be hosted in Indonesia. In this article, I will compare Cloud Functions, Cloud Run, Compute Engine, and Google Kubernetes Engine (GKE). Here are some key considerations to keep in mind when choosing Google Cloud Platform (GCP) services:
1. Overview
Service |
Description |
Cloud Functions |
Event-driven serverless compute for executing lightweight functions in response to triggers. |
Cloud Run |
Fully managed service for deploying containerized applications. Scales automatically based on traffic. |
Compute Engine |
Provides virtual machines (VMs) for running custom workloads with full control over the environment. |
Google Kubernetes Engine (GKE) |
Managed Kubernetes platform for orchestrating containerized applications. Supports scaling and advanced workloads. |
2. Use Cases
Service |
Best For |
Cloud Functions |
Lightweight tasks like processing events (e.g., file uploads or download, database updates). |
Cloud Run |
Microservices, APIs, and stateless workloads where you need fast deployment and scaling of containers. |
Compute Engine |
Workloads requiring custom VM configurations, persistent state, or high-performance computing. |
GKE |
Applications requiring advanced container orchestration, scaling, and flexibility. |
3. Deployment Model
Service |
Deployment Model |
Cloud Functions |
Deploys code directly as functions. GCP manages the runtime and scaling. |
Cloud Run |
Deploys containerized apps directly. You provide a container, and GCP manages the runtime environment. |
Compute Engine |
Provides full control over OS, libraries, and software. You manage deployments via SSH, scripts, etc. |
GKE |
Deploys containerized applications using Kubernetes YAML manifests. |
4. Scalability
Service |
Scalability |
Cloud Functions |
Automatically scales based on events. No manual configuration needed. |
Cloud Run |
Automatically scales instances up or down based on incoming traffic (zero to max instances). |
Compute Engine |
Requires manual configuration for scaling (e.g., managed instance groups or autoscaling policies). |
GKE |
Provides both manual and automatic scaling for pods and nodes. |
5. Pricing Model
Service |
Pricing |
Cloud Functions |
Pay-per-use: billed for execution time, invocations, and resources allocated. |
Cloud Run |
Pay-per-use: billed for CPU, memory, and request duration. |
Compute Engine |
Pay-per-VM or instance-hour usage. Reserved instances provide cost savings. |
GKE |
Pay-per-cluster and resources (VMs and nodes). Autopilot mode simplifies cost management. |
6. Management and Operations
Service |
Management |
Cloud Functions |
Fully managed by GCP; no server management required. |
Cloud Run |
Fully managed by GCP; minimal operational overhead. |
Compute Engine |
Requires manual management of OS, patches, and dependencies. |
GKE |
Partially managed; GCP handles the Kubernetes control plane, but you manage nodes and pods. |
7. Flexibility
Service |
Flexibility |
Cloud Functions |
Limited to supported runtimes (Node.js, Python, Go, etc.). |
Cloud Run |
Supports any language or runtime as long as it is packaged in a container. |
Compute Engine |
Most flexible: supports any OS, runtime, or application. |
GKE |
Highly flexible: supports diverse containerized workloads, complex orchestration, and hybrid setups. |
8. Cold Start
Service |
Cold Start Impact |
Cloud Functions |
Significant cold start impact for infrequently used functions. |
Cloud Run |
May experience cold starts when scaling from zero. |
Compute Engine |
No cold starts since VMs are always running (if configured). |
GKE |
Minimal cold start issues; pods are pre-provisioned when autoscaling is configured properly. |
9. Learning Curve
Service |
Learning Curve |
Cloud Functions |
Beginner-friendly; ideal for developers new to cloud. |
Cloud Run |
Easy to learn if familiar with containers. |
Compute Engine |
Moderate to steep; requires understanding of VM management and cloud infrastructure. |
GKE |
Steep; requires familiarity with Kubernetes concepts and container orchestration. |
10. Limitations
Service |
Key Limitations |
Cloud Functions |
Execution time limited to 9 minutes; not suitable for long-running tasks. |
Cloud Run |
Limited to stateless applications; dependent on containerized architecture. |
Compute Engine |
Requires manual setup and management, which can increase operational complexity. |
GKE |
Complex setup and management; overkill for simple applications. |
Bonus
- Cloud Run:
- To reduce cold start, can add always have 1 instance
- Compute Engine
- To reduce compute engine pricing, you can have scheduler to start and stop the compute engine on certain time.
- GKE
- GKE is running above compute engine, so you may see some compute engine running automatically