Skip to main content

Agent Skills Framework Extension

Deployment Strategy Patterns Skill

When to Use This Skill

Use this skill when implementing deployment strategy patterns patterns in your codebase.

How to Use This Skill

  1. Review the patterns and examples below
  2. Apply the relevant patterns to your implementation
  3. Follow the best practices outlined in this skill

Production deployment strategies for zero-downtime releases and risk mitigation.

Core Capabilities

  1. Blue-Green Deployments - Instant rollback, zero downtime
  2. Canary Releases - Gradual traffic shifting with metrics
  3. Rolling Updates - Incremental pod replacement
  4. Feature Flags - Runtime feature control
  5. Automated Rollback - Health-based automatic reversion

Blue-Green Deployment

# k8s/blue-green/blue-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-blue
labels:
app: myapp
version: blue
spec:
replicas: 3
selector:
matchLabels:
app: myapp
version: blue
template:
metadata:
labels:
app: myapp
version: blue
spec:
containers:
- name: myapp
image: myapp:v1.0.0
ports:
- containerPort: 8080
---
apiVersion: v1
kind: Service
metadata:
name: myapp-service
spec:
selector:
app: myapp
version: blue # Switch to 'green' for cutover
ports:
- port: 80
targetPort: 8080

Canary with Flagger

apiVersion: flagger.app/v1beta1
kind: Canary
metadata:
name: myapp
spec:
targetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp

service:
port: 80
targetPort: 8080

analysis:
interval: 1m
threshold: 5
maxWeight: 50
stepWeight: 10

metrics:
- name: request-success-rate
thresholdRange:
min: 99
interval: 1m

- name: request-duration
thresholdRange:
max: 500
interval: 1m

webhooks:
- name: load-test
url: http://flagger-loadtester/
timeout: 5s
metadata:
cmd: "hey -z 1m -q 10 -c 2 http://myapp-canary/"

Feature Flag Service

use std::collections::HashMap;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FeatureFlag {
pub name: String,
pub enabled: bool,
pub rollout_percentage: u8,
pub user_targeting: Vec<String>,
}

pub struct FeatureFlagService {
flags: HashMap<String, FeatureFlag>,
}

impl FeatureFlagService {
pub fn is_enabled(&self, flag_name: &str, user_id: &str) -> bool {
let flag = match self.flags.get(flag_name) {
Some(f) => f,
None => return false,
};

if !flag.enabled {
return false;
}

// Check user targeting
if flag.user_targeting.contains(&user_id.to_string()) {
return true;
}

// Check rollout percentage
let hash = self.hash_user_id(user_id);
let bucket = hash % 100;

bucket < flag.rollout_percentage
}

fn hash_user_id(&self, user_id: &str) -> u8 {
// Consistent hashing for stable rollout
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};

let mut hasher = DefaultHasher::new();
user_id.hash(&mut hasher);
(hasher.finish() % 100) as u8
}
}

Automated Rollback

import requests
import time
from typing import Dict

class AutomatedRollback:
def __init__(self, deployment_name: str, namespace: str):
self.deployment = deployment_name
self.namespace = namespace

def monitor_and_rollback(
self,
duration_minutes: int = 10,
error_threshold: float = 0.01
) -> bool:
start_time = time.time()
end_time = start_time + (duration_minutes * 60)

while time.time() < end_time:
metrics = self.get_metrics()

error_rate = metrics['errors'] / metrics['total_requests']

if error_rate > error_threshold:
print(f"Error rate {error_rate:.2%} exceeds threshold {error_threshold:.2%}")
self.rollback()
return False

time.sleep(30)

print("Deployment successful!")
return True

def get_metrics(self) -> Dict[str, int]:
# Query Prometheus or application metrics
return {'total_requests': 1000, 'errors': 5}

def rollback(self):
import subprocess
subprocess.run([
'kubectl', 'rollout', 'undo',
f'deployment/{self.deployment}',
'-n', self.namespace
])

Usage Examples

Blue-Green Cutover

Apply deployment-strategy-patterns skill to implement blue-green deployment with instant cutover

Canary Release

Apply deployment-strategy-patterns skill to configure canary release with 10% traffic and automated rollback

Feature Flags

Apply deployment-strategy-patterns skill to implement feature flag service with percentage rollout

Integration Points

  • cicd-automation-patterns - CI/CD integration
  • k8s-statefulset-patterns - Stateful deployments
  • cloud-infrastructure-patterns - Load balancer configuration

Success Output

When successful, this skill MUST output:

✅ SKILL COMPLETE: deployment-strategy-patterns

Completed:
- [x] Deployment strategy selected (blue-green|canary|rolling)
- [x] Infrastructure configured (K8s manifests|Flagger|feature flags)
- [x] Health checks implemented (readiness, liveness, metrics)
- [x] Rollback mechanism tested (automatic|manual)
- [x] Traffic shifting validated (gradual|instant)
- [x] Monitoring integrated (Prometheus, error rates)

Outputs:
- k8s/deployment.yaml (deployment manifest)
- k8s/service.yaml (service configuration)
- k8s/canary.yaml (Flagger canary if applicable)
- scripts/cutover.sh (blue-green switch script if applicable)
- monitoring/alerts.yaml (automated rollback rules)

Deployment Metrics:
- Downtime: 0 seconds (zero-downtime achieved)
- Rollback time: <60 seconds
- Error threshold: <1% during rollout
- Traffic shift: Gradual (10% increments) or Instant

Completion Checklist

Before marking this skill as complete, verify:

  • Deployment strategy matches risk profile (canary for high-risk, blue-green for instant rollback)
  • Health checks configured (HTTP probes, metrics endpoints)
  • Rollback mechanism tested in staging (automatic and manual)
  • Traffic shifting works correctly (gradual or instant as designed)
  • Monitoring alerts trigger on error rate threshold
  • Load balancer configured for chosen strategy
  • Feature flags implemented if needed (runtime control)
  • Deployment documented (runbook, rollback procedure)
  • Zero-downtime verified in staging
  • Performance metrics baseline established

Failure Indicators

This skill has FAILED if:

  • ❌ Downtime occurred during deployment (not zero-downtime)
  • ❌ Rollback mechanism didn't work (manual intervention required)
  • ❌ Health checks didn't detect bad deployment (false negative)
  • ❌ Traffic shifting caused service disruption
  • ❌ Monitoring didn't trigger automated rollback on errors
  • ❌ Feature flags broken or not accessible
  • ❌ Load balancer misconfigured (traffic not routing correctly)
  • ❌ Canary analysis failed to detect regressions

When NOT to Use

Do NOT use this skill when:

  • Development/staging environments (simpler deployment acceptable)
  • Single-instance applications (no need for gradual rollout)
  • Stateful services without replication (requires different strategy)
  • Database migrations (use migration-specific patterns)
  • Emergency hotfixes (may need direct deployment)
  • Non-production environments (overhead not justified)
  • Services with <100 requests/day (insufficient traffic for canary)

Use alternative skills:

  • simple-deployment-patterns - For dev/staging environments
  • database-migration-patterns - For schema changes
  • hotfix-deployment-patterns - For emergency fixes
  • stateful-deployment-patterns - For databases, queues

Anti-Patterns (Avoid)

Anti-PatternProblemSolution
No health checksBad deployments not detectedAlways implement readiness/liveness probes
Manual rollback onlySlow response to incidentsImplement automated rollback on error threshold
All-at-once traffic shiftHigh risk for regressionsUse gradual shift (10%, 25%, 50%, 100%)
No monitoring integrationBlind deploymentIntegrate Prometheus metrics, error rates
Deploying without testingProduction failuresAlways test strategy in staging first
Skipping rollback testingRollback fails when neededRegularly test rollback procedure
No feature flag fallbackCannot disable bad featuresUse feature flags for high-risk features
Blue-green without validationSwitch to broken versionValidate green environment before cutover

Principles

This skill embodies:

  • #5 Eliminate Ambiguity - Clear deployment strategy selection criteria
  • #8 No Assumptions - Test rollback, verify health checks
  • #11 Reliability - Zero-downtime deployments, automated rollback
  • #12 Observability - Monitoring integration, error rate tracking
  • Risk Mitigation - Gradual rollout, instant rollback capability
  • Production Safety - Health checks prevent bad deployments

Full Standard: CODITECT-STANDARD-AUTOMATION.md


Version: 1.1.0 | Updated: 2026-01-04 | Author: CODITECT Team