Problem Statement
Deploying a new version of a service to all users at once can cause widespread failures if the new version has bugs or performance issues. This can lead to downtime, loss of revenue, and damage to user trust.
This diagram shows users sending requests to a load balancer that routes a small portion to the canary group running the new version, while the rest go to the stable group running the old version.
### Before (No Canary Deployment) ### class ServiceDeployer: def __init__(self, instances): self.instances = instances def deploy(self, version): # Deploy new version to all instances at once for instance in self.instances: instance.update(version) ### After (With Canary Deployment) ### class ServiceDeployer: def __init__(self, instances): self.instances = instances def deploy(self, version): # Deploy new version to canary instances only canary_instances = self.instances[:int(len(self.instances)*0.1)] for instance in canary_instances: instance.update(version) # Monitor canary instances if self.monitor_canary(): # Deploy to remaining instances for instance in self.instances[int(len(self.instances)*0.1):]: instance.update(version) else: self.rollback(canary_instances) def monitor_canary(self): # Simplified monitoring logic return all(instance.is_healthy() for instance in self.instances[:int(len(self.instances)*0.1)]) def rollback(self, instances): for instance in instances: instance.rollback()