9.1 Production Deployment Patterns & Traffic Shifting

Key Takeaways

  • SageMaker Production Variants host multiple model versions behind a single HTTPS endpoint, allowing traffic partitioning via InitialVariantWeight for A/B testing and dynamic zero-downtime weight adjustments via UpdateEndpointWeightsAndCapacities.
  • SageMaker Deployment Guardrails automate Blue/Green updates with three traffic shifting modes: AllAtOnce (100% immediate cutover post-health check), Canary (small initial step like 10% during a baking period before 100%), and Linear (equal incremental steps over time like 20% every 5 minutes).
  • Shadow Deployments replicate live production requests to a new model variant (Shadow Variant) where responses are discarded or logged for offline evaluation while only Live Variant responses are returned to callers, eliminating customer-facing risk.
  • Deployment Guardrails support automated CloudWatch rollback alarms (monitoring ModelLatency, Invocation5XXErrors, CPUUtilization, or custom business metrics) that abort deployment and roll back traffic immediately if thresholds are violated during the baking window.
  • Updating an endpoint configuration with Blue/Green guardrails provisions the new green fleet alongside the live blue fleet, executes health checks, and terminates the old fleet only after successful baking, maintaining high availability across Multi-AZ fleets throughout the transition.
Last updated: August 2026

Production Deployment Patterns & Traffic Shifting

Deploying machine learning models into mission-critical production environments requires resilient deployment strategies that eliminate downtime, mitigate customer-facing regression risk, and support continuous model improvement. In Amazon SageMaker, deploying a model update is not a blunt, high-risk server restart. Instead, SageMaker provides sophisticated orchestration mechanisms—including Production Variants, Deployment Guardrails (Blue/Green deployments with Canary and Linear shifting), Shadow Deployments, and Automated CloudWatch Rollbacks.

For the AWS Certified Machine Learning Engineer — Associate (MLA-C01) exam, you must master the mechanics of traffic shifting, understand how to configure A/B testing across multiple production variants behind a single endpoint, select the appropriate guardrail strategy based on risk tolerance, and configure automated rollback alarms to protect SLA commitments.


1. Endpoint Configuration & Production Variants

In Amazon SageMaker, a real-time hosting endpoint is decoupled into three distinct architectural entities:

  1. Model: Defines the container image in Amazon ECR, model artifact location in Amazon S3 (model.tar.gz), and environment variables.
  2. Endpoint Configuration (EndpointConfig): Defines the hardware topography, including instance types, initial instance counts, data capture options, and one or more Production Variants.
  3. Endpoint: The persistent HTTPS REST URL (https://runtime.sagemaker.<region>.amazonaws.com/endpoints/<endpoint-name>/invocations) that clients invoke.
+-----------------------------------------------------------------------------------------+
|                   SAGEMAKER PRODUCTION VARIANTS ARCHITECTURE                            |
|                                                                                         |
|                                  Client Invocations                                     |
|                                          |                                              |
|                                          v                                              |
|                           [HTTPS SageMaker Endpoint URL]                                |
|                                          |                                              |
|                 +------------------------+------------------------+                     |
|                 | Traffic Distribution via InitialVariantWeight   |                     |
|                 |                                                 |                     |
|                 v (90% Traffic)                                   v (10% Traffic)       |
|   +----------------------------+                    +----------------------------+      |
|   | Variant A (Champion Model) |                    | Variant B (Challenger Model|      |
|   | - Model: fraud-xgb-v1      |                    | - Model: fraud-xgb-v2      |      |
|   | - Instance: ml.c6i.xlarge  |                    | - Instance: ml.c6i.xlarge  |      |
|   | - Weight: 9.0              |                    | - Weight: 1.0              |      |
|   | - Instance Count: 4        |                    | - Instance Count: 2        |      |
|   +----------------------------+                    +----------------------------+      |
+-----------------------------------------------------------------------------------------+

Production Variants for A/B Testing

A single SageMaker endpoint configuration can host up to 10 Production Variants. Each variant specifies a separate model, instance type, and instance count:

  • InitialVariantWeight: Determines the statistical ratio of incoming traffic routed to that specific variant. For example, setting Variant A weight to 9.0 and Variant B weight to 1.0 distributes 90% of live requests to Variant A and 10% to Variant B.
  • Direct Variant Invocation (TargetVariant): While traffic is distributed by weight by default, client applications can bypass weighted routing and target a specific variant directly by passing the TargetVariant HTTP header in the InvokeEndpoint API request (e.g., X-Amzn-SageMaker-Target-Variant: VariantB).

Dynamic Traffic Rebalancing (UpdateEndpointWeightsAndCapacities)

When conducting A/B tests or progressively promoting a challenger model, you do not need to create a new endpoint configuration or redeploy the endpoint to adjust traffic ratios. The UpdateEndpointWeightsAndCapacities API allows you to dynamically adjust variant weights and instance counts in real time without downtime:

import boto3

sagemaker_client = boto3.client('sagemaker')

# Dynamically shift traffic: 50% to Variant A, 50% to Variant B
response = sagemaker_client.update_endpoint_weights_and_capacities(
    EndpointName='fraud-detection-endpoint',
    DesiredWeightsAndCapacities=[
        {
            'VariantName': 'VariantA-XGBoostV1',
            'DesiredWeight': 0.5,
            'DesiredInstanceCount': 3
        },
        {
            'VariantName': 'VariantB-XGBoostV2',
            'DesiredWeight': 0.5,
            'DesiredInstanceCount': 3
        }
    ]
)

[!IMPORTANT] A/B Testing vs. Blue/Green Deployments:

  • Production Variants (A/B Testing) are designed to evaluate model performance differences (e.g., business conversion, click-through rates, accuracy on real users) across two or more concurrently running models over an extended period.
  • Blue/Green Deployment Guardrails are designed for safe infrastructure cutovers when deploying a new endpoint configuration to replace an old one with automated rollback protection.

2. SageMaker Deployment Guardrails & Blue/Green Deployments

When updating an existing endpoint to use a new EndpointConfig (e.g., new model version, updated container image, or different instance family), SageMaker utilizes Deployment Guardrails to manage traffic shifting safely between the old fleet (Blue) and the new fleet (Green).

+-----------------------------------------------------------------------------------------+
|                     SAGEMAKER BLUE/GREEN DEPLOYMENT PHASES                              |
|                                                                                         |
|   [1. PROVISION GREEN FLEET]  ---> SageMaker launches new instances with new config     |
|                 |                                                                       |
|                 v                                                                       |
|   [2. HEALTH CHECKS]          ---> Verifies container initialization & /ping response   |
|                 |                  If health checks fail, Green fleet is terminated.    |
|                 v                                                                       |
|   [3. TRAFFIC SHIFTING]       ---> Shifts traffic via AllAtOnce, Canary, or Linear      |
|                 |                                                                       |
|                 v                                                                       |
|   [4. BAKING PERIOD]          ---> Monitors CloudWatch alarms (e.g., 15-30 min)         |
|                 |                  If ALARM triggers -> AUTO-ROLLBACK to Blue Fleet.    |
|                 v                                                                       |
|   [5. PROMOTION & CLEANUP]    ---> 100% on Green fleet -> Blue fleet terminated.        |
+-----------------------------------------------------------------------------------------+

Blue/Green Traffic Shifting Modes

SageMaker supports three distinct traffic shifting options within DeploymentConfig:

+-----------------------------------------------------------------------------------------+
|                       TRAFFIC SHIFTING STRATEGIES COMPARED                              |
|                                                                                         |
|   1. ALL AT ONCE                                                                        |
|   Traffic: [ Blue: 100% ] -------- Health Checks Pass --------> [ Green: 100% ]         |
|                                                                                         |
|   2. CANARY (e.g., 10% Canary Step, 15 min Baking Period)                               |
|   Step 1:  [ Blue: 90%  |  Green: 10% ]  <--- (Baking Period: 15 min)                   |
|   Step 2:  [ Blue: 0%   |  Green: 100% ] (If no CloudWatch alarms trigger)              |
|                                                                                         |
|   3. LINEAR (e.g., 20% Step Value, 5 min Step Interval)                                |
|   Step 1:  [ Blue: 80%  |  Green: 20% ]  <--- 5 min                                     |
|   Step 2:  [ Blue: 60%  |  Green: 40% ]  <--- 5 min                                     |
|   Step 3:  [ Blue: 40%  |  Green: 60% ]  <--- 5 min                                     |
|   Step 4:  [ Blue: 20%  |  Green: 80% ]  <--- 5 min                                     |
|   Step 5:  [ Blue: 0%   |  Green: 100% ] (Complete)                                     |
+-----------------------------------------------------------------------------------------+

Detailed Comparison Table

Traffic Shifting ModeTraffic Shift MechanismRisk ProfileTotal Cutover TimeIdeal Production Scenario
AllAtOnce100% of traffic is switched to the Green fleet instantaneously after container health checks pass.Moderate (Exposes all traffic immediately if latent runtime bugs exist).Fast (Immediate post-health check).Development/staging environments, non-critical workloads, or urgent security patches where fast cutover is paramount.
CanaryShifts a small initial percentage (e.g., 5–15%) to Green for a specified baking window (e.g., 15–30 min). If healthy, shifts the remaining traffic in a single final step.Low (Limits potential customer impact to the small canary slice during evaluation).Moderate (Canary baking window + cutover).Production workloads where you want to test new model weights with minimal blast radius before full enterprise cutover.
LinearShifts traffic in incremental step percentages (e.g., 20% every 5 minutes) across multiple steps until 100% is reached.Lowest (Gradual, continuous risk absorption across stepped intervals).Longest (Number of steps × step interval duration).High-volume, mission-critical production services where traffic increases must be gradual to verify backend dependencies.

3. Shadow Deployments (Dark Launching / Request Mirroring)

A Shadow Deployment allows you to evaluate a new model variant (Shadow Variant) under true production conditions—with real traffic volume, concurrency, and real-world payload distributions—with zero risk to the end-user experience.

+-----------------------------------------------------------------------------------------+
|                          SAGEMAKER SHADOW DEPLOYMENT FLOW                               |
|                                                                                         |
|                                   Client Request                                        |
|                                         |                                               |
|                                         v                                               |
|                           [HTTPS SageMaker Endpoint]                                    |
|                                         |                                               |
|               +-------------------------+-------------------------+                     |
|               | Request Duplicated / Mirrored by SageMaker Engine |                     |
|               |                                                   |                     |
|               v (Live Request)                                    v (Mirrored Copy)     |
|   +--------------------------+                        +--------------------------+      |
|   |       LIVE VARIANT       |                        |      SHADOW VARIANT      |      |
|   |    (Current Production)  |                        |       (New Model V2)     |      |
|   +--------------------------+                        +--------------------------+      |
|               |                                                   |                     |
|               v                                                   v                     |
|   [Prediction Response]                              [Response Discarded / S3]          |
|               |                                                   |                     |
|               v                                                   v                     |
|     Returned to Client!                              Captured for Offline Analysis      |
|     (SLA & Accuracy Safe)                            (Latency & Accuracy Comparison)    |
+-----------------------------------------------------------------------------------------+

Operational Mechanics of Shadow Mode:

  1. Dual Execution: SageMaker duplicates incoming requests in parallel. One copy is sent to the Live Variant, and an identical mirrored copy is sent to the Shadow Variant.
  2. Response Handling: The Live Variant processes the request and returns its prediction to the calling application. The Shadow Variant's response is never returned to the caller; it is discarded or captured to Amazon S3 via SageMaker Data Capture.
  3. Independent Performance Tracking: Amazon CloudWatch tracks latency, error rates, and resource utilization metrics separately for both variants (e.g., ModelLatency for LiveVariant vs. ModelLatency for ShadowVariant).
  4. Promotion: Once the engineering team verifies that the Shadow Variant meets latency SLAs, memory constraints, and prediction parity over several days, the Shadow Variant can be promoted to the Live Variant with zero downtime.

[!TIP] Exam Scenario Rule: If an exam question asks to "test a new model against live production traffic, validate latency, resource utilization, and prediction quality without any risk of serving erroneous predictions to customers," choose Shadow Deployment.


4. Automated Rollbacks with Amazon CloudWatch Alarms

Deployment guardrails achieve zero-downtime safety through automated monitoring and rollback triggers during the deployment's baking period.

Configuring CloudWatch Auto-Rollback Alarms

When defining the DeploymentConfig, you attach CloudWatch alarms to the AutoRollbackConfiguration. If any specified CloudWatch alarm enters the ALARM state during traffic shifting or the baking window, SageMaker immediately halts the deployment and initiates an automatic rollback.

+-----------------------------------------------------------------------------------------+
|                          AUTOMATED ROLLBACK DECISION TREE                               |
|                                                                                         |
|   [Traffic Shifting Active] ---> Canary: 10% Green / 90% Blue                           |
|               |                                                                         |
|               +----------------- CloudWatch Alarm Fires? ----------------+              |
|               |                                                          |              |
|               v (YES: e.g., 5XX Errors > 1% or Latency > 150ms)          v (NO)         |
|   [ABORT DEPLOYMENT]                                             [BAKING COMPLETES]     |
|   1. Instant 100% traffic rerouted to Blue Fleet                 1. Shift 100% to Green |
|   2. Green Fleet terminated automatically                        2. Terminate Blue Fleet|
|   3. Zero customer downtime; endpoint remains healthy            3. Deployment Succeeded|
+-----------------------------------------------------------------------------------------+

Critical CloudWatch Metrics for Rollback Alarms:

  • Invocation5XXErrors: Server-side model failures, container crashes, or unhandled exceptions.
  • Invocation4XXErrors: Client-side errors, payload schema mismatches, or serialization faults.
  • ModelLatency: The time taken by the model container to generate and return a prediction (detects performance regressions).
  • OverheadLatency: The time taken by SageMaker routing infrastructure before and after container execution.
  • CPUUtilization / GPUUtilization / MemoryUtilization: Hardware saturation indicating resource leaks.

Example: Boto3 Endpoint Update with Canary Guardrails & Rollback Alarms

import boto3

sagemaker_client = boto3.client('sagemaker')

response = sagemaker_client.update_endpoint(
    EndpointName='fraud-detection-realtime',
    EndpointConfigName='fraud-detection-v2-config',
    DeploymentConfig={
        'BlueGreenUpdatePolicy': {
            'TrafficRoutingConfiguration': {
                'Type': 'CANARY',
                'CanarySize': {
                    'Type': 'CAPACITY_PERCENT',
                    'Value': 10  # Route 10% traffic to Green fleet
                },
                'WaitIntervalInSeconds': 900  # 15-minute baking period
            },
            'TerminationWaitInSeconds': 300,  # 5 minutes before Blue teardown
            'MaximumExecutionTimeoutInSeconds': 3600
        },
        'AutoRollbackConfiguration': {
            'Alarms': [
                {'AlarmName': 'FraudModel-High5XXErrors'},
                {'AlarmName': 'FraudModel-HighModelLatency'}
            ]
        }
    }
)
Loading diagram...
SageMaker Production Deployment Patterns & Guardrails Flow
Test Your Knowledge

An ML engineer manages a real-time SageMaker endpoint hosting an e-commerce ranking model. The team has trained a new model version and wants to perform an A/B test by routing 85% of live production traffic to the existing model (Variant A) and 15% to the new model (Variant B). After two weeks of evaluation, the engineer needs to shift 100% of the traffic to Variant B with zero endpoint downtime and without creating a new endpoint configuration. Which approach satisfies these requirements?

A
B
C
D
Test Your Knowledge

A financial institution is deploying an updated credit risk scoring model to an existing SageMaker real-time endpoint. Because credit decisions directly affect customer loan approvals, the engineering team requires a deployment strategy where an initial 10% of production traffic is routed to the new model for a 20-minute baking period. If the model experiences elevated latency or container crashes, the deployment must automatically revert all traffic to the original model without human intervention. Which configuration meets these requirements?

A
B
C
D
Test Your Knowledge

A computer vision engineering team has trained a new deep learning defect detection model. Before serving predictions to the assembly line, the team must validate that the new model can handle peak production request throughput and maintain sub-50ms inference latency without any risk of returning incorrect defect classifications to factory workers. Which deployment pattern should the engineer implement?

A
B
C
D
Test Your Knowledge

An ML engineer configures a Blue/Green deployment for a SageMaker endpoint using Linear traffic shifting (20% step value every 5 minutes). During the third step (60% traffic on Green), the model container begins throwing memory allocation errors, causing the Invocation5XXErrors metric to breach its CloudWatch threshold. What immediate action will Amazon SageMaker take based on this breach?

A
B
C
D