You need to deploy a lightweight microservice that responds to HTTP requests, processes Pub/Sub messages, and runs scheduled jobs. Compare Cloud Functions (2nd gen) vs Cloud Run for this use case. When does each make sense, and how do they handle cold starts, concurrency, and VPC connectivity differently?
Quick Answer
Cloud Functions 2nd gen is built on Cloud Run but adds event triggers and simpler deployment for single-purpose functions. Cloud Run offers full container control, higher concurrency (up to 1000), longer timeouts (60 min), and multi-container support. Use Functions for event-driven glue code; Cloud Run for services.
Detailed Answer
Cloud Functions 2nd Gen Architecture
Cloud Functions 2nd gen is actually built on Cloud Run under the hood, which is why their capabilities have significantly converged. Functions 2nd gen support up to 60 minutes timeout, 16 GiB memory, 4 vCPUs, and concurrency up to 1000. The key differentiator is the developer experience: Functions provide built-in event triggers for Pub/Sub, Cloud Storage, Firestore, and 100+ Eventarc sources without writing subscriber code. You deploy source code (not a container), and Google builds the container automatically.
Cloud Run Advantages
Cloud Run accepts any container image, enabling you to use any language, runtime, or binary. It supports multi-container pods (sidecar pattern for proxies or log shippers), gRPC and WebSocket streaming, session affinity, startup/liveness probes, and volume mounts for secrets or shared storage. Cloud Run services can handle multiple URL paths, making them suitable for full web applications and API services with multiple endpoints. Cloud Run Jobs handle batch workloads with parallelism and retry configurations.
Cold Start Analysis
Both platforms experience cold starts when scaling from zero or scaling up. Cloud Functions cold starts include source code download, dependency installation, and runtime initialization—typically 1-5 seconds for Node.js/Python, 5-15 seconds for Java. Cloud Run cold starts depend entirely on your container image: optimized images with small base layers and pre-compiled binaries can cold start in under 1 second. Both support minimum instances to eliminate cold starts for latency-sensitive workloads, but you pay for idle instances.
Concurrency Model Differences
Cloud Functions 1st gen processes one request per instance. Functions 2nd gen and Cloud Run both support concurrent request processing—a single instance can handle multiple simultaneous requests, reducing the number of instances needed and improving cost efficiency. For CPU-bound workloads, set concurrency to match vCPU count. For I/O-bound workloads (database queries, API calls), concurrency of 50-80 is typical.
Decision Framework
Use Cloud Functions when: you need event-driven processing with minimal boilerplate, the function has a single responsibility, the team prefers deploying source code over managing Dockerfiles, or you need rapid prototyping. Use Cloud Run when: you need a multi-endpoint service, custom system dependencies, multi-container sidecars, WebSocket support, or container image portability across clouds. In practice, mature organizations often start with Functions and migrate to Cloud Run as services grow in complexity.