> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Deployment Strategies and Rollback Actions

> Overview of ML deployment strategies, automated rollback mechanisms, AWS tooling, security, monitoring, disaster recovery, and best practices for safe reproducible production MLOps.

In this lesson we cover deployment strategies and rollback actions that keep ML application and model updates safe, predictable, and repeatable. This article explains common patterns, automated rollback flows, and AWS-focused tooling for production-grade MLOps.

Agenda:

* Fundamentals of ML deployment strategies
* How rollback mechanisms work
* AWS deployment types: blue-green, canary, linear, and A/B testing
* How rollbacks resolve production issues
* Key concepts related to ML workflow orchestration

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/iiCLxhVvY8hcANvo/images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/ml-deployment-agenda-session-topics.jpg?fit=max&auto=format&n=iiCLxhVvY8hcANvo&q=85&s=bf422597e6ac7c559ed54b4762e4a336" alt="The image displays an agenda for a session on machine learning deployment, including topics like ML deployment strategies, rollback mechanisms, AWS deployment types, and production issue management." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/ml-deployment-agenda-session-topics.jpg" />
</Frame>

## Four-step process for safe ML deployments

To reduce downtime and customer impact, use a consistent, four-step deployment approach:

1. Validate the model: run tests and compare metrics against production-like datasets to verify accuracy and performance.
2. Controlled release: expose the new model incrementally rather than switching traffic all at once.
3. Continuous monitoring: collect metrics and logs in real time to detect regressions and drift.
4. Instant rollback: automate the ability to revert to the last known-good version when thresholds are breached.

This methodology reduces risk, enables reproducibility, and ensures releases remain auditable.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/iiCLxhVvY8hcANvo/images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/safe-ml-deployment-process-diagram.jpg?fit=max&auto=format&n=iiCLxhVvY8hcANvo&q=85&s=4437b231115e71b78f2eb34cd2559832" alt="The image outlines a process for safe machine learning deployments, including steps like validating the model, controlled release, performance monitoring, and potential rollback, highlighting benefits such as reduced downtime, limited customer impact, and deployment readiness." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/safe-ml-deployment-process-diagram.jpg" />
</Frame>

## Example AWS-based deployment pipeline

A typical automated pipeline for ML on AWS:

* Source control: store model code, infra-as-code, and configs in a VCS such as AWS CodeCommit, GitHub, or GitLab.
* Orchestration: trigger CI/CD with AWS CodePipeline, GitHub Actions, or similar to run builds, tests, and deployments.
* Artifact: produce a trained model package or container image (ECR or model package in SageMaker).
* Hosting: serve the artifact with SageMaker real-time endpoints, batch transform jobs, or ECS/EKS containers.
* Observability: use CloudWatch, X-Ray, and SageMaker Model Monitor for metrics, traces, and drift detection.

These components give you clear rollback points and a repeatable MLOps workflow.

Helpful references:

* [Amazon SageMaker Documentation](https://docs.aws.amazon.com/sagemaker/)
* [AWS CodePipeline](https://docs.aws.amazon.com/codepipeline/)
* [Amazon CloudWatch](https://docs.aws.amazon.com/cloudwatch/)

Table: AWS toolchain mapping

| Pipeline stage      |                             AWS service examples | Purpose                              |
| ------------------- | -----------------------------------------------: | ------------------------------------ |
| Source Control      |                           `CodeCommit`, `GitHub` | Store code, training/serving configs |
| CI/CD Orchestration |                      `CodePipeline`, `CodeBuild` | Run builds, tests, deploy steps      |
| Artifact Storage    |          `S3`, `ECR`, `SageMaker Model Registry` | Persist model artifacts and images   |
| Hosting / Serving   |              `SageMaker Endpoints`, `ECS`, `EKS` | Real-time inference or batch jobs    |
| Observability       | `CloudWatch`, `X-Ray`, `SageMaker Model Monitor` | Metrics, traces, drift detection     |

***

## Deployment strategies

Below are common deployment patterns used in MLOps. Each strategy balances risk, complexity, and speed differently.

### Blue–green deployment

Blue–green deploys a new version into an isolated environment (green), validates it, and then switches production traffic from blue to green for near-zero downtime.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/iiCLxhVvY8hcANvo/images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/blue-green-deployment-aws-load-balancer.jpg?fit=max&auto=format&n=iiCLxhVvY8hcANvo&q=85&s=f79d508ee8d9b7b82fb2074c53ccdf5d" alt="The image illustrates a Blue/Green Deployment process, showing the transition from a current (Blue) environment to a new (Green) environment using AWS Load Balancer and AWS Route 53, with an emphasis on traffic switching." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/blue-green-deployment-aws-load-balancer.jpg" />
</Frame>

Key points:

* Route traffic with an Application Load Balancer or `Route 53`.
* Test the green environment in isolation before switching DNS or ALB target groups.
* Rollback is simple: direct traffic back to blue if problems appear.

### Canary deployment

Canary releases route a small fraction of production traffic to the new model to validate behavior under real load.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/iiCLxhVvY8hcANvo/images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/canary-deployment-sagemaker-traffic-diagram.jpg?fit=max&auto=format&n=iiCLxhVvY8hcANvo&q=85&s=5e5d08c9d41cd46778141a4ac1e80c34" alt="The image illustrates a Canary Deployment strategy, showing traffic gradually switching from an old model (90%) to a new model (10%) using SageMaker Endpoints. The diagram suggests that rollback diverts traffic back to the stable version." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/canary-deployment-sagemaker-traffic-diagram.jpg" />
</Frame>

Typical flow:

* Start with a small percentage (e.g., `5–10%`) of traffic to the canary.
* Monitor latency, error rate, and business KPIs.
* Gradually increase traffic when metrics remain within thresholds, or revert immediately on regressions.

### Linear (incremental) deployment

Linear deployments shift traffic in fixed increments (e.g., 0 → 20 → 50 → 100), validating at each step.

* Increase traffic in controlled steps and validate at each stage.
* If any step shows regressions, rollback to the previous stable percentage or to 0% immediately.

### A/B testing

A/B testing runs two or more model variants in parallel and compares their real-world performance using predefined metrics.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/iiCLxhVvY8hcANvo/images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/ab-testing-deployments-flowchart.jpg?fit=max&auto=format&n=iiCLxhVvY8hcANvo&q=85&s=d953076be63d467410f76d96c7b04465" alt="The image depicts a flowchart of A/B testing deployments, showing user traffic split between Model A (Control) and Model B (Variant), followed by a comparison of metrics and a decision to promote the winner or rollback." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/ab-testing-deployments-flowchart.jpg" />
</Frame>

Best practices:

* Define evaluation metrics and statistical significance thresholds before launching.
* Use consistent traffic splits (e.g., `50/50`) or business-driven ratios.
* Promote the winning model automatically or manually after validation.

Comparison of strategies

| Strategy    |           Risk |   Speed to 100% | Typical use case                            |
| ----------- | -------------: | --------------: | ------------------------------------------- |
| Blue–Green  | Low (isolated) |    Fast cutover | Major version changes                       |
| Canary      |         Medium |         Gradual | Validate behavior under production load     |
| Linear      |         Medium | Controlled pace | Incremental confidence increases            |
| A/B Testing |  Low to medium | Depends on test | Experimentation and metric-driven selection |

***

## Rollback mechanisms

A robust rollback reverts to a known-good state automatically when failures are detected.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/iiCLxhVvY8hcANvo/images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/rollback-mechanisms-flowchart-deploy-monitor.jpg?fit=max&auto=format&n=iiCLxhVvY8hcANvo&q=85&s=977910887a6de8c25ce77d80b84e500f" alt="The image is a flowchart illustrating rollback mechanisms, showing steps from deploying a new model to monitoring and detecting failures, with a rollback to a stable version if needed." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/rollback-mechanisms-flowchart-deploy-monitor.jpg" />
</Frame>

Typical automated rollback flow:

1. Deploy new version and enable active monitoring.
2. Continuously evaluate health and metric thresholds (latency, errors, KPI deltas).
3. If thresholds are breached, trigger an automated rollback to the last stable version.
4. Log events and analyze root causes to prevent recurrence.

Example pseudocode for automated rollback logic:

```yaml theme={null}
# Pseudocode for pipeline step that triggers rollback based on CloudWatch alarms
on_deploy:
  - enable_monitoring
  - wait: monitoring_window
  - if CloudWatchAlarm == ALARM:
      trigger_rollback(to: last_stable_model)
  - else:
      promote_traffic(step: next_percentage)
```

Automation options:

* Use `CloudWatch Alarms` + `EventBridge` to trigger Lambda/Runbook for rollback.
* Integrate alarms into CI/CD (CodePipeline) to stop promotions on failures.

***

## Security pillars for safe deployments

Combine access controls, encryption, and network isolation to harden your deployment platform.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/iiCLxhVvY8hcANvo/images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/security-deployments-iam-encryption-vpc.jpg?fit=max&auto=format&n=iiCLxhVvY8hcANvo&q=85&s=27532fe460c65d351e11824adb183f00" alt="The image outlines aspects of security in deployments, focusing on IAM roles and policies, encryption (KMS and TLS), and private networking (VPC)." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/security-deployments-iam-encryption-vpc.jpg" />
</Frame>

* IAM roles and least-privilege policies to control access to model artifacts and endpoints.
* Encrypt data at rest with `AWS KMS` and in transit with TLS.
* Use VPCs, private subnets, and security groups to restrict access to inference endpoints and data stores.

<Callout icon="lightbulb" color="#1CB2FE">
  Always apply the principle of least privilege for service roles and encrypt secrets and model artifacts at rest. Use private networking to reduce attack surface for inference endpoints.
</Callout>

***

## Monitoring and observability

Effective monitoring detects regressions, performance issues, and model drift early.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/iiCLxhVvY8hcANvo/images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/monitoring-deployments-metrics-logs-anomalies.jpg?fit=max&auto=format&n=iiCLxhVvY8hcANvo&q=85&s=389e188fb700868b238f633fea720292" alt="The image illustrates a process for monitoring deployments, including collecting metrics and logs, monitoring model drift, detecting anomalies, and taking alerts and actions." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/monitoring-deployments-metrics-logs-anomalies.jpg" />
</Frame>

Recommended tooling and practices:

* Capture logs, metrics, and traces with `CloudWatch` and `X-Ray`.
* Detect model quality degradation and data drift with `SageMaker Model Monitor`.
* Implement automated alerts and runbooks for critical thresholds to trigger rollback or mitigation steps.
* Store historical metrics for trend analysis and postmortems.

Reference: [Amazon SageMaker Model Monitor](https://docs.aws.amazon.com/sagemaker/latest/dg/model-monitor.html)

***

## Disaster recovery fundamentals

Plan for catastrophic failures via backups, replication, and tested restore procedures.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/iiCLxhVvY8hcANvo/images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/disaster-recovery-s3-versioning-replication-backups.jpg?fit=max&auto=format&n=iiCLxhVvY8hcANvo&q=85&s=f7854d0d61133f0a9d3f4d86a2fa92b6" alt="The image illustrates the disaster recovery basis, highlighting three key components: S3 Versioning, Cross-Region Replication, and Backups and Snapshots, all leading to Recovery and Restore." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/disaster-recovery-s3-versioning-replication-backups.jpg" />
</Frame>

Core practices:

* Enable S3 versioning to protect model artifacts from accidental deletion or overwrite.
* Use Cross-Region Replication (CRR) to protect against regional outages.
* Take regular backups and snapshots (EBS, RDS) for point-in-time recovery.
* Regularly test restore procedures and document recovery time objectives (RTO) and recovery point objectives (RPO).

***

## Anti-patterns to avoid

Avoid practices that increase production risk and reduce reproducibility.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/iiCLxhVvY8hcANvo/images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/anti-patterns-avoiding-version-control-deployment.jpg?fit=max&auto=format&n=iiCLxhVvY8hcANvo&q=85&s=fad1d47c87f764e02512372c3ee0a73a" alt="The image describes anti-patterns to avoid: no version control, manual deployment, and no monitoring, highlighting their respective issues." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/anti-patterns-avoiding-version-control-deployment.jpg" />
</Frame>

* No version control: experiments and production changes become unreproducible and hard to audit.
* Manual deployments: increase the chance of human error and inconsistent rollouts — prefer automated CI/CD.
* No monitoring: issues remain undetected until they cause business impact.

***

## Key takeaways

* Leverage blue–green, canary, linear, and A/B testing to stage and validate model releases.
* Secure deployments with least-privilege IAM, encryption (KMS/TLS), and VPC isolation.
* Instrument robust monitoring and automated rollback to recover quickly from regressions.
* Build backups, versioning, and cross-region replication into your disaster recovery plan.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/iiCLxhVvY8hcANvo/images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/deployment-strategies-security-ml-production.jpg?fit=max&auto=format&n=iiCLxhVvY8hcANvo&q=85&s=b762a8aa584b4573df4658825589f5c4" alt="The image is a summary slide outlining four strategies: using various deployment strategies, ensuring security and monitoring for compliance, applying rollback for resilience, and achieving reliable ML production aligned with exam goals. It is attributed to KodeKloud." width="1920" height="1080" data-path="images/AWS-Certified-Machine-Learning-Engineer-Associate/Deployment-and-Orchestration-of-ML-Workflows/Deployment-Strategies-and-Rollback-Actions/deployment-strategies-security-ml-production.jpg" />
</Frame>

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/aws-machine-learning-associates/module/c3d1a3a2-07f8-4702-8653-061263bb5db2/lesson/514de4c1-d32d-4965-9fc2-69963084fae1" />
</CardGroup>
