🔵

Google Cloud Platform Intermediate

Build on Google Cloud: Cloud SQL and Firestore, Cloud Functions and Cloud Run, GKE, load balancing, VPC, monitoring and IaC.

21 lessons 63 quiz questions
Lessons & quizzes Certificate

📚 Lessons & quizzes

Each lesson ends with its own short quiz. Answer them as you go — score 90% across all lessons to earn your certificate.

1 Cloud SQL — Managed Relational Databases

Cloud SQL is Google Cloud’s fully managed relational database service, supporting MySQL, PostgreSQL, and SQL Server. Google handles patching, backups, replication, and failover, so you focus on schema and queries rather than running the engine yourself.

Key features include automated backups and point-in-time recovery, high availability (HA) via a synchronously replicated standby in a second zone, and read replicas to scale read traffic. You connect securely through the Cloud SQL Auth Proxy or with private IP over your VPC.

Cloud SQL is best for transactional (OLTP) workloads up to tens of terabytes. For very large, globally distributed relational needs with horizontal scaling, you would reach for Cloud Spanner instead. Choose the machine type and storage to match your workload, and enable HA for production.

# Create a PostgreSQL instance with high availability
gcloud sql instances create shop-db \
  --database-version=POSTGRES_15 \
  --tier=db-custom-2-7680 \
  --region=europe-north1 \
  --availability-type=REGIONAL

# Create a database and a read replica
gcloud sql databases create orders --instance=shop-db
gcloud sql instances create shop-db-replica \
  --master-instance-name=shop-db --region=europe-north1

2 Firestore — Serverless Document NoSQL

Firestore is a fully managed, serverless document database. Data lives in documents (sets of key-value fields) organised into collections. It scales automatically, offers strong consistency, and provides real-time listeners that push changes to clients — ideal for web and mobile apps.

Firestore runs in Native mode (the modern API with real-time updates and offline support) or Datastore mode (compatible with the older Datastore API). You query by field values and build composite indexes for multi-field queries. Pricing is based on document reads, writes, deletes, and stored data.

Firestore shines for hierarchical, semi-structured data and apps needing live synchronisation. It is not designed for analytical scans over huge tables — for that you would use BigQuery or Bigtable.

# Create a Firestore database in Native mode
gcloud firestore databases create \
  --location=eur3 \
  --type=firestore-native

# Export a collection to Cloud Storage for backup
gcloud firestore export gs://my-backups/firestore \
  --collection-ids=users,orders

3 Cloud Bigtable — Wide-Column NoSQL at Scale

Cloud Bigtable is a fully managed, wide-column NoSQL database built for massive analytical and operational workloads — think time-series data, IoT telemetry, financial ticks, and ad-tech. It delivers single-digit millisecond latency at very high throughput and scales to petabytes.

Bigtable stores rows sorted by a single row key; there are no secondary indexes or joins. Designing the row key well (to spread writes and group related reads) is the most important performance decision. It is compatible with the HBase API and integrates with Dataflow, Dataproc, and BigQuery.

Use Bigtable when you need sustained high read/write throughput on huge datasets. For small datasets or rich document queries, Firestore is simpler and cheaper.

# Create a Bigtable instance and table
gcloud bigtable instances create sensors \
  --display-name="Sensor Data" \
  --cluster-config=id=sensors-c1,zone=europe-north1-a,nodes=3

gcloud bigtable instances tables create readings \
  --instance=sensors --column-families=metrics

4 Cloud Functions — Event-Driven Serverless

Cloud Functions runs small, single-purpose pieces of code in response to events without you managing servers. A function can be triggered by an HTTP request, a Pub/Sub message, a Cloud Storage object change, or other event sources. You pay only for execution time and invocations.

2nd-generation Cloud Functions are built on Cloud Run and Eventarc, giving longer timeouts, larger instances, concurrency, and more event sources. Functions scale to zero when idle and scale out automatically under load.

They are ideal for glue logic: resizing an uploaded image, processing a queue message, or responding to a webhook. For long-running services or full containers, Cloud Run is the better tool.

# Deploy a 2nd-gen HTTP function (Node.js)
gcloud functions deploy resize-image \
  --gen2 \
  --runtime=nodejs20 \
  --region=europe-north1 \
  --trigger-http \
  --entry-point=resize \
  --allow-unauthenticated

5 Cloud Run — Serverless Containers

Cloud Run runs stateless containers in a fully managed, serverless environment. You package your app as a container image, deploy it, and Cloud Run handles scaling — including scale to zero — and gives you an HTTPS endpoint automatically. You bring any language or framework that listens on a port.

Cloud Run supports concurrency (many requests per container instance), configurable CPU and memory, request and event triggers, and gradual traffic splitting between revisions for safe rollouts. Each deploy creates an immutable revision.

Choose Cloud Run when you want serverless economics with full container flexibility, more control than Cloud Functions, but without managing a Kubernetes cluster like GKE.

# Deploy a container image to Cloud Run
gcloud run deploy api \
  --image=europe-north1-docker.pkg.dev/my-proj/apps/api:1.0 \
  --region=europe-north1 \
  --concurrency=80 \
  --max-instances=10 \
  --allow-unauthenticated

# Split traffic 90/10 between revisions for a canary
gcloud run services update-traffic api \
  --to-revisions=api-00002=10,api-00001=90

6 App Engine — Managed Application Platform

App Engine is Google’s original platform-as-a-service (PaaS) for running web applications without managing infrastructure. It comes in two environments: standard (fast-starting sandboxed runtimes that scale to zero) and flexible (apps run in containers on managed Compute Engine VMs, allowing custom runtimes).

You configure the app with an app.yaml file describing the runtime, scaling, and routing. App Engine supports versions and traffic splitting, and an app can have multiple services (formerly modules) that together form one application.

App Engine suits classic web apps and APIs where you want automatic scaling and minimal operations. For container-first serverless, many teams now choose Cloud Run, which shares much of the same underlying technology.

# A minimal app.yaml for the standard environment
# runtime: python312
# instance_class: F1

# Deploy the current directory and split traffic
gcloud app deploy app.yaml --version=v2 --no-promote
gcloud app services set-traffic default \
  --splits=v2=0.2,v1=0.8 --split-by=random

7 Google Kubernetes Engine (GKE)

Google Kubernetes Engine (GKE) is a managed Kubernetes service. Google operates the control plane (API server, scheduler, etcd) while you run workloads on nodes grouped into node pools. GKE handles upgrades, auto-repair, and integration with Google Cloud networking and IAM.

GKE offers two modes: Standard, where you manage and pay for nodes, and Autopilot, where Google provisions and bills per-Pod resources for a hands-off experience. Features include cluster autoscaling, the horizontal Pod autoscaler, and Workload Identity for secure access to Google APIs.

Use GKE when you need full Kubernetes — complex microservices, custom controllers, or portability — and are willing to manage more than Cloud Run requires.

# Create an Autopilot cluster
gcloud container clusters create-auto prod-cluster \
  --region=europe-north1

# Get credentials and deploy
gcloud container clusters get-credentials prod-cluster \
  --region=europe-north1
kubectl create deployment web --image=nginx

8 Artifact Registry — Storing Images and Packages

Artifact Registry is Google Cloud’s managed repository for container images and language packages (Maven, npm, Python, and more). It is the successor to Container Registry and offers regional repositories, fine-grained IAM, and vulnerability scanning.

You create a repository, authenticate Docker against the regional host (for example europe-north1-docker.pkg.dev), then push and pull images. GKE, Cloud Run, and Cloud Functions all pull images from Artifact Registry, and Cloud Build can push to it as part of CI/CD.

Keeping images in a regional repository close to your runtime reduces pull latency and egress, and IAM lets you grant least-privilege read or write access per repository.

# Create a Docker repository
gcloud artifacts repositories create apps \
  --repository-format=docker \
  --location=europe-north1

# Authenticate Docker and push an image
gcloud auth configure-docker europe-north1-docker.pkg.dev
docker push europe-north1-docker.pkg.dev/my-proj/apps/api:1.0

9 Cloud Load Balancing — Global and Regional

Cloud Load Balancing distributes traffic across backends for availability and scale. The global external Application Load Balancer serves HTTP(S) traffic from a single anycast IP, routing users to the nearest healthy backend worldwide and supporting URL maps, SSL, and Cloud CDN.

For non-HTTP traffic there are network load balancers (TCP/UDP), which can be passthrough (preserving client IPs) or proxy-based. Backends can be managed instance groups, network endpoint groups (NEGs) for serverless or containers, and health checks remove unhealthy backends automatically.

Choose a global Application Load Balancer for worldwide web apps and a regional or network load balancer for regional or non-HTTP workloads.

# Reserve a global IP and create a backend service
gcloud compute addresses create web-ip --global
gcloud compute backend-services create web-backend \
  --global \
  --protocol=HTTP \
  --health-checks=web-hc

10 Managed Instance Groups and Autoscaling

A managed instance group (MIG) runs identical VM instances from an instance template. The MIG keeps the desired number of instances running, recreates failed ones (autohealing), and can span multiple zones for resilience. MIGs are the standard backend for load balancers on Compute Engine.

Autoscaling adds or removes instances based on signals such as average CPU utilisation, load-balancing capacity, or custom Cloud Monitoring metrics. You set minimum and maximum sizes and a target utilisation, and the autoscaler adjusts within those bounds.

MIGs also enable rolling updates: you change the template and roll the new version across instances gradually, with surge and unavailable limits to protect availability.

# Create a MIG with autoscaling on CPU
gcloud compute instance-groups managed create web-mig \
  --template=web-template \
  --size=2 \
  --region=europe-north1

gcloud compute instance-groups managed set-autoscaling web-mig \
  --region=europe-north1 \
  --min-num-replicas=2 --max-num-replicas=10 \
  --target-cpu-utilization=0.6

11 VPC Design — Shared VPC, Peering, Private Access

A Virtual Private Cloud (VPC) on Google Cloud is global: one VPC spans all regions, with subnets that are regional. Three patterns connect and structure networks. Shared VPC lets a host project share its network with service projects, centralising network administration while teams deploy into their own projects.

VPC Network Peering privately connects two VPCs (even across organisations) so resources communicate using internal IPs, without a gateway or VPN. Peering is non-transitive: if A peers with B and B with C, A and C are not connected.

Private Google Access lets VMs without external IPs reach Google APIs and services (like Cloud Storage) over Google’s internal network, improving security by keeping traffic off the public internet.

# Enable Private Google Access on a subnet
gcloud compute networks subnets update prod-subnet \
  --region=europe-north1 \
  --enable-private-ip-google-access

# Peer two VPC networks
gcloud compute networks peerings create to-data \
  --network=app-vpc --peer-network=data-vpc

12 Cloud NAT and Cloud DNS

Cloud NAT provides managed network address translation so VMs and GKE nodes without external IPs can make outbound connections to the internet (for updates, package downloads, or APIs). It does not allow unsolicited inbound connections, which improves security by keeping instances private.

Cloud DNS is a scalable, managed Domain Name System service. You create managed zones — public zones for internet-facing names and private zones resolvable only within your VPC — and add record sets (A, AAAA, CNAME, MX, TXT). Cloud DNS offers high availability and low-latency, anycast-served resolution.

Together, Cloud NAT keeps instances private while still allowing egress, and Cloud DNS gives you authoritative name resolution for public and internal services.

# Create a Cloud Router and Cloud NAT for egress
gcloud compute routers create nat-router \
  --network=app-vpc --region=europe-north1
gcloud compute routers nats create app-nat \
  --router=nat-router --region=europe-north1 \
  --auto-allocate-nat-external-ips \
  --nat-all-subnet-ip-ranges

# Create a private DNS zone
gcloud dns managed-zones create internal \
  --dns-name=corp.internal. --visibility=private \
  --networks=app-vpc

13 Cloud CDN — Content Delivery

Cloud CDN caches your content at Google’s globally distributed edge points of presence, serving users from a location near them. It works with the global external Application Load Balancer: you enable CDN on a backend service or backend bucket, and cacheable responses are stored at the edge.

Caching is governed by HTTP Cache-Control headers and cache modes (for example cache static content or use origin headers). Cloud CDN reduces latency for users, lowers load on your origin, and cuts egress cost. You can invalidate cached objects when content changes.

Pair Cloud CDN with a backend bucket (Cloud Storage) for static assets, or with a compute backend for dynamic apps that still have cacheable responses.

# Enable Cloud CDN on a backend service
gcloud compute backend-services update web-backend \
  --global \
  --enable-cdn \
  --cache-mode=CACHE_ALL_STATIC

# Invalidate a cached path after a deploy
gcloud compute url-maps invalidate-cdn-cache web-map \
  --path="/static/*"

14 IAM Deeper — Roles and Service Accounts

Google Cloud IAM grants members (users, groups, service accounts) roles on resources. A role is a bundle of permissions. Basic roles (Owner, Editor, Viewer) are broad and discouraged for production. Predefined roles are curated per-service (e.g. roles/storage.objectViewer) and follow least privilege. Custom roles let you assemble exactly the permissions you need when no predefined role fits.

A service account is a non-human identity used by applications and workloads. Prefer granting roles to service accounts and, on GKE, use Workload Identity to bind Kubernetes service accounts to Google service accounts, avoiding long-lived key files.

IAM policies are inherited down the resource hierarchy (organisation → folder → project → resource), so a grant at a higher level applies below it.

# Grant a predefined role to a service account
gcloud projects add-iam-policy-binding my-proj \
  --member="serviceAccount:app@my-proj.iam.gserviceaccount.com" \
  --role="roles/storage.objectViewer"

# Create a custom role from a definition file
gcloud iam roles create deployer --project=my-proj \
  --file=deployer-role.yaml

15 Secret Manager and Cloud KMS

Secret Manager stores sensitive values — API keys, passwords, certificates — as secrets with automatically managed versions. Access is governed by IAM, every access can be audit-logged, and apps fetch secrets at runtime rather than baking them into images or code. You can pin to a specific version or use latest.

Cloud KMS (Key Management Service) manages cryptographic keys used for encryption and signing. Keys live in key rings, support rotation, and can be software-backed or HSM-backed. KMS underpins customer-managed encryption keys (CMEK), letting you control the keys that protect data in services like Cloud Storage and BigQuery.

Use Secret Manager for secrets your app reads, and KMS when you need to manage the encryption keys themselves or sign data.

# Create a secret and add a version
gcloud secrets create db-password --replication-policy=automatic
echo -n "s3cr3t" | gcloud secrets versions add db-password --data-file=-

# Create a KMS key ring and key with rotation
gcloud kms keyrings create app-keys --location=europe-north1
gcloud kms keys create data-key --keyring=app-keys \
  --location=europe-north1 --purpose=encryption \
  --rotation-period=90d --next-rotation-time=2026-09-01T00:00:00Z

16 Cloud Monitoring and Logging — Operations Suite

The Google Cloud Operations suite (formerly Stackdriver) provides observability. Cloud Monitoring collects metrics, builds dashboards, and fires alerting policies when conditions breach thresholds, with notifications via email, PagerDuty, or Pub/Sub. Uptime checks probe endpoints from multiple locations.

Cloud Logging centralises logs from Google Cloud services and your apps. You query with the Logs Explorer, route entries with log sinks to Cloud Storage, BigQuery, or Pub/Sub, and define log-based metrics. The suite also includes Cloud Trace (latency), Cloud Profiler, and Error Reporting.

Good operations means dashboards for the golden signals (latency, traffic, errors, saturation), alerts on what users feel, and sinks that retain logs for compliance.

# Create a log sink that exports to BigQuery
gcloud logging sinks create errors-to-bq \
  bigquery.googleapis.com/projects/my-proj/datasets/logs \
  --log-filter='severity>=ERROR'

# Read recent error logs
gcloud logging read 'severity>=ERROR' --limit=20 --format=json

17 Pub/Sub — Asynchronous Messaging

Pub/Sub is a fully managed, scalable messaging service for decoupling producers and consumers. Publishers send messages to a topic; subscribers receive them via a subscription. This publish-subscribe pattern lets many services react to events independently and absorb traffic spikes.

Subscriptions are pull (consumers fetch and acknowledge) or push (Pub/Sub posts to an HTTPS endpoint). Pub/Sub guarantees at-least-once delivery, so consumers should be idempotent. Features include message ordering keys, dead-letter topics for poison messages, and retention.

Use Pub/Sub for event-driven architectures, streaming ingestion into Dataflow or BigQuery, and fan-out where one event triggers many independent workflows.

# Create a topic and a subscription with a dead-letter topic
gcloud pubsub topics create orders
gcloud pubsub topics create orders-dead
gcloud pubsub subscriptions create orders-worker \
  --topic=orders \
  --dead-letter-topic=orders-dead \
  --max-delivery-attempts=5

# Publish a message
gcloud pubsub topics publish orders --message='{"id":42}'

18 Cloud Storage — Classes and Lifecycle

Cloud Storage holds objects in buckets with a globally unique name. It offers four storage classes that trade lower storage price for higher access cost and minimum storage duration: Standard (hot, frequent access), Nearline (≈ monthly access), Coldline (≈ quarterly), and Archive (rarely accessed, long-term). All classes share the same API and millisecond access.

Object Lifecycle Management automates transitions and deletions with rules — for example, move objects to Coldline after 30 days and delete after 365. Object Versioning retains overwritten and deleted versions, and retention policies can lock objects for compliance.

Choose Standard for active data and colder classes plus lifecycle rules to cut cost for aging data without changing your application code.

# Create a bucket and set a lifecycle rule via JSON
gcloud storage buckets create gs://my-proj-data \
  --location=europe-north1 --default-storage-class=STANDARD

# lifecycle.json moves to COLDLINE after 30 days, deletes after 365
gcloud storage buckets update gs://my-proj-data \
  --lifecycle-file=lifecycle.json

19 Backups and Snapshots

Resilience depends on good backups. Persistent disk snapshots capture the state of a Compute Engine disk; they are incremental (only changed blocks after the first), stored redundantly, and can be regional or multi-regional. You can automate them with a snapshot schedule (resource policy) and create new disks from a snapshot.

Cloud SQL provides automated backups plus point-in-time recovery (PITR) using write-ahead logs, so you can restore to a specific second. Other services have their own backup mechanisms — Firestore exports, GKE Backup, and Cloud Storage versioning.

A sound strategy defines a retention period, tests restores regularly, and stores critical copies in a different region to survive a regional outage.

# Attach an hourly snapshot schedule to a disk
gcloud compute resource-policies create snapshot-schedule daily-snap \
  --region=europe-north1 \
  --max-retention-days=14 \
  --daily-schedule --start-time=02:00
gcloud compute disks add-resource-policies web-disk \
  --zone=europe-north1-a --resource-policies=daily-snap

20 Infrastructure as Code — Terraform and Deployment Manager

Infrastructure as Code (IaC) declares your infrastructure in version-controlled files instead of clicking the console. Terraform (with the Google provider) is the most widely used tool: you write HCL describing resources, run plan to preview changes, and apply to converge real infrastructure to the desired state, tracked in a state file.

Google’s native option is Cloud Deployment Manager, which uses YAML/Jinja/Python templates, though many teams now standardise on Terraform (and Infrastructure Manager, a managed Terraform service). IaC gives you repeatability, review via pull requests, and easy environment cloning.

Store state remotely (e.g. a Cloud Storage backend with locking), keep modules reusable, and never edit resources by hand once they are managed by code.

# A Terraform resource for a Cloud Storage bucket
# resource "google_storage_bucket" "data" {
#   name     = "my-proj-data"
#   location = "EUROPE-NORTH1"
# }

terraform init
terraform plan -out=tfplan
terraform apply tfplan

21 Cloud Build — CI/CD on Google Cloud

Cloud Build is Google’s managed CI/CD service. A build is defined in a cloudbuild.yaml file as a sequence of steps, each running in a container. Typical steps build a Docker image, run tests, push to Artifact Registry, and deploy to Cloud Run, GKE, or App Engine.

Builds are triggered manually, by triggers on repository events (push or pull request from GitHub, Bitbucket, or Cloud Source Repositories), or on a schedule. Builds run with a service account whose IAM roles must permit the deployments. You can store artifacts and use substitutions for variables like the commit SHA.

Cloud Build pairs naturally with IaC and Artifact Registry to form a full pipeline from commit to production deploy.

# cloudbuild.yaml: build, push, deploy to Cloud Run
steps:
  - name: gcr.io/cloud-builders/docker
    args: ['build','-t','europe-north1-docker.pkg.dev/$PROJECT_ID/apps/api:$SHORT_SHA','.']
  - name: gcr.io/cloud-builders/docker
    args: ['push','europe-north1-docker.pkg.dev/$PROJECT_ID/apps/api:$SHORT_SHA']
  - name: gcr.io/google.com/cloudsdktool/cloud-sdk
    entrypoint: gcloud
    args: ['run','deploy','api','--image','europe-north1-docker.pkg.dev/$PROJECT_ID/apps/api:$SHORT_SHA','--region','europe-north1']

🎓 Certificate of Completion

🔒 Complete every lesson quiz above with 90%+ to unlock your downloadable certificate.