DevOps  

Implementing Blue-Green Deployment for Zero Downtime in .NET

Modern web applications must run continuously without impacting users during updates. Whether you deploy an ASP.NET Core API, an Angular front-end, or a SQL-backed enterprise system, service interruptions can affect business operations and customer experience.

Blue-Green Deployment is a proven deployment strategy that ensures zero downtime, reduces deployment risk, and provides instant rollback capabilities.

This article explains the concept, benefits, workflow, and practical steps for implementing Blue-Green Deployment in .NET applications.

What Is Blue-Green Deployment?

Blue-Green Deployment is a technique where two identical production environments run side-by-side:

  • Blue Environment – the current live system

  • Green Environment – the new version you want to deploy

Traffic is routed to only one environment at a time. After deploying and testing the new version in the Green environment, you switch traffic from Blue to Green instantly. If any issue appears, you can immediately switch back to Blue.

This provides true zero-downtime deployment and fast rollback.

Why Use Blue-Green Deployment?

Key advantages include:

  • Zero downtime during deployment

  • Safe, quick rollback

  • Fully testable production-like environment

  • No impact on active users

  • Cleaner deployment pipeline

  • Ideal for microservices, APIs, and UI applications

Blue-Green Deployment: High-Level Workflow

  1. Current version runs in Blue environment.

  2. New version is deployed to Green environment.

  3. Functional, integration, and smoke testing are performed on Green.

  4. Once validated, traffic is routed from Blue → Green.

  5. Green becomes the new live production environment.

  6. Blue is kept as rollback backup until stable.

Flowchart: Blue-Green Deployment Process

               +---------------------------+
               |       Start Deployment    |
               +-------------+-------------+
                             |
                             v
                 +-----------+-------------+
                 | Deploy new version to   |
                 |     GREEN environment   |
                 +-----------+-------------+
                             |
                             v
                +------------+------------+
                | Perform smoke and QA    |
                | testing on GREEN        |
                +------------+------------+
                             |
               +-------------+-------------+
               |   Tests Passed?           |
               +------+---------+----------+
                      |         |
                      | Yes     | No
                      v         v
        +-------------+--+   +--+---------------------+
        | Switch traffic |   | Fix issues in GREEN    |
        | BLUE → GREEN   |   | Redeploy and retest    |
        +-------------+--+   +-------------------------+
                      |
                      v
          +-----------+------------+
          |     GREEN is Live      |
          +-----------+------------+
                      |
                      v
       +--------------+------------------+
       | BLUE kept as rollback backup    |
       +--------------+------------------+
                      |
                      v
              +-------+--------+
              | Deployment Done|
              +----------------+

How Blue-Green Deployment Works in .NET

1. Prepare Two Production Environments

Both environments must be identical:

  • Same configuration

  • Same networking

  • Same database connections

  • Same infrastructure (IIS, Kestrel, Azure App Service, AWS, Docker, Kubernetes, etc.)

Example environment naming:

  • app-prod-blue.mycompany.com

  • app-prod-green.mycompany.com

Approaches to Implement Blue-Green Deployment in .NET

Method 1: Azure App Service Slots (Most Recommended for .NET Applications)

Azure App Service provides Deployment Slots, which naturally follow the Blue-Green pattern.

  • Production slot → Blue

  • Staging slot → Green

Steps

  1. Deploy new version to Staging slot (Green).

  2. Test the application.

  3. Swap slots to make Green live.

  4. Old Blue becomes backup.

This method ensures instant DNS-level traffic switching with no downtime.

Method 2: Kubernetes (AKS/EKS/GKE)

Kubernetes supports Blue-Green deployment using:

  • Separate Deployments for Blue and Green

  • Controlled traffic routing through Services or Ingress

For example

apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-green
spec:
  replicas: 3

After testing Green, update Ingress to point traffic from Blue to Green.

Method 3: Nginx or Load Balancer Routing

If hosting on-premises or VM-based infrastructure:

  • Keep Blue and Green running on separate servers

  • Update your Nginx, HAProxy, or Load Balancer config to switch traffic

Example Nginx routing

upstream app_live {
    server blue.example.com;
    # Switch to green:
    # server green.example.com;
}

Traffic routing is instant.

Method 4: IIS + DNS Switch (Basic Approach)

For smaller applications:

  1. Deploy Green on a separate IIS instance

  2. Change DNS record to point to Green

  3. Keep Blue in standby

DNS-level propagation must be configured with minimal TTL for near-instant switching.

Handling Databases in Blue-Green Deployment

Database changes are the most sensitive part. Follow these guidelines:

  1. Use backward-compatible database migrations

  2. Introduce schema changes first, use them later

  3. Never break existing APIs during switch

  4. Use feature flags when needed

  5. Avoid destructive migrations during deployment

Blue-Green is easier if your DB remains shared.

Rollback Strategy

If any issue appears after switch:

  1. Route traffic back to Blue immediately

  2. Disable Green until fixed

  3. Redeploy the corrected version to Green

This rollback is instant and does not require downtime.

Best Practices

  • Automate builds and deployments through CI/CD

  • Perform smoke tests on Green before switching

  • Keep monitoring dashboards active during switch

  • Log separate metrics for Blue and Green

  • Use feature flags for risky features

  • Keep switches reversible for a few hours after deployment

Conclusion

Blue-Green Deployment provides one of the safest and most reliable ways to deploy .NET, Angular, or SQL Server–based applications without any downtime. By maintaining two identical environments and switching traffic only after verifying the new version, teams can ensure business continuity, quick rollback, and confidence in production releases.

Whether you use Azure App Service, Kubernetes, a load balancer, or on-premises servers, Blue-Green Deployment significantly improves deployment reliability for enterprise-grade web applications developed using ASP.NET Core.