{{announcement.body}}
{{announcement.title}}

Blue-Green Deployment, Zero Downtime Updates, and Failover Protection With Traffic Distribution Add-On

DZone 's Guide to

Blue-Green Deployment, Zero Downtime Updates, and Failover Protection With Traffic Distribution Add-On

Learn about the solutions that allow implementing an advanced traffic routing, maximally automate this process and get several benefits.

· DevOps Zone ·
Free Resource

The absolute majority of production environments need to be accessible to customers at any time, and the most common problem here is the process of project re-deployment. Usually, it is solved with the help of additional software, but their integration is rather complicated and may require extra human resources, as well as the valuable time spent on configuring these tools. Also, multiple environment copies can be used as an insurance of high availability. In this situation you can face the problem of proper traffic distribution between such project copies, including aspects like a method for requests routing, servers loading rates, etc. Solving all of these issues can become a challenge even for experienced developers.

So in this article, we’d like to talk about the solutions that allow implementing an advanced traffic routing, maximally automate this process and get several benefits, like:

  • Apply the implicit blue-green deployment or zero-downtime update by redirecting portion or all traffic to a new version of an application
  • Perform ongoing A/B testing by routing part of the traffic to a newer application version to compare performance and UX rates
  • Achieve advanced failover protection and high availability through sharing the load between two fully functional application copies in different cloud regions 
public IP

Let’s go through the main traffic routing methods, see how to manually configure them based on the example of NGINX server and as well how to automate this process using an add-on that can be installed in one click.

Round Robin

Round Robin is the most simple and frequently used routing method. It allows us to distribute requests one-by-one among the servers with preconfigured priorities and traffic ratio.

round robin

Note that this method should be selected only when you have identical content on your endpoints since data requested by users will be loaded from both backends.

Sticky Sessions

Sticky Sessions method assigns every end user to a specific backend that receives their requests until the corresponding session is live. Herewith, on the first visit, the customer is routed based on the servers’ weights, while the assigned backend is remembered, ensuring that all subsequent requests from this user go to the same environment.

sticky sessions

Commonly, this is implemented by remembering the IP address, which is not optimal, as there could be a lot of customers behind a proxy, resulting in unfair balancing. Thus, there can be used a solution based on the session cookies to make a persistent routing, when each browser becomes a unique “user”, allowing to make balancing more even.

In such a way, Sticky Sessions' distribution of new users is similar to the round-robin method and is performed according to the pre-set priority. For example, setting 50% to 50% will make both application versions being visited by an equal amount of unique users, which is useful. But, irrespectively of the server’s weights, the “old” user’s requests will always be redirected to the hosts they are assigned to until their session is expired or cookie is removed.

Also, upon setting a 100% ratio for any server, the second one won’t be removed from the settings completely, so it will be able to process the already existing sessions.

Failover

Failover traffic routing allows redirecting the customers to a backup standby server in case of any failure on the production server. In other words, you have a primary server and backup one - all the requests are initially forwarded to the first endpoint, while the second one is used only in case the primary service goes down. The requests will be automatically redirected to the working server, so that your users, probably, won’t even notice any interruption in the application work.

failover

Automated Traffic Distribution

To automate the settings, there can be used a Traffic Distributor add-on that is available for one-click installation through Jelastic Marketplace

It provides smart traffic routing using the method and distribution ratio specified by the developer or system administrator within the user-friendly wizard.

With the help of Traffic Distributor, it’s simple to perform so-called “invisible” updates that will cause no downtime for your application due to traffic ratio slider functionality. You can do traffic switching between backends while add-on installation or later on with add-on reconfiguration. To do this click on Add-Ons > Configure.

Change Routing method (round-robin, sticky sessions or failover) and Traffic ratio based on your needs.

Such possibility is highly demanded in the current reality of the rapid development and fast-growing concurrency, as you need to constantly update your project to remain demanded, conquer new users, and, generally, not to fall behind your competitors. 

Managing Traffic Distributor via API

Jelastic allows us to automate Traffic Distributor management using the platform embedded API methods. So, let’s see how to control load balancing between your projects without GUI:

1. To work with Platform via API, you need to get a platform access token. Then such an API call can be performed as a POST request to install traffic distributor add-on, for example, you can do this with the curl command.

2. Now, you can create the Traffic Distributor using the install method:

https://[hoster-api-host]/1.0/marketplace/jps/rest/install?jps=traffic-distributor&session={session}&envName={env_name}&displayName={env_display_name}&settings={addon_settings}

where:

{session} - user’s session or access token 

{env_name} - name of the target environment

{env_display_name} - the visible name of the environment in the Dashboard

{addon_settings} - list of add-on specific settings in JSON format (key/value pairs)

Available Settings:

  • extip [boolean / number] - enables the public IP(s) for the Traffic Distributor
  • balancerCount [number] - amount of the balancers inside the Traffic Distributor
  • routingMethod [string]- defines the necessary method of the traffic's routing. Possible values: 
    • round-robin
    • sticky-sessions
    • failover
  • backend1 [string] - host of the first backend
  • backend2 [string] - host of the second backend
  • range [number] -  percent of the traffic routed to the first environment

API request example:

curl -X POST 'https://app.demo.jelastic.com/1.0/marketplace/jps/rest/install' -d session=a4b66e7376064865a0c512c5fd21b7a3b32ca3d8 -d jps=traffic-distributor -d envName=traffic-distributor -d displayName=TrafficDistributor --data-urlencode settings='{ "extip": true, "balancerCount": 1, "routingMethod": "round-robin", "backend1": "applicationap1", "backend2": "applicationap2", "range": 60 }'

3. Traffic distributor reconfiguration can be done with API executeappaction method:

https://[hoster-api-host]/1.0/marketplace/jps/rest/executeappaction?session={session}&appUniqueName={app_unique_name}&action=configure&params={your_addon_settings}

where:

  • {session} - user’s session or authentication token 
  • {app_unique_name} - unique name of the installed add-on. Could be found as the value of the uniqueName key in the response of GetEnvInfo method.
  • {your_addon_settings} - list of add-on specific settings in JSON format (described above).

API request example:

curl -X POST 'https://app.demo.jelastic.com/1.0/marketplace/jps/rest/executeappaction' -d session=a4b66e7376064865a0c512c5fd21b7a3b32ca3d8 -d appUniqueName=f5698359-f4ff-42fd-8955-1f9a750abcd9 -d action=configure --data-urlencode params='{ "extip": true, "balancerCount": 1, "routingMethod": "round-robin", "backend1": "application1", "backend2": "application2", "range":0 }

With Jelastic Traffic Distribution add-on you can easily get advanced traffic routing with maximum automation in order to smoothly perform blue-green deployment, zero-downtime updates or ongoing A/B testing, as well as achieve advanced failover protection and high availability.

Topics:
devops, failover, load balance, load balancing, load balancing algorithms, sticky sessions, traffic management, tutorial, uptime, zero downtime deployments

Published at DZone with permission of Tetiana Fydorenchyk , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}