You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
GCP offers several serverless compute options that let you run code without managing infrastructure. This lesson covers Cloud Functions for event-driven functions and Cloud Run for containerised applications.
Serverless means you don't manage servers. GCP handles provisioning, scaling, patching, and availability. You focus on your code and pay only for what you use.
| Service | Unit of Deployment | Use Case |
|---|---|---|
| Cloud Functions | A single function | Event-driven, lightweight operations |
| Cloud Run | A container image | Any HTTP service, APIs, microservices |
| App Engine | An application | Web applications, full app lifecycle |
Cloud Functions is GCP's Functions-as-a-Service (FaaS) offering. Write a single-purpose function, deploy it, and GCP runs it in response to events.
| Runtime | Languages |
|---|---|
| Node.js | 16, 18, 20 |
| Python | 3.9, 3.10, 3.11, 3.12 |
| Go | 1.20, 1.21, 1.22 |
| Java | 11, 17, 21 |
| Ruby | 3.0, 3.2 |
| .NET | 6, 8 |
| PHP | 8.1, 8.2, 8.3 |
| Trigger | Event |
|---|---|
| HTTP | An HTTP request |
| Cloud Storage | Object created, deleted, archived, or metadata updated |
| Pub/Sub | Message published to a topic |
| Firestore | Document created, updated, deleted, or written |
| Cloud Audit Logs | Log entry matching a filter |
| Cloud Scheduler | Scheduled interval (cron) |
| Eventarc | Events from 130+ sources |
import functions_framework
@functions_framework.http
def hello(request):
name = request.args.get('name', 'World')
return f'Hello, {name}!'
Deploy:
gcloud functions deploy hello \
--gen2 \
--runtime=python312 \
--region=europe-west2 \
--trigger-http \
--allow-unauthenticated
| Feature | 1st Gen | 2nd Gen |
|---|---|---|
| Runtime | Cloud Functions only | Built on Cloud Run |
| Max timeout | 9 minutes | 60 minutes |
| Max instances | 1,000 | 1,000 (configurable) |
| Concurrency | 1 request per instance | Multiple requests per instance |
| Traffic splitting | No | Yes |
| Event sources | Limited | 130+ via Eventarc |
2nd Gen is recommended for all new functions.
| Component | Rate |
|---|---|
| Invocations | $0.40 per million |
| Compute time | Varies by memory/CPU allocated |
| Networking | Outbound data transfer charges |
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.