Prepare and test your skills
Prepare and test your skills
Automated drainage in deployment pipelines is the practice of making traffic shifts a programmed pipeline stage instead of a manual cutover. The pipeline controls Cloud Load Balancing (opens in a new tab) configuration, including URL maps and backend services, so each release or incident response moves traffic from old backends to new backends in small, verifiable steps. Health checks, weight-based splitting, and overload protections provide the signals and guardrails that let the pipeline advance, pause, or roll back without dropping user sessions.
Health checks and autohealing are the automated signals that remove unresponsive backends from the serving pool. A Compute Engine virtual machine (VM) can remain in the RUNNING state while its application software has crashed, so autoscaling alone cannot guarantee responsiveness. The health check probes each backend independently, and traffic flows from the load balancer only to backends that respond successfully while traffic stops flowing to backends that fail probes. When backends are Managed Instance Groups (MIGs), autohealing adds a second flow where the MIG depends on its health check to identify unavailable VMs, deletes those VMs, and creates replacement VMs so future pipeline stages have healthy targets.
Weight-based traffic splitting is the pipeline mechanism for canary releases, A/B testing, and service migration on Application Load Balancers. The pipeline defines percentage-based splits across multiple backend services, so a new version receives only a small share of live requests while the previous version continues serving the majority. Because the split is controlled by configuration, the pipeline can advance the percentages automatically after validation or reverse them instantly for rollback. A typical automated canary preserves order and validation gates:
Exam tip: Weighted traffic splitting takes precedence over session affinity, so do not configure session affinity when you rely on percentage-based splits for canary control.
Traffic steering, actions, and policies are the three Application Load Balancer capabilities for draining specific subsets of traffic. Traffic steering routes requests based on HTTP(S) parameters such as host, path, and headers, so requests carrying user-agent:Mobile flow to mobile-designated instances while other requests flow to default instances. Traffic actions perform request-based and response-based operations such as redirects and header transformations, while traffic policies fine-tune load-balancing behavior such as advanced algorithms and request mirroring to a recording service. The pipeline implements all three capabilities through the same control plane where configuration flows from pipeline automation to URL maps and then to backend services, which in turn select the backends.
| Capability | Controls | Pipeline use |
|---|---|---|
| Traffic steering | Which backend service receives a request based on HTTP parameters | Drain mobile, path-specific, or header-specific traffic to a new version first |
| Traffic actions | What happens to the request or response, such as redirect or header change | Redirect users between versions or transform headers during migration |
| Traffic policies | How load balancing behaves across backends, including mirroring | Mirror live traffic to a new backend for validation without shifting users |
Regional internal Application Load Balancers use regional URL maps and backend services, while cross-region internal Application Load Balancers must use the global URL map and global backend service APIs.
Overload protection is the set of guardrails that keeps remaining backends available while drainage shifts load. Graceful degradation keeps the system available with reduced performance or accuracy under high load, then resumes full functionality when load returns to a manageable level. Google Search illustrates the pattern by prioritizing results from higher-ranked pages during overload and recomputing fuller results after load decreases. Pipeline orchestration combines peer protections so a traffic shift does not cause cascading failures:
Project-level quotas limit the number of API requests a Google Cloud service can receive, which protects against distributed denial-of-service (DDoS) attacks and runaway billing. For globally served applications, Network Service Tiers Premium Tier carries traffic from the internet entry point of presence (PoP) closest to the sender across the Google network to the appropriate backend.
Connection draining is the pattern for gracefully removing a backend from serving traffic so in-flight requests complete before shutdown. When an instance is removed from an instance group or an endpoint is removed from a zonal network endpoint group (zonal NEG), the backend service (opens in a new tab) stops sending new connections to that removed backend while existing connections are allowed time to finish. This behavior applies to Google Cloud load balancers and Cloud Service Mesh and is controlled by a connection draining timeout of 0 to 3600 seconds.
Graceful removal is the separation of new traffic from existing traffic at the moment a backend is marked for removal. The load balancer sends no new connections or requests to the removed virtual machine (VM) or endpoint, while packets and requests that belong to already-established flows continue to reach that same backend for the configured timeout. If no timeout is set, or the timeout is set to zero (0), Google Cloud ends existing connections on the removed instance or endpoint as quickly as possible. Validating drainage therefore means confirming that new flows arrive only on remaining backends while old flows on the draining backend decline to zero before the VM is deleted.
Drainage behavior across load balancer types depends on whether the load balancer proxies the connection or only routes packets. During the timeout all three types withhold new connections from the draining backend, but what happens after the timeout reflects how each design terminates connections.
| Load balancer type | During draining timeout | After timeout expires |
|---|---|---|
| Application Load Balancer | Existing requests to the removed VM or endpoint are given time to complete; no new connections are sent to it | The load balancer stops sending all traffic to the removed VM or endpoint |
| Proxy Network Load Balancer | Existing Transmission Control Protocol (TCP) connections continue to work; no new connections are sent to it | Existing TCP connections remain active and the proxy closes all existing TCP connections within 10 minutes, the default idle timeout |
| Passthrough Network Load Balancer | Packets belonging to existing connections are routed to the marked VM or endpoint | The load balancer removes the connection tracking entry; later packets are routed to a different backend, which may send a TCP reset (RST) |
A passthrough Network Load Balancer by itself cannot send RST or FIN packets to close a connection. After its connection tracking entry is removed, the newly selected backend has no record of the old TCP connection, so closure depends on that backend sending an RST and the client reconnecting through normal backend selection.
Drain timeout configuration is set on the backend service that references the instance group or zonal NEG. In the console, the timeout is set under backend configuration in Advanced configurations in the Connection draining timeout field, where 0 disables draining. With Google Cloud CLI (gcloud), the timeout is set with the --connection-draining-timeout flag on a new or existing backend service, for example on a global backend service with gcloud compute backend-services update BACKEND_SERVICE --global --connection-draining-timeout=CONNECTION_TIMEOUT_SECS. When the same instance group or zonal NEG is a backend for multiple backend services, the largest timeout value becomes the effective timeout. If the backend is a managed instance group (MIG), operations that delete the instance are delayed by at least that effective timeout, so the timeout must be long enough for the longest expected request plus connection close time.
Exam tip: When one instance group or zonal NEG is shared by backend services with different draining timeouts, the largest timeout wins — 100 seconds and 200 seconds results in 200 seconds of draining.
Validation of completed drainage confirms that the draining backend receives no new work and that its existing work finishes cleanly. Health checking supports this by helping ensure that traffic is not routed to unhealthy or unavailable resources, and backend health can be checked during removal to confirm that remaining backends stay healthy while the removed backend stops receiving new flows. Operators should monitor open connections and request counts on the draining VM or endpoint until existing requests complete and connection termination is observed, and only then allow the managed instance group deletion or endpoint removal to proceed. Connection pooling can break this validation because a previously established pooled connection can still carry new requests to a draining VM, and those requests may succeed at first and then fail when the VM is deleted.
Traffic redirection and failover in Google Cloud is the controlled shifting of user traffic between backend services, regions, or deployments to preserve availability. Global external Application Load Balancer (opens in a new tab) resources distribute traffic across regions in normal operation, regional external Application Load Balancer resources provide isolated backup targets, and Cloud DNS routing policies automate the switch between them. Health checks, URL maps, backend services, and Premium Tier routing work together so only responsive backends receive traffic while performance and error signals are observed.
URL maps and backend services form the traffic control plane for Application Load Balancers by separating where traffic should go from how backends share that traffic. A request follows a two-phase flow where the load balancer first selects a backend service or backend bucket based on rules in the URL map, then the selected backend service selects a specific backend instance based on its locality policy, hashing, and outlier detection. Regional internal, cross-region internal, and global external Application Load Balancers support the same three categories of advanced behavior:
URL map routing modes are mutually exclusive within one URL map. A simple host and path rule first evaluates host rules against the request host, then evaluates the associated path matcher on a longest-path-matches-first basis. An advanced host, path, and route rule instead evaluates route rules in priority order, which enables precise percentage splits and header matches.
Gradual deployment shifts use weight-based splitting and header-based steering to drain traffic from one deployment to another without redeploying code. Traffic splitting defines percentage-based splits across multiple backend services, so an operator can send 95% of traffic to the previous version and 5% to the new version, validate performance and errors, then gradually shift percentages until 100% reaches the new version. This pattern is used for new-version rollouts, A/B testing, and service migration, and the weighted splitting configuration takes precedence if session affinity is also configured. A controlled shift between deployments follows an explicit order:
Header-based steering complements splitting by directing subsets of traffic to designated backends. Traffic steering can send requests with user-agent:Mobile to mobile-optimized instances while sending all other traffic to default instances. Request mirroring copies traffic to an additional service for compliance recording or later replay without affecting the primary response path.
Health-based draining is the mechanism that removes unresponsive backends from the serving pool during shifts and incidents. Health checks ensure that load balancers route application traffic to only the backends that are responsive, even when infrastructure appears healthy. For example, all Compute Engine virtual machines (VMs) hosting an application might be in the RUNNING state while the application software on some VMs has crashed, and health checks remove those crashed VMs from the serving pool. When backends are managed instance groups (MIGs), autohealing restores capacity because unavailable VMs are proactively deleted and new VMs are created while the load balancer continues to avoid the failed backends. Configure load balancing between application tiers as well as at the edge, such as using an internal Application Load Balancer for reliable communication between the web and application tiers in a three-tier stack, so a failing middle tier is also drained automatically.
Global-to-regional failover protects a global external Application Load Balancer with one or more regional external Application Load Balancers and Cloud DNS. The primary load balancer is the global external Application Load Balancer that handles client traffic during normal operations, and each backup load balancer is a regional external Application Load Balancer that receives traffic when the primary fails health checks. Failover occurs when Cloud DNS detects an outage and routes traffic from the primary to the backups, while failback occurs when Cloud DNS reverses routing back to the primary after health checks pass. Regional external Application Load Balancers work best as failover targets because regional load balancers are self-contained within individual regions and isolated from global external Application Load Balancer infrastructure in the same region.
| Strategy | Steady-state traffic path | Cloud DNS policy | Choose when |
|---|---|---|---|
| Active-passive global-to-regional failover | Cloud DNS resolves to the global external Application Load Balancer; regional load balancers remain idle backup | Failover routing policy | Backups should receive traffic only during a global outage or configuration error |
| Active-active global-to-regional bypass | Traffic flows sequentially through the global external Application Load Balancer as an edge frontend with Cloud CDN caching into regional load balancers through internet network endpoint groups (NEGs) with fully qualified domain names (FQDNs) | Geolocation routing policy | The global layer should add edge value in normal operation but clients must bypass it directly to regionals during a global outage |
Both load balancer types are based on Envoy proxies and process traffic in similar ways, which reduces behavior differences after failover. Deploy two or more regional external Application Load Balancers in the regions where traffic should fail over, perform capacity planning so surviving regions can absorb the redirected load, and reserve additional proxy-only subnet capacity for standby proxies.
Exam tip: Active-passive failover uses a Cloud DNS failover routing policy with idle regional backups, while active-active bypass uses a geolocation routing policy with traffic flowing through both layers in steady state.
Premium Tier routing and observability preserve performance and control while redirected traffic shifts regions. Traffic from the internet enters the high-performance Google network at the point of presence (PoP) closest to the sender, is routed within the Google network from the entry PoP to the selected Compute Engine backend, and outbound traffic exits at the PoP closest to the destination. This reduces hops between users and the entry point, which matters when traffic suddenly shifts regions. For multi-region applications serving global users, choose Premium Tier, while for single-region backends that do not need global features, a regional load balancer remains resilient to zone outages. During any shift, protect backends with rate limiting such as API request quotas and project-level resource quotas, throttle overloads independently at replicas with tools like Apigee, drop excess requests at the frontend layer to protect backend components, and monitor traffic spikes with analytics and monitoring tools so surges are detected before they escalate.
The connection draining timeout on a backend service is configurable from 0 to 3600 seconds, where 0 disables draining and ends existing connections on the removed instance or endpoint as quickly as possible. When one instance group or zonal network endpoint group (zonal NEG) is shared by multiple backend services, the largest timeout value becomes the effective timeout.
All three types withhold new connections from the draining backend during the timeout, but they differ after the timeout expires. An Application Load Balancer stops sending all traffic to the removed virtual machine or endpoint, a Proxy Network Load Balancer keeps existing Transmission Control Protocol (TCP) connections active and closes them within 10 minutes, and a Passthrough Network Load Balancer removes the connection tracking entry so later packets are routed to a different backend which may send a TCP reset.
Use a Cloud DNS failover routing policy for active-passive global-to-regional failover where the global external Application Load Balancer handles client traffic normally and regional external Application Load Balancers remain idle backup. Use a geolocation routing policy for active-active global-to-regional bypass where traffic flows sequentially through the global external Application Load Balancer into regional load balancers in steady state and clients bypass the global layer directly to regionals during a global outage.
Your organization operates a global, mission-critical application hosted on Google Cloud using Compute Engine Managed Instance Groups (MIGs) behind an external Application Load Balancer. To improve release velocity and prevent customer-facing incidents, the SRE team requires the deployment pipeline to automate canary deployments, metric validation, and traffic draining.
The automated CI/CD workflow must satisfy the following criteria:
Which strategy should you integrate into your CI/CD pipeline to orchestrate this automated traffic draining and canary workflow?
Last updated