Skip to main content
Mark Ku's Blog

Why Use Rolling Updates for Applications?

Today's e-commerce sites operate nearly 24/7, 365 days a year, meaning users could be on the system at any time. With traditional deployment methods, the website is unavailable during the update process. This can lead to a poor user experience, such as users seeing error pages or being forcibly logged out. If maintenance downtime is too long, users might turn to other platforms to place their orders, resulting in customer churn.

Rolling deployments, on the other hand, reduce deployment downtime, provide a better user experience, and increase the system's operational uptime.

According to Six Strategies for Application Deployment, rolling deployment is a relatively easy strategy to implement. This post outlines a design for a rolling deployment using Microsoft's open-source .NET project, YARP, for software load balancing.

Design Approach

1. First, Group the Servers

YARP load balancer distributing user traffic to two server batches In the LTM (Local Traffic Manager), we divide the servers into three groups: All Server, Batch A, and Batch B. Depending on the deployment phase, the LTM will switch traffic to different active server groups.

All Server Group 192.168.0.1 192.168.0.2 192.168.0.3 192.168.0.4

Batch A Group 192.168.0.1 192.168.0.3

Batch B Group 192.168.0.2 192.168.0.4

2. Deployment Process for Batch A Server Group (Users Served by Batch B)

Rolling update design with YARP load balancer directing traffic to server batche
Rolling update design with YARP load balancer directing traffic to server batche

1. Call the LTM API to switch traffic to the Batch B group.

2. Deploy the application.

3. Perform internal testing.

4. Call the LTM API to switch traffic to the Batch A group.

3. Deployment Process for Batch B Server Group (Users Served by Batch A)

YARP reverse proxy deployment architecture with Batch A, Batch B, GitLab
YARP reverse proxy deployment architecture with Batch A, Batch B, GitLab

1. Deploy the application.

2. Perform internal testing.

3. Call the LTM API to switch traffic to the All Server group.

4. Verify the Production Environment

5. Complete the Application Deployment

Special Considerations

  • If the backend API has changes, it must be deployed before the frontend.
  • On the backend, APIs must remain backward-compatible for several versions before obsolete features can be removed.

How to Implement

Finally, by referencing the sample code in Microsoft's official YARP documentation, we can see that it's easy to specify a server group (Cluster) using ReassignProxyRequest and modify the current group via an API to achieve both A/B testing and rolling deployments. However, as I haven't had time to implement this yet, I'm just writing down the design concept for now.

public void Configure(IApplicationBuilder app, IProxyStateLookup lookup)
    {
        app.UseRouting();
        app.UseEndpoints(endpoints =>
        {
            endpoints.MapReverseProxy(proxyPipeline =>
            {
                // Custom cluster selection
                proxyPipeline.Use((context, next) =>
                {
                    if (lookup.TryGetCluster(ChooseCluster(context), out var cluster))
                    {
                        context.ReassignProxyRequest(cluster);
                    }

                    return next();
                });
                proxyPipeline.UseSessionAffinity();
                proxyPipeline.UseLoadBalancing();
            });
        });
    }

private string ChooseCluster(HttpContext context)
{
        // Decide which cluster to use. This could be random, weighted, based on headers, etc.
        return Random.Shared.Next(2) == 1 ? "cluster1" : "cluster2";
}

References

Previous article I wrote about YARP

YARP Official Documentation - A/B testing

Thoughts and Introduction to Zero-Downtime Application Publishing

Six Strategies for Application Deployment

Author

Mark Ku

10 年以上的軟體工程師,做過北美電商與 AI SaaS 訂閱收費系統。Read More

Found this useful?

The author's free tools, daily podcasts and newsletter are all here.

Mark Ku · This article is licensed under CC BY 4.0. Credit the author and link back to the original when reusing it.

Comments

Subscribe to Newsletter

Subscribe to get new posts delivered instantly — never miss a tech share.

By submitting, you agree to receive emails. You can anytime.

Popular Posts

View all
Mark Ku
··647

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution
Mark Ku
··465

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.
Mark Ku
··277

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki
Mark Ku
··216

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1
Mark Ku
··210

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning
Mark Ku
··209

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Setting Up Samba on Ubuntu to Share Folders with Windows 11