Applying site reliability engineering practices · Topic 2 of 3

Service Lifecycle, Toil, Capacity Planning and Autoscaling

Manage the service lifecycle and toil, plan capacity with quotas, reservations and Dynamic Workload Scheduler, and autoscale MIGs, Cloud Run and GKE.

  • 5 min
In a nutshell
  • Lifecycle: plan, launch with readiness review, maintain, retire cleanly.
  • Toil is manual, repetitive and automatable; cap it and automate it away.
  • Quotas can be raised; system limits cannot; quota does not guarantee capacity.

What it is

A service is not finished when it launches. It moves through planning, deployment, maintenance and finally retirement, and at every stage it needs enough capacity to meet its SLOs.

Capacity has two parts: making sure the resources can be obtained (quotas, reservations) and making sure the service uses the right amount at each moment (autoscaling).

PlanSLOs, capacityLaunchreadiness reviewOperateautoscaling, reduce toilMaintainupgradesRetiredrain, delete

How it works

Service management across the lifecycle

StageSRE activities
PlanningDefine SLIs and SLOs, estimate demand, design for failure, check quotas
Deployment and launchProduction readiness review: monitoring, alerts, runbooks, rollback plan, load test
MaintenancePatching, upgrades, capacity reviews, reducing toil, postmortem actions
RetirementAnnounce deprecation, migrate users, drain traffic, keep data per retention rules, delete resources and IAM grants

Toil is manual, repetitive, automatable work with no lasting value that grows with the service, such as restarting a stuck job by hand every night. SRE teams cap toil (Google's guideline is no more than about half of an engineer's time) and spend the rest on engineering that removes it.

Quotas and limits

QuotasSystem limits
WhatPer project or region caps on resources or API ratesFixed maximums of a product
Can changeRequest an increase in the Cloud Quotas page or with the APINo
ExamplevCPUs in a region, GPUs, API requests per minuteMaximum size of an object or number of items per resource

Quota is not capacity: having quota does not guarantee a zone has free machines at that moment. Check quotas during planning, before a launch or a failover test, and set alerts when usage approaches a quota.

Reservations

A Compute Engine reservation holds capacity for specific machine types in a zone, so VMs can be created when needed, for example for a peak or a regional failover.

  • Reservations are billed as running VMs whether used or not; combine them with committed use discounts for a lower rate.
  • Automatically consumed reservations are used by any matching VM; specific reservations only by VMs that name them.
  • Shared reservations can be used by other projects in the organization that you share them with.

Dynamic Workload Scheduler

Dynamic Workload Scheduler handles scarce accelerators such as GPUs and TPUs. It has two modes:

ModeUse
Flex StartRun when capacity becomes available, for jobs that can wait, such as training
CalendarReserve capacity for a set future period

Capacity from either mode is consumed through Compute Engine, GKE, Vertex AI and Batch; on Compute Engine, Flex Start works through managed instance group resize requests.

Autoscaling

PlatformWhat scalesSignals and settings
Managed instance groupsNumber of VMsCPU utilization, load balancer serving capacity, Cloud Monitoring metrics, schedules; min and max replicas; initialization period; predictive autoscaling
Cloud RunNumber of instancesConcurrent requests per instance and CPU; min instances to avoid cold starts; max instances to protect backends
GKEPods and nodesHorizontal Pod Autoscaler (replicas), Vertical Pod Autoscaler (requests), cluster autoscaler and node auto-provisioning (nodes); Autopilot manages nodes for you
gcloud compute instance-groups managed set-autoscaling web-mig \
  --region=europe-west1 --min-num-replicas=3 --max-num-replicas=20 \
  --target-cpu-utilization=0.6 --cool-down-period=90

gcloud run services update web --region=europe-west1 \
  --min-instances=2 --max-instances=50 --concurrency=80
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: web
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: web
  minReplicas: 3
  maxReplicas: 30
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 60

HPA scales pods; if pods cannot be scheduled, the cluster autoscaler adds nodes. Set realistic resource requests, because both depend on them.

A worked example

A retailer expects ten times normal traffic on one sale day. The SRE team load tests staging to find the per-instance capacity and checks regional vCPU quota, requesting an increase weeks ahead.

They create a reservation for the extra VMs in two zones for the day and add a scaling schedule that raises the managed instance group minimum before the sale. Cloud Run front ends get higher minimum instances to avoid cold starts.

ForecastLoad testQuota increaseReservationsale dayScaling scheduleraise minimumSale

How the exam asks about this

  • "A planned event must not fail because VMs cannot be created in the region." Create reservations ahead of time, and confirm quota.
  • "Training jobs need GPUs but can start whenever capacity is free." Use Dynamic Workload Scheduler in Flex Start mode.
  • "Cloud Run requests are slow after quiet periods." Set minimum instances to keep warm instances ready.

What to remember for the exam

  • Lifecycle: plan, launch with readiness review, maintain, retire cleanly.
  • Toil is manual, repetitive and automatable; cap it and automate it away.
  • Quotas can be raised; system limits cannot; quota does not guarantee capacity.
  • Reservations guarantee zonal capacity and are billed whether used or not.
  • MIG, Cloud Run and GKE each autoscale; set sensible minimums and maximums.
Watch out

Setting no maximum on autoscaling can overwhelm a database or run up a large bill during a traffic spike or attack. Always set a max that downstream systems can handle.

Common mistakes

Requesting quota increases on the day of the event. Approval can take time. Plan increases well ahead.

Assuming quota means machines are available. Quota is permission, not capacity. Use reservations for guaranteed capacity.

Using HPA without resource requests. Utilization targets need requests to calculate against, and the cluster autoscaler needs them to fit pods.

Check yourself

  • What is the difference between a quota and a system limit?

    A quota is an adjustable cap you can ask to raise, while a system limit is a fixed maximum of the product.

  • When should you use a Compute Engine reservation?

    When you need guaranteed capacity for specific machine types in a zone at a known time, such as a peak event or failover.

  • What does the cluster autoscaler do when HPA adds pods that do not fit?

    It adds nodes to the node pool so the pending pods can be scheduled.

Topic 2 of 3 in Applying site reliability engineering practices

Test yourself on Applying site reliability engineering practices

The full Google Cloud Professional Cloud DevOps Engineer question bank has 751 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by Google Cloud. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.