Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 61

Deployment & Rollback Strategies

This lesson is built with resources from youtube.com, uber.com and 1 more site.

Hello! Welcome to your next lesson in the "Staff-Level System Design Depth" module.

In our last lesson, we constructed a comprehensive security model, covering authentication, authorization, and data protection to ensure our system is robust against threats. Now that we have a secure, observable system, the next critical step is to deploy new versions of it safely, without disrupting users or violating our service level objectives (SLOs).

Today's lesson addresses the learning outcome: Articulate a deployment and rollback strategy (e.g., blue-green, canary) for a critical service.

For a Staff-level engineer, this conversation is not just about defining terms. It's about demonstrating a deep understanding of risk management, automation, and the complex interplay between stateless application code and stateful data stores. You're expected to lead discussions on how to ship software quickly while maintaining the highest standards of reliability, a core tension in any large-scale engineering organization.

We will cover:

  1. The landscape of common deployment strategies.
  2. A deep dive into Blue-Green and Canary deployments.
  3. The critical challenge of handling database migrations during a release.
  4. A case study on how Uber manages deployments at scale.
  5. How to articulate a complete rollback plan.

1. The Landscape of Deployment Strategies

There are several established patterns for deploying software, each with a different profile of risk, cost, and complexity. A great engineer knows which tool to use for which job.

To get a broad overview of the most common strategies, let's start with a short, informative video.

Top 5 Most-Used Deployment Strategies

This video from ByteByteGo provides an excellent visual summary of the five most-used deployment strategies. It will help us establish a shared vocabulary and a high-level understanding of each approach.

Watch the entire video (about 9 minutes). As you watch, focus on the core mechanism of each strategy and its primary advantages and disadvantages. Big Bang: The all-at-once approach. Rolling: The incremental update. Blue-Green: The identical twin. Canary: The small-scale test. Feature Toggles: The in-code switch.

This video gives you a great mental map of the options. Here is a visual summary of the key patterns.

The Most Popular Deployment Strategies
This image provides a clear visual comparison of five key deployment strategies: Blue/Green, Canary, A/B Testing, Feature Flag, and Rolling. Each diagram illustrates how traffic is directed to new versions, offering a quick reference for their mechanics.

For a Staff-level interview, you should be able to summarize these trade-offs concisely. Here’s a comparative table to help structure your thoughts:

Strategy Downtime Risk Cost Rollback Speed Complexity Best For
Rolling Minimal/Zero Medium Low Slow Low Simple, stateless services
Blue-Green Zero Low High Instant Medium Critical apps where instant rollback is key
Canary Zero Very Low Medium Instant High Data-driven environments with mature monitoring

For critical services at companies like Google or Uber, simple Rolling deployments are often insufficient because a bad release can still affect a significant portion of users before it's detected. Blue-Green and Canary are the two primary strategies you should be prepared to discuss in depth.


2. Deep Dive: Blue-Green Deployment

As the video explained, Blue-Green deployment involves running two identical production environments: "Blue" (the current version) and "Green" (the new version).

  • Deployment: You deploy the new version to the Green environment, which is not yet receiving live traffic. You can run a full suite of tests (smoke tests, integration tests) against it with confidence.
  • Release: To release, you switch the router to send all traffic from Blue to Green.
  • Rollback: If something goes wrong, rollback is instantaneous. You simply switch the router back to Blue.

Staff-Level Discussion Points:

  • Primary Advantage: The key benefit is the near-zero risk rollback. Because the old Blue environment is kept running, you can revert traffic in seconds if the Green environment shows problems.
  • Major Drawback: Cost and State: The most obvious drawback is the cost of maintaining double the infrastructure. A more subtle, and arguably more difficult, challenge is managing stateful services, particularly databases. If the Green version requires a database schema change that is incompatible with the Blue version, a simple traffic switch will break the application for one of the versions.

This leads to a critical problem you must be able to solve.


3. Handling State: Zero-Downtime Database Migrations

How do you perform a Blue-Green deployment if v2 of your code requires a users table with a last_name column but v1 only expects a full_name column? This is a classic interview deep-dive question.

The solution is to decouple the code deployment from the database schema migration using a phased approach, often called the Expand and Contract pattern.

How do software projects achieve zero downtime database migrations?

This video explains the 'expand and contract' pattern, a robust technique for making backward-incompatible schema changes with zero downtime. This is a must-know pattern for discussing deployments of stateful systems.

Watch from 02:28 to 06:52. The video walks through the multi-step process of splitting a name column into first_name and last_name without downtime. Focus on the sequence of deployments and data migration steps.

Let's formalize the steps for your interview narrative:

  1. Expand (Phase 1):

    • Schema Change: Add the new first_name and last_name columns to your database, making them nullable. This change is backward-compatible; the old code will ignore them.
    • Code Deployment: Deploy new code that writes to both the old full_name column and the new first_name/last_name columns. It continues to read from the old full_name column. This ensures data consistency for new or updated records.
  2. Migrate (Phase 2):

    • Backfill: Run a background script to populate the new columns for all existing historical data. You do this by iterating through the old records, splitting full_name, and populating first_name and last_name. This can be done gradually to avoid load spikes.
  3. Switch (Phase 3):

    • Code Deployment: Once the backfill is complete, deploy new code that reads exclusively from the first_name and last_name columns. It may still need to write to the full_name column for rollback safety.
  4. Contract (Phase 4):

    • Code Deployment: After a period of monitoring and gaining confidence, deploy a final version of the code that no longer writes to or reads from the full_name column.
    • Schema Change: Drop the full_name column from the database.

Being able to walk through this four-phase process demonstrates your ability to think through the complexities of real-world deployments beyond simple stateless applications.


4. Deep Dive: Canary Deployment & Analysis

Canary deployment is the strategy of choice for data-driven organizations that want to validate a new release with real production traffic before a full rollout. It’s named after the "canary in a coal mine" analogy.

The core idea is to release the new version to a small subset of the production environment (e.g., 1% of servers or users). You then compare the performance of the "canary" group against the "control" group (the existing version).

This is where the Google SRE philosophy shines. A canary release is not just a deployment; it's a scientific experiment.

Canarying Releases - Google SRE Workbook

The Google SRE Workbook chapter 'Canarying Releases' is the definitive source on this topic. It reframes canarying as a process of managing risk against your error budget.

Please read the following sections: 'Balancing Release Velocity and Reliability': Understand how canaries help manage the trade-off between shipping features and maintaining SLOs. 'A Roll Forward Deployment Versus a Simple Canary Deployment': See the quantitative impact on error budget. 'Minimizing Risk to SLOs and the Error Budget': Focus on how canary population size limits the 'blast radius' of a bad release. 'Selecting and Evaluating Metrics': This is crucial. What makes a good canary metric? (SLIs are a great start). 'Requirements on Monitoring Data': Emphasizes the need for monitoring to be able to differentiate between canary and control versions.

Staff-Level Discussion Points:

  • Tied to SLOs and Error Budgets: A powerful way to frame this is: "We use a canary to spend a small, controlled portion of our error budget to gain confidence in a release. If the canary's error rate exceeds a predefined threshold, we've spent our 'testing budget' for this release, and we automatically roll back."
  • Automated Canary Analysis (ACA): The goal is not to have humans stare at dashboards. A mature canary process uses statistical analysis to automatically compare key SLIs (latency, error rate, saturation) between the canary and control groups. If the canary performs statistically worse, the deployment is automatically halted and rolled back.
  • Progressive Rollouts: A canary release is often the first step in a multi-stage progressive rollout. For example:
    • Stage 1: Canary to 1% of traffic for 30 minutes. Run ACA.
    • Stage 2: If successful, expand to 10% for 1 hour. Continue ACA.
    • Stage 3: If successful, expand to 50% for 2 hours. Continue ACA.
    • Stage 4: Roll out to 100%.

5. Case Study: Continuous Deployment at Uber

Articulating these strategies in the context of a company like Uber or Google demonstrates that you can apply theory to complex, real-world environments. Uber's approach is particularly insightful because it deals with a large monorepo where a single change can affect thousands of microservices.

Continuous deployment for large monorepos | Uber Blog

This Uber Engineering blog post details how they reimagined their continuous deployment (CD) system. It's a masterclass in applying deployment strategies at extreme scale.

Read the sections 'Designing for automation' and 'Post-release observations'. Pay special attention to: How they determine the 'impact' of a commit in a monorepo. The new challenges that arose from faster, automated deployments. Their solution: staggering deployments according to service tiering.

Key Takeaways for Your Interview Narrative:

  • Blast Radius of Shared Libraries: Acknowledge that in a monorepo, a change to a common library is extremely high-risk. A simple 1% canary across all affected services could still bring down the entire system if the library is fundamental.
  • Tiered Deployments (A Staff+ Strategy): This is Uber's brilliant solution. You can articulate it as: "To mitigate the risk of shared library changes, we would implement a tiered deployment strategy. We classify services into tiers of criticality (e.g., Tier 0 for most critical, Tier 3 for least). A risky change is first deployed only to Tier 3 services. We let it 'bake' there and monitor its health. Only if it succeeds do we promote the deployment to Tier 2, and so on. This contains the blast radius of a bad change to our least critical systems."
  • Deployment Systems Must Be Operationally Aware: A key insight from the Uber article is that their CD system is tightly coupled with their observability stack. It is aware of alerts and will automatically pause deployments if a service is unhealthy, preventing further damage.

Conclusion

You are now equipped to articulate a sophisticated and realistic deployment and rollback strategy for a critical service. You can move beyond simple definitions to a nuanced discussion of trade-offs, risk management, and advanced patterns used at top-tier companies.

Key Takeaways:

  • Structure Your Answer: Start by comparing the main strategies (Rolling, Blue-Green, Canary) and their trade-offs.
  • Address the Stateful Challenge: Immediately show your depth by discussing the Expand and Contract pattern for zero-downtime database migrations.
  • Frame Canary as a Data-Driven Process: Talk about canary analysis in the context of SLOs, error budgets, and automation (ACA).
  • Use Advanced, Real-World Examples: Discussing tiered deployments for monorepos (the Uber model) or tying canary analysis to SRE principles (the Google model) will clearly signal your Staff-level experience.
  • Don't Forget Rollbacks: A deployment strategy is incomplete without a rollback plan. For each strategy, be ready to explain how you would revert a change, emphasizing the need for automation.

Preview of the Next Lesson:
We've covered deploying a new version of a service. The next lesson will elevate this concept to an even larger scale. We will learn to: Propose phased migration strategies for redesigning or replacing existing systems. This involves orchestrating deployments and traffic shifting not just for a single service, but across multiple new and old systems during a major architectural evolution.