You deploy to one canary host first and want to proceed only if its error rate is not worse than the rest. How do you script the decision?
AdvancedScenarioScenarios: deployments, user management and fleet operations
Answer
Situation read → Compare canary and baseline error rates over comparable recent traffic, with a minimum request count to avoid noise.
What I'd do →
rate() { # rate HOST -> "errors total" for the most recent 5,000 requests
ssh -n "$1" "tail -n 5000 /var/log/nginx/access.log" |
awk '{t++; if ($9 ~ /^5/) e++} END {print e+0, t+0}'
}
read -r ce ct < <(rate "$canary")
be=0 bt=0; for h in "${baseline[@]}"; do read -r e t < <(rate "$h"); be=$((be + e)); bt=$((bt + t)); done
(( ct >= 500 )) || die "canary has only $ct requests; not enough data"
awk -v ce="$ce" -v ct="$ct" -v be="$be" -v bt="$bt" \
'BEGIN {c = ce / ct; b = (bt ? be / bt : 0); printf "canary %.3f%% baseline %.3f%%\n", 100*c, 100*b
exit !(c <= b * 1.5 + 0.001)}' || { rollback "$canary"; exit 1; }
echo "canary healthy, continuing rollout"
Why → Relative comparison handles normal background errors; a minimum sample avoids judging on 10 requests.
Interview tip → Mention that Argo Rollouts or Flagger automate this with Prometheus queries, and that latency matters as much as errors.
More on Scenarios: deployments, user management and fleet operations
Write the core of a deploy script with release directories, an atomic symlink switch and rollback.IntermediateDeploy to 10 servers behind an AWS ALB one at a time, removing each from the target group during its deploy. Outline the script.AdvancedAfter a deploy, the health check fails intermittently. Your script must roll back automatically, but only if the failure persists. How?IntermediateImplement a blue/green switch on a single nginx host with a script.AdvancedOnboard 30 engineers: create accounts and install their SSH keys from their GitHub usernames, idempotently.IntermediateAn engineer leaves the company. Write the offboarding steps for Linux servers.Intermediate