Lesson 2 of 5 CI/CD and Testing for ML and AI

Deploying Models with Guardrails and Automatic Rollback

This lesson explains deployment strategies that shift traffic gradually to a new model and roll back automatically, limiting the impact of a model that is slower, error-prone or less accurate on live data.

Learning outcomes

After completing this lesson, you will be able to:

  • Use SageMaker AI deployment guardrails for blue/green updates.
  • Roll back automatically on CloudWatch alarms.
  • Choose between all-at-once, canary and linear shifting.
  • Choose alarms and baking periods.

SageMaker AI deployment guardrails

When an endpoint is updated, SageMaker AI can perform a blue/green deployment: it creates a new fleet (green) beside the old one (blue) and shifts traffic according to a mode. All at once shifts everything, then watches for a baking period. Canary shifts a small portion, such as 10%, waits, then shifts the rest. Linear shifts traffic in equal steps, such as 20% every 10 minutes. Rolling deployment replaces instances in batches without creating a full second fleet, which suits large endpoints or scarce instance types.

Match the pairs

Traffic shifting modes

Exam skills 3.3.1

Match each SageMaker AI deployment guardrail mode with how it shifts traffic.

Log in to try this activity Interactive activities are free with an account.

Automatic rollback

Each deployment can specify CloudWatch alarms, for example on Invocation5XXErrors, ModelLatency or a custom business metric. If any alarm enters ALARM during traffic shifting or the baking period, SageMaker AI automatically rolls traffic back to the blue fleet. Beyond endpoint updates, rollback can also mean redeploying the previous approved model package or pointing an alias back to an earlier agent or prompt version.

The following diagram shows the traffic on each fleet over time during a canary deployment of a new recommendation model.

The recommendation model's canary deployment. 10% of capacity serves the new model for ten minutes while SageMaker AI watches the 5XX and p99 latency alarms; then all traffic shifts and the old fleet is kept for a five-minute baking period. If either alarm fires at any point, traffic returns to the old fleet automatically.
The scenario is illustrative.
True or false

Automatic rollback

Exam skills 3.3.1

Check how SageMaker AI rolls back a bad deployment.

Log in to try this activity Interactive activities are free with an account.

Choosing a strategy

SageMaker AI deployment guardrails offer several ways to shift traffic to a new model on an existing endpoint. All-at-once shifts all traffic immediately, which is fastest but riskiest. Canary shifts a small share first and the rest after a baking period. Linear shifts traffic in equal steps. Each can roll back automatically on alarms, and the right choice depends on how much risk a bad release would carry. The following table summarises the strategies.

StrategyTraffic shiftExtra capacityBest for
All at once100% then bakeFull second fleetLow-risk changes, fast rollout
CanarySmall share, then the restFull second fleetCatching problems on a small share first
LinearEqual steps over timeFull second fleetGradual exposure with checks at each step
RollingBatches of instancesOnly one batchLarge endpoints, limited capacity

Choosing alarms and baking periods

Automatic rollback is only as good as the alarms it watches. Operational alarms on Invocation5XXErrors and ModelLatency catch a model that crashes or slows down, but a model can serve fast, error-free and wrong predictions. To catch that, the application can publish a business or quality signal, such as the click-through rate of recommendations or the share of low-confidence predictions, as a custom CloudWatch metric and add an alarm on it to the rollback configuration.

Thresholds should be set relative to the current model's normal behaviour, for example a p99 latency 20% above the usual value, rather than at arbitrary absolute numbers. With a small canary, such as 10% of capacity, a metric is computed from fewer requests and is therefore noisier, so the wait interval must be long enough to collect a meaningful sample, and the alarm may need several evaluation periods before it fires.

The baking period is the time SageMaker AI keeps the old fleet after all traffic has shifted, while it continues to watch the alarms. It should cover the time a problem needs to appear, such as memory growth that causes failures after half an hour or a daily traffic peak. A shadow test before the deployment complements these mechanisms: it validates the new model on real traffic without user impact, and the guarded deployment then limits the impact of anything the shadow test could not measure, such as user behaviour.

Scenario questions

Watch the canary

Exam skills 3.3.1

Choose alarms and baking periods that catch a bad release.

Log in to try this activity Interactive activities are free with an account.
Worked example

A canary with rollback

A recommendation model update must expose at most 10% of users to problems, and roll back automatically if error rates or latency rise.

"DeploymentConfig": {
  "BlueGreenUpdatePolicy": {
    "TrafficRoutingConfiguration": {
      "Type": "CANARY",
      "CanarySize": {"Type": "CAPACITY_PERCENT", "Value": 10},
      "WaitIntervalInSeconds": 600 },
    "TerminationWaitInSeconds": 300,
    "MaximumExecutionTimeoutInSeconds": 3600 },
  "AutoRollbackConfiguration": {
    "Alarms": [{"AlarmName": "recs-5xx-high"}, {"AlarmName": "recs-p99-latency-high"}] } }

10% of capacity receives the new model for ten minutes. If either alarm fires during that time or the baking period, traffic returns to the old fleet without human action.

Check yourself

Which deployment strategy suits large fleets or scarce capacity?

Show answer

A rolling deployment, which updates instances in batches without doubling capacity.

Exam Tips

Remember for the exam

  • Small share first with automatic rollback: canary with CloudWatch alarms.
  • Equal traffic steps: linear; everything at once: all-at-once with baking.
  • Large fleets or scarce capacity: rolling deployment.
  • Rollback is triggered by CloudWatch alarms during shifting or baking.
  • Deployment guardrails apply when updating an existing endpoint.