Applicability
When to Use
✓When you want to minimize blast radius of bad deploys
✓When gradual rollout reduces risk
✓When real user traffic validates better than tests
Overview
How It Works
Canary deployment sends a small percentage of traffic to the new version and monitors key metrics. If metrics look good, traffic is gradually increased (1% -> 5% -> 25% -> 50% -> 100%). If metrics degrade at any step, traffic is immediately rolled back.
The MCP agent manages the rollout: it adjusts traffic weights via the load balancer, monitors error rates and latency via Datadog, and makes the decision to proceed or rollback at each stage.
Implementation
Code Example
typescript
const stages = [1, 5, 25, 50, 100]; // traffic percentage
async function canaryRollout(newVersion) {
for (const percentage of stages) {
await kubernetes.setCanaryWeight({ deployment: "app", canaryWeight: percentage });
await slack.sendMessage({ channel: "#deploys", text: `Canary at ${percentage}%: ${newVersion}` });
// Monitor for 5 minutes at each stage
const baseline = await datadog.queryMetrics({ query: "avg:app.error_rate{version:stable}", from: "-1h" });
await sleep(5 * 60 * 1000);
const canary = await datadog.queryMetrics({ query: `avg:app.error_rate{version:${newVersion}}`, from: "-5m" });
if (canary.value > baseline.value * 1.5) {
await kubernetes.setCanaryWeight({ deployment: "app", canaryWeight: 0 });
await slack.sendMessage({ channel: "#deploys", text: `Canary rolled back at ${percentage}%: error rate ${canary.value} vs baseline ${baseline.value}` });
return;
}
}
await slack.sendMessage({ channel: "#deploys", text: `Canary complete: ${newVersion} at 100%` });
}Quick Info
Categorydeployment
ComplexityHard