Safe Deployment and Rollback Strategies Questions
Releasing changes to production safely and incrementally, and recovering when they fail: blue-green, canary, and rolling deployments, feature flags, dark launches, traffic shifting, and progressive rollout, together with rollback strategies, safe-deploy practices, blast-radius containment, automated recovery, and safe forward/backward migration. Covers deployment orchestration across cloud platforms, staged exposure of new behavior to users, assessing deployment risk, designing reversible releases, and restoring a known-good state quickly. Focuses on how a release reaches production and how it is unwound on failure, distinct from broader incident command, which lives in Enterprise Operations & Incident Management.
Walk through blue-green deployment end to end: preparing the second environment, validating it, and cutting traffic over via DNS or a load balancer. What happens to session affinity and database state during the cutover, and why does this pattern give near-instant rollback at roughly double the infrastructure cost?
Sample Answer
Direct answer
Blue-green deployment runs two full, identical production environments, "blue" (currently live) and "green" (the new version), and switches all traffic from one to the other at once via a DNS change or load-balancer reconfiguration, rather than gradually. Because the previous environment stays fully running and untouched, rollback is just switching traffic back, which is close to instant.
Structured elaboration
- Prepare: deploy the new version into the idle environment (green) while blue continues serving all production traffic.
- Validate: run smoke tests and synthetic checks against green directly, without exposing it to real users yet, since it's on its own environment.
- Cut over: repoint the load balancer or update DNS so all new traffic goes to green. A load-balancer switch is effectively instant; a DNS switch is delayed by however long clients cache the old DNS TTL, which is why teams that need a fast cutover keep TTLs short or use a load balancer instead of DNS for the switch.
- Monitor and hold: keep blue running, unmodified, for some period after cutover specifically so rollback is available without a redeploy.
- Decommission: once green is proven stable, blue becomes the new idle environment for the next release (roles swap).
Session affinity and database state: stateless web frontends are the easy case: any request can go to either environment. Sticky sessions complicate the cutover, since a user mid-session on blue needs to either finish there or have their session state migrated to green. The database is usually the real complication, because you typically can't run two full database copies and keep them in sync cheaply, so both blue and green usually share ONE database, which means any schema change has to be compatible with BOTH the old and new application code during the window when either might be live.
Worked example
A stateless API service with a shared Postgres database: blue-green here is mechanically simple because the database is shared and unaffected by the switch. If the release also renamed a column, that rename would need to happen as a separate, backward-compatible expand-contract migration BEFORE the blue-green cutover, not as part of it, precisely because a straight rename would break whichever environment is still live during validation.
Trade-offs and pitfalls
Blue-green roughly doubles your running infrastructure cost for the duration both environments exist, which is the main reason teams don't leave it running indefinitely. The most common mistake is treating the database as if it participates in the blue-green switch the same way stateless compute does; it doesn't, and schema changes need their own compatibility discipline layered on top.
Design a canary-plus-shadow rollout for a high-traffic recommendation model: traffic splits for each phase, what you'd compare between baseline and candidate, and how you'd control for environment differences like caching and cold-start.
Sample Answer
Direct answer
A canary-plus-shadow rollout for a recommendation model runs the candidate in two phases: first purely in shadow (receiving a copy of real traffic, its outputs logged but never shown to users) to validate correctness and performance without any user risk, then as a genuine traffic-splitting canary (a small percentage of users actually seeing its recommendations) to validate the metric that matters most, actual user response, which shadow mode can't measure.
Structured elaboration
- Shadow phase: mirror a copy of production requests to the candidate model, log its outputs alongside the incumbent's, but serve users only the incumbent's response. This validates latency, error rate, and output-distribution sanity (are recommendations wildly different in a suspicious way) with zero user-facing risk, since nothing shown to users depends on the candidate yet.
- Canary phase: after shadow mode looks clean, actually split live traffic (say 1-5% to the candidate) so real user engagement metrics (click-through, downstream conversion) can be measured, since shadow mode fundamentally can't tell you how users RESPOND to different recommendations, only whether the model runs correctly.
- What to compare between baseline and candidate: in shadow, compare output distributions (are recommended items reasonable, is there a spike in a suspicious category) and system metrics (latency, error rate); in canary, compare actual engagement metrics (CTR, session length, downstream conversion) between the traffic split groups.
- Controlling for caching and cold-start differences: the candidate model, freshly deployed, likely has cold caches (feature caches, embedding lookups) that the long-running incumbent doesn't, which can make the candidate look artificially slower or even functionally different (colder feature values) in an early comparison purely due to warm-up, not the model itself. Mitigate by excluding an explicit warm-up window from analysis, and by pre-warming caches for the candidate before it starts receiving even shadow traffic where feasible.
Worked example
A candidate ranking model runs in shadow for 24 hours against 100% of traffic (mirrored, not affecting users), during which its p99 latency, output-distribution sanity checks, and error rate are compared to the incumbent; the first 30 minutes of shadow data are excluded from the analysis specifically to let feature caches warm up. Once shadow looks clean, the candidate moves to a genuine 2% traffic canary for several days (long enough to accumulate a meaningful sample of the actual engagement metric, which moves more slowly and noisily than a system metric), comparing CTR and session-length between the 2% candidate group and a matched 2% control group of the incumbent.
Trade-offs and pitfalls
Shadow mode is safe but incomplete: a model can pass shadow validation perfectly and still regress a real business metric once actual users see and respond to its outputs differently than the incumbent's, which is exactly why the canary phase can't be skipped even after a clean shadow run. The common mistake is treating cold-start effects as noise to ignore rather than an artifact to explicitly control for, which can make a perfectly good candidate look worse than it is during the earliest part of validation.
Compare blue-green, canary, and rolling deployments (and note where a plain recreate deployment still fits). For each, explain how traffic is shifted, the resulting rollback complexity, the infrastructure cost, and which kind of service (stateless vs. stateful) it suits best.
Sample Answer
Direct answer
Blue-green, canary, and rolling all reduce the risk of a bad release, but through different mechanisms: blue-green switches ALL traffic at once between two full environments, canary exposes a small SLICE of traffic to the new version before widening it, and rolling replaces instances gradually IN PLACE. A plain recreate deployment, by contrast, tears down the old version entirely before starting the new one, accepting downtime in exchange for simplicity.
Structured elaboration
| Strategy | Traffic shift | Rollback complexity | Infra cost | Best for |
|---|---|---|---|---|
| Blue-green | All-at-once, via LB/DNS switch | Low (switch back) | High (2x during overlap) | Stateless services needing near-instant rollback |
| Canary | Gradual, percentage-based | Low-medium (shrink canary slice) | Low-medium (small extra capacity) | High-traffic services where blast-radius control matters most |
| Rolling | Gradual, instance-by-instance in place | Medium (redeploy previous version, also gradual) | Low (no duplicate fleet) | Stateless services where some capacity reduction during rollout is acceptable |
| Recreate | All-at-once, old torn down first | Trivial (redeploy old version) but WITH downtime | Lowest | Low-traffic or maintenance-window-tolerant services |
Rollback complexity nuance: blue-green's rollback is fastest because the old environment never stopped running; canary and rolling both have to actively redeploy or re-route, which takes real time even if it's automated; recreate's "rollback" is simple mechanically but means accepting a second period of downtime.
Stateful services: all three of blue-green/canary/rolling get significantly harder with state (a database, in-memory session data, local disk), because you can't just duplicate or partially expose the data layer the way you can stateless compute; the deployment strategy for the STATELESS layer often decouples from a separate, more careful strategy for the DATA layer.
Worked example
A stateless API fronting a shared database: canary is a strong default, since it limits blast radius on the code change while the shared database (which doesn't get canaried the same way) stays constant underneath. Blue-green would be a better fit if the team's top priority is minimizing time-to-rollback over minimizing blast radius, since flipping back to the old environment is close to instant.
Trade-offs and pitfalls
There's no universally "best" strategy: the choice trades off blast radius, rollback speed, infrastructure cost, and operational complexity, and the right answer depends on which of those the specific service and change profile cares about most. A common mistake is picking a strategy based on what's trendy (everyone reaches for canary) rather than what the actual risk profile of the change calls for; a low-risk config change might not need any of this ceremony at all.
What are feature flags, and what different categories of flag exist based on who owns them and how long they're meant to live? What pitfalls tend to show up as flags accumulate over time?
Sample Answer
Direct answer
Feature flags are runtime switches that let you turn a piece of behavior on or off without a redeploy, which decouples DEPLOYING code from RELEASING a feature to users. The common types are a release flag (temporarily gates a feature during rollout, meant to be removed once it's fully live), an experiment flag (drives an A/B test, removed once the experiment concludes), an operational flag (a longer-lived control, like a rate limiter toggle or a maintenance-mode switch), and a kill-switch (an emergency, instant off-switch for something risky).
Structured elaboration
- Release flags: owned by the engineer shipping the feature; short-lived by design, meant to be deleted once the feature is fully rolled out and stable.
- Experiment flags: owned jointly by product/data science and engineering; lifetime tied to the experiment's duration, removed once a winner is chosen.
- Operational flags: owned by the team operating the service; can be long-lived (a genuinely permanent operational lever), which is the ONE type where "long-lived" isn't automatically a problem.
- Kill-switches: owned by whoever's on-call; meant to be exercised rarely but tested regularly so it's trustworthy when actually needed.
- Common pitfalls as flags accumulate: flag debt (release flags that were never cleaned up after the feature fully shipped, cluttering the codebase with dead branches), flag sprawl (so many flags that nobody can reason about which combinations of flag states are even possible, let alone tested), and stale defaults (a flag's fallback value drifts out of sync with what's actually safe as the surrounding code evolves).
Worked example
A team ships a new checkout flow behind a release flag, ramps it from 5% to 100% of users over two weeks while watching conversion metrics, then deletes the flag and the old code path once it's fully rolled out and stable for a monitoring period. If that deletion step gets skipped (a common failure under deadline pressure to move to the next feature), six months later the codebase has a flag nobody remembers the purpose of, defaulting to a value nobody's sure is still correct.
Trade-offs and pitfalls
Flags buy real safety (instant, redeploy-free control over risky behavior) at the cost of code complexity: every flag is effectively a branch that has to be reasoned about and eventually tested in both states. The single most common failure mode in practice isn't misusing a flag while it's active, it's forgetting to remove it once its job is done, which is why healthy flag programs bake in an explicit cleanup step (an expiration date, a dashboard of stale flags, or a policy that blocks new flags until old ones are retired) rather than relying on developers to remember.
You deployed a new model version and shortly after notice a meaningful regression in a key metric. What rollback options do you have (hot-swap to the previous model, disable via a feature flag, blue-green rollback, abort a canary, fall back to shadowing), and what determines which you'd use?
Sample Answer
Direct answer
When a newly deployed model shows a real regression, the rollback options range from fastest-but-broadest to slower-but-more-targeted: a feature-flag disable or hot-swap to the previous model version are usually the fastest and safest first moves, while aborting an in-progress canary or falling back to shadow mode are options specifically available if you hadn't yet fully committed the new model to live traffic.
Structured elaboration
- Feature-flag disable: if the new model sits behind a flag, flipping it off instantly routes back to the previous model or a fallback rule-based path, with no redeploy needed; this is usually the fastest option and the first one to reach for if it's available.
- Hot-swap to the previous model: if the serving infrastructure keeps the previous model version warm and loadable, switching the active model pointer is close to instant and doesn't require a full redeploy of the serving service, only a config/pointer change.
- Blue-green rollback: if the model was deployed via a blue-green pattern at the serving-infrastructure level, switching traffic back to the previous serving environment is as fast as any blue-green rollback, at the cost of the infrastructure overhead of having kept a full previous environment warm.
- Aborting a canary: if the regression is caught while the new model is still only receiving a slice of traffic (not yet fully promoted), simply stopping the canary and routing all traffic back to the previous model is both fast and low-risk, since most traffic was never exposed to the bad model in the first place.
- Falling back to shadowing: if you're not confident the previous model is the right target either (maybe you want to keep learning about the new model's behavior without exposing users to it), routing the new model to shadow mode (receiving a copy of traffic but not affecting real responses) while live traffic goes back to the previous model gets you both safety and continued visibility.
Time-to-recovery and validation, roughly fastest to slowest: feature-flag disable and canary-abort are typically seconds; hot-swap is seconds to low minutes depending on model-loading time; blue-green rollback is minutes; each needs post-rollback validation that the false-positive rate (or whatever the regressed metric was) has actually returned to baseline on the RESTORED model, not just an assumption that reverting fixes it, since the regression could in principle have a cause unrelated to the model itself (a data-pipeline issue feeding both versions, for example).
Worked example
A model regression discovered via a 7% false-positive increase, with the new model deployed behind a feature flag at 100% traffic (fully promoted, not mid-canary): flip the flag to route back to the previous model immediately (seconds), then validate the false-positive rate over the next several minutes of restored traffic actually returns to its prior baseline, confirming the rollback addressed the regression rather than coinciding with an unrelated fix.
Trade-offs and pitfalls
The biggest pitfall is treating "we rolled back" as automatically meaning "the problem is solved" without validating the metric actually recovers; if the false-positive spike was caused by an upstream data issue affecting BOTH models, rolling back the model alone wouldn't fix it, and validation is what catches that distinction. The other common mistake is not having ANY of these fast paths (no flag, no hot-swap capability, no blue-green) available for a model deployment, forcing a full redeploy as the only option even for the highest-stakes, fastest-moving incidents.
Unlock Full Question Bank
Get access to all 16 Safe Deployment and Rollback Strategies interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.