Prepare and test your skills

Prepare and test your skills

Traffic splitting and deployment strategies in Cloud Run (opens in a new tab) control how incoming requests are divided across active service versions. A Cloud Run service receives all traffic at its main URL, and its traffic configuration decides which revision (opens in a new tab) gets what percentage. This makes deployments safer because a new version can be tested with real users before it takes over, and traffic can be moved back quickly if problems appear.
Traffic allocation is the rule that maps a percentage of requests from a Cloud Run service to each serving revision. The service depends on its traffic configuration to route each new request, and the percentages for all serving revisions must add up to 100. Traffic changes are not instantaneous, so requests already being processed continue to completion and are not dropped during the transition. Once a split is set, that split pattern continues to apply to future deployments until it is explicitly cleared.
A canary rollout is a gradual deployment where a new revision first serves a small share of traffic while the old revision serves the rest. The new revision is first deployed to receive 0% of traffic by deploying with no-traffic or by leaving Serve this revision immediately unchecked, so the new revision exists but the old revision still handles all requests. Traffic is then shifted in small steps, for example from 5% to 25% to 50% to 100% for the new revision, while performance is checked after each increase. Choose a canary rollout when the goal is to limit risk by exposing only a few users to the new version at first.
A blue-green split is a traffic allocation that keeps two revisions active at once, with the stable blue revision and the new green revision each receiving a defined percentage. The same mechanism can split traffic across more than two revisions, for example 25% to one revision, 25% to a second, and 50% to a third. Traffic flows from the service URL to each listed revision according to its percentage, so increasing one revision requires decreasing the others to keep the total at 100. Choose a multi-revision split when versions need to run side by side for comparison, staged migration, or a controlled blue-green handoff.
| Strategy | Traffic allocation | Choose when |
|---|---|---|
| Gradual rollout | New revision starts at 0%, then moves to a small percent such as 5% or 10% and grows | The new version needs real-user validation with limited blast radius |
| Split traffic | Two or more named revisions share traffic, such as 25% and 75% | Multiple versions must stay active during migration or testing |
| Rollback | One previous revision receives 100% and the faulty revision receives 0% | The current version must be replaced immediately with a known-good version |
| Serve latest | The latest healthy revision receives 100%, overriding any split | Normal single-version operation should resume after testing |
A rollback is a traffic change that sends 100% of traffic back to a previous revision after a faulty deployment. The previous revision must still exist, and after the change the revision being rolled back from serves 0% of traffic. Sending all traffic to the latest revision is the opposite reset action, because it clears any split and makes the newest healthy revision and all future revisions serve 100% of traffic. Use rollback to recover fast, and use serve-latest when staged testing is finished and one version should handle everything again.
A revision tag is a name attached to a revision that creates a separate test URL for that revision without giving it production traffic. The tagged revision can receive requests sent directly to its tag URL while the main service URL continues to send 100% of traffic to the stable revisions. A common safe sequence moves a container through testing before migration:
A Cloud Run service exposes two URLs: the main service URL routes 100% of production clients to the stable blue revision, while the tag URL green---myservice-abcdef.a.run.app routes only testers to the new green revision deployed with 0% traffic, enabling isolated testing before traffic migration.
After testing succeeds, the tagged revision is added to the main traffic split like any other revision. Remove tags when they are no longer needed to avoid keeping extra testable revisions running.
Exam tip: Traffic percentages must total 100, and a split stays in effect for later deployments until you explicitly send all traffic to the latest revision.
Rollback procedures and revision tagging in Cloud Run (opens in a new tab) determine how traffic is returned to a stable version and how a new version is tested. A Cloud Run service revision is an immutable snapshot of container images and settings created by each deployment. Cloud Run controls which revision receives user requests through traffic settings that assign a percentage to each revision, while a revision tag (opens in a new tab) provides a separate test URL so a new revision can be verified before it receives production traffic.
Rolling back to a previous stable revision means sending 100 percent of traffic from the current revision to an earlier healthy revision. The faulty revision is not changed or deleted; Cloud Run simply updates the service traffic configuration so requests flow from clients to the selected previous revision. Traffic changes are not instantaneous, and requests already being processed run to completion without being dropped, so in-flight requests may reach either the new revision or the previous revision during the transition.
A rollback traffic setting persists for future deployments until it is explicitly reset. If a service is left sending 100 percent of traffic to a specific older revision, later deployments continue to use that pinned pattern instead of automatically serving the newest revision. To return to normal operation, traffic must be sent to the latest revision so new revisions serve 100 percent as soon as they are healthy. The command gcloud run services update-traffic SERVICE --to-revisions REVISION=100 performs a rollback, while --to-latest restores latest-revision serving.
Testing with a revision tag means deploying a new revision with 0 percent production traffic and reaching it through a unique tag URL. A revision tag is a lowercase name attached to a revision, such as green, that creates a direct address like https://green---myservice-abcdef.a.run.app where test traffic flows from testers to that specific revision. Production users continue to flow to the untagged serving revision, so testing does not affect them. The tagged revision is deployed with options such as --no-traffic --tag TAG_NAME to keep it out of production serving.
Teams commonly vet a container through the following ordered checks before migration:
A tagged revision in Cloud Run can be verified in the production environment without changing what production clients receive. Remove tags when testing is finished to avoid extra cost, especially when revision-level minimum instances keep tagged revisions running. A revision with 0 percent traffic can be deleted even if it still has a tag, and Cloud Run then tries to remove that tag from the traffic configuration.
Migrating production traffic to a tested revision means shifting production percentages from the current serving revision to the verified tagged revision. Migration starts after the tag URL tests pass, with traffic flowing from clients through the service traffic split to both revisions. All assigned percentages must add up to 100, so every increase for the new revision requires an equal decrease for the old one. The split can be raised over hours or days until the new revision is trusted with full traffic.
| Goal | Traffic setting | Result |
|---|---|---|
| Rollback | 100% to previous revision | Production clients flow to the previous stable revision and the faulty revision serves 0% |
| Safe test | 0% to new revision plus tag | Testers flow to the tag URL while production clients stay on the serving revision |
| Gradual migration | Split such as 90/10, then higher for the new revision | Production clients shift step by step until the new revision serves 100% |
Cleanup after migration keeps costs and configuration simple in Cloud Run. Tags that are no longer needed should be removed because tagged revisions with revision-level minimum instances continue to consume resources. Service-level minimum instances do not allocate extra capacity to tagged revisions, so choosing service-level minimums or removing tags avoids unnecessary billing.
Exam tip: A traffic split persists for later deployments; send all traffic to the latest revision to stop pinning traffic to an older revision and resume automatic serving of new revisions.
Revision triggers and configuration management in Cloud Run (opens in a new tab) explain what creates a new service version and why old versions cannot change. A Cloud Run service revision is an immutable snapshot of code and configuration that serves traffic for a Cloud Run service. Each deployment to a Cloud Run service creates a new revision, and Cloud Run automatically routes requests as soon as possible to the latest healthy service revision.
A Cloud Run service revision contains one or more container images plus the configuration settings that control how those containers run. The configuration includes settings such as environment variables, memory limits, CPU limits, and request concurrency values. When Cloud Run imports a container image at deploy time, Cloud Run keeps that copy as long as the image is used by a serving revision. Container images are not pulled again from their container repository when a new Cloud Run instance starts.
Any deployment or configuration change to a Cloud Run service triggers creation of a new Cloud Run service revision, even when the container image does not change. A new revision can be deployed using the Google Cloud console, the gcloud command line, or a YAML configuration file that updates spec.template attributes. Common triggers fall into the following groups:
For example, deploying a container image to a new service creates the first revision, deploying a different container image to that same service creates a second revision, and setting an environment variable afterward creates a third revision.
Exam tip: Changing any configuration setting creates a new revision even if the container image is unchanged, and an existing revision can never be edited.
Immutability means a Cloud Run service revision cannot be modified after its creation, so every fix or tuning step produces a new revision. If a service is deployed from a container image tag, the tag is resolved to a digest and the revision always serves that particular digest. The revision suffix is assigned automatically, but a custom suffix can be supplied with the gcloud parameter --revision-suffix.
Cloud Run service revisions are managed over time to limit clutter and cost. Revisions that are not receiving requests do not consume resources and are not billed, although minimum instances can create billing considerations. Over time Cloud Run removes unused revisions, and there is a maximum of 1000 revisions per service, after which older revisions are automatically deleted.
Traffic allocation in a Cloud Run service maps a percentage of requests from the service URL to each serving revision, and the percentages for all serving revisions must add up to 100. Traffic changes are not instantaneous, so requests already being processed continue to completion without being dropped. Once set, a split pattern continues to apply to future deployments until it is explicitly cleared by sending all traffic to the latest revision.
Use a canary rollout for a Cloud Run service revision when the goal is to limit risk by exposing only a few users to the new version at first. The new revision is first deployed to receive 0 percent of traffic by deploying with no-traffic or by leaving Serve this revision immediately unchecked, so the old revision still handles all requests. Traffic is then shifted in small steps, for example from 5 percent to 25 percent to 50 percent to 100 percent for the new revision, while performance is checked after each increase.
Rolling back a Cloud Run service means updating the service traffic configuration to send 100 percent of traffic from the current revision to an earlier healthy revision, which must still exist. The faulty revision is not changed or deleted and serves 0 percent of traffic after the change, while requests already being processed run to completion without being dropped. The rollback setting persists for future deployments until it is explicitly reset by sending traffic to the latest revision so new revisions serve 100 percent as soon as they are healthy.
A revision tag in Cloud Run is a name attached to a revision that creates a separate test URL for that revision without giving it production traffic. Testers can send requests directly to the tag URL while the main service URL continues to send 100 percent of traffic to the stable revisions, so testing does not affect production clients. After testing succeeds, the tagged revision can be added to the main traffic split like any other revision, and tags should be removed when no longer needed to avoid keeping extra testable revisions running.
Your company hosts a public REST API on Google Cloud Run. You have developed an update with performance improvements, but you want to test it safely in production before doing a full rollout.
You need to implement a canary deployment where:
What should you do?
Deploy the new revision with no immediate traffic assigned, and then configure Cloud Run traffic splitting to allocate 10% of traffic to the new revision and 90% to the previous revision.
Update the existing revision in place and set the maximum instance limit on that revision to handle 10% of normal daily concurrency.
Deploy the updated container image to a new, separate Cloud Run service and configure an external Application Load Balancer with weighted backend services.
Create a Pub/Sub topic to intercept 10% of HTTP API requests and push them asynchronously to the new revision.
Last updated