Introduction
Different deployment strategies balance speed, safety, and complexity. From simple rolling deploys to canary releases, choosing the right strategy depends on your risk tolerance and infrastructure.
Key Concepts
- Rolling Deploy: Update servers one at a time — Kamal's default strategy. Some servers run old code while others run new code during the transition.
- Blue-Green Deploy: Two identical environments — deploy to the inactive one, then swap traffic. Instant rollback by swapping back.
- Canary Deploy: Route a small percentage of traffic to the new version first, monitor for errors, then roll out fully.
Real World Context
A SaaS company with 10,000 active users uses canary deployments to route 5% of traffic to new code first. If error rates spike, they roll back instantly without affecting 95% of users.
Deep Dive
Rolling Deploy (Kamal Default)
Kamal deploys to one server at a time:
yaml# config/deploy.yml servers: web: hosts: - web1.example.com - web2.example.com - web3.example.com
bashkamal deploy # Deploys to each host sequentially
Blue-Green with Kamal Destinations
yaml# config/deploy.production.yml servers: web: hosts: - blue.example.com - green.example.com
bash# Deploy and verify kamal deploy --destination production curl https://myapp.com/health
Feature Flags
ruby# Gemfile gem 'flipper' gem 'flipper-active_record' # Usage if Flipper.enabled?(:new_checkout, current_user) render 'checkout/new' else render 'checkout/legacy' end # Enable for percentage of users Flipper.enable_percentage_of_actors(:new_checkout, 10)
Rollback
bash# Kamal auto-rolls back on health check failure # Manual rollback: kamal rollback
Common Pitfalls
- Deploying without feature flags for risky changes — A feature flag lets you disable a broken feature without rolling back the entire deploy.
- Not monitoring after deploy — Watch error rates and response times for 15-30 minutes after every deploy.
Best Practices
- Use rolling deploys for most changes — Kamal's default is safe and simple for the majority of deploys.
- Use feature flags for high-risk features — Wrap new features in flags so you can disable them instantly without redeploying.
Summary
- Rolling deploys (Kamal's default) update servers sequentially.
- Blue-green deployments allow instant rollback by swapping environments.
- Feature flags decouple deployment from feature activation.
- Always monitor error rates and response times after deploying.
Code Examples
ruby
# Feature flags decouple deploy from activation
if Flipper.enabled?(:new_pricing, current_user)
# New pricing logic
else
# Existing pricing logic
end
# Gradually roll out
Flipper.enable_percentage_of_actors(:new_pricing, 5) # 5%
Flipper.enable_percentage_of_actors(:new_pricing, 25) # 25%
Flipper.enable_percentage_of_actors(:new_pricing, 100) # Everyone