Deployment Patterns
tenement supports zero-downtime deployments through weighted routing. Route traffic between instances using the ten weight command.
Weighted Routing
Section titled “Weighted Routing”Traffic to {service}.{domain} is distributed across all instances of that service based on their weights.
# Set instance weight (0-100)ten weight api:v1 80ten weight api:v2 20
# Check current weightsten psINSTANCE SOCKET UPTIME HEALTH WEIGHTapi:v1 /tmp/tenement/api-v1.sock 2d healthy 80api:v2 /tmp/tenement/api-v2.sock 5m healthy 20How it works:
- Requests to
api.example.comare load-balanced by weight - Direct requests to
v1.api.example.combypass weights (always route to v1) - Weight 0 excludes instance from traffic (but keeps it running)
Blue-Green Deployment
Section titled “Blue-Green Deployment”Deploy new versions with zero downtime by switching all traffic at once.
1. Deploy New Version
Section titled “1. Deploy New Version”# Current: api:blue handling all trafficten ps# api:blue weight=100
# Deploy new version as "green"ten spawn api --id green2. Test Green
Section titled “2. Test Green”# Direct requests to green bypass routingcurl https://green.api.example.com/health3. Switch Traffic
Section titled “3. Switch Traffic”# Instant cutoverten weight api:blue 0ten weight api:green 1004. Cleanup
Section titled “4. Cleanup”After verifying green works:
ten stop api:blueRollback
Section titled “Rollback”If issues arise:
ten weight api:green 0ten weight api:blue 100Canary Deployment
Section titled “Canary Deployment”Gradually shift traffic to test new versions with real users.
1. Deploy Canary
Section titled “1. Deploy Canary”# Current: api:v1 at 100%ten spawn api --id v2ten weight api:v2 0 # Start at 0%2. Gradual Rollout
Section titled “2. Gradual Rollout”# 5% canaryten weight api:v1 95ten weight api:v2 5
# Monitor for errors...
# 25% canaryten weight api:v1 75ten weight api:v2 25
# 50/50ten weight api:v1 50ten weight api:v2 50
# Full rolloutten weight api:v1 0ten weight api:v2 1003. Monitor
Section titled “3. Monitor”Watch metrics during rollout:
# Prometheus metricscurl https://example.com/metrics | grep api
# Instance healthten psRollback
Section titled “Rollback”At any point:
ten weight api:v2 0ten weight api:v1 100A/B Testing
Section titled “A/B Testing”Run experiments by splitting traffic between variants.
# 50/50 splitten spawn api --id controlten spawn api --id experiment
ten weight api:control 50ten weight api:experiment 50Each variant can run different code, configuration, or flags.
Multi-Instance Load Balancing
Section titled “Multi-Instance Load Balancing”Scale horizontally by running multiple instances of the same service.
# Spawn multiple instancesten spawn api --id prod-1ten spawn api --id prod-2ten spawn api --id prod-3
# Equal weights for round-robin-ish distributionten weight api:prod-1 33ten weight api:prod-2 33ten weight api:prod-3 34Traffic is distributed randomly based on weights.
Deployment Commands
Section titled “Deployment Commands”The ten deploy and ten route commands automate common deployment patterns:
ten deploy
Section titled “ten deploy”Spawn a new version and wait for it to become healthy:
# Deploy v2 with full trafficten deploy api --version v2
# Deploy v2 with initial weight (for canary)ten deploy api --version v2 --weight 10
# Deploy with custom health timeoutten deploy api --version v2 --timeout 60The deploy command:
- Spawns a new instance with the version as instance ID
- Waits for health checks to pass (default 30s timeout)
- Sets the initial traffic weight
ten route
Section titled “ten route”Atomically swap traffic between versions (blue-green):
# Route all traffic from v1 to v2ten route api --from v1 --to v2This sets v1 weight to 0 and v2 weight to 100 in a single operation.
Best Practices
Section titled “Best Practices”Always Test First
Section titled “Always Test First”# Spawn new versionten spawn api --id new
# Test directly (bypasses routing)curl https://new.api.example.com/healthcurl https://new.api.example.com/test-endpoint
# Then route trafficten weight api:new 10Monitor During Rollout
Section titled “Monitor During Rollout”- Watch error rates in logs
- Check Prometheus metrics
- Verify health checks pass
Keep Old Version Running
Section titled “Keep Old Version Running”Don’t stop the old version until the new one is verified:
# Old version at 0% but still runningten weight api:old 0
# Can instant rollback if neededten weight api:old 100ten weight api:new 0Use Instance Auto-Start for Critical Services
Section titled “Use Instance Auto-Start for Critical Services”[instances]api = ["prod"] # Always spawn on bootRouting Reference
Section titled “Routing Reference”| URL Pattern | Behavior |
|---|---|
{id}.{service}.{domain} | Direct to specific instance |
{service}.{domain} | Weighted routing across instances |
{domain} | Dashboard |
Examples:
v2.api.example.com→ always routes toapi:v2api.example.com→ weighted across allapi:*instancesexample.com→ dashboard
Next Steps
Section titled “Next Steps”- Configuration Reference - Full config options
- Production Deployment - TLS and systemd setup
- Troubleshooting - Common issues