Open In App

Deploying Scalable Applications with Azure

Last Updated : 08 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In modern software development, deploying a scalable application is an important task. With the increase in the number of users, the applications have to handle a large user database, for this, they require a robust infrastructure that is also scalable which will ensure seamless performance and reliability.

Primary Terminologies

  • Azure: Azure is a cloud computing platform developed by Microsoft that provides a range of tools and services to help developers build, deploy, and manage applications.
  • Docker: Docker is an open-source platform that helps a developer build, test, and deploy applications. It updates and containerizes applications which makes it easier to design an application. With the help of Docker, we can separate the application's infrastructure and the application which allows us easy distribution. Using Docker the developers are able to create a standardized component which includes the operating system libraries that help to run the applications.
  • Dockerfile: A Dockerfile is a text file instruction that is used to generate a Docker Image. It could be referred to as a recipe that specifies all the necessary instructions for building a Docker Image.
  • Docker Image: Docker Image is a pre-packaged bundle of everything that is needed to run an application. It contains the application's code, libraries, and dependencies required inside the container.
  • Container: A container is a virtual box like a shipping container containing everything needed to run a software application. It makes the process of development, testing, and deployment smoother.

Steps to Create and Deploy Scalable Applications on Azure

Step 1: Login into your Azure account

Step 2: Click on Create a resource

dsa3

Step 3: Click on Web App and fill in the details

Resource Group- (Give any name related to the web app)

Name- (Give any unique name to the web app , this will be a part of the URL)

Publish- Code

Runtime Stack- ASP.NET V4.8

Sku and size - Free F1 ( you can choose a paid plan too)

Step 4: Click on Review + Create and then click on create again

dsa4

Step 5: Click on Go to Resource and then Click on the Azure Cloud Shell logo

dsa5

Step 6: Write the Bash Code

git clone <github repository url>
git config --global user.email "<your email> "
git config --global user.name "<your name>"
cd <path to the code file>
Steps to Deploying Scalable Applications on Azure

Step 7: Git Deployment

git init
git add .
git commit -m "<commit message>"

Step 8: Configure App Service

 az webapp deployment source config-local-git --name <name of web app> --resource-group <resource group name>

Step 9: Deploy Web App

After running the above command you'll be getting a Json output in which there will be a predefined URL "scmURi:" you have to copy that URL and we will add this as a remote into our local github repository.

git remote add azure '<paste the url here> '
git push azure master

Your code will be deployed and you just have to refresh your web page.

Steps to Create and Deploy a Scalable Docker Image on Azure

Step 1: Create a DockerFile.

The image below shows a general template to create a Docker File.

DockerFile
FROM openjdk: 8
COPY . /src/java
WORKDIR /src/java
RUN ["javac", "HelloReactor. java"]
ENTRYPOINT [ "java", "HelloReactor"]

Step 2: Building a Docker Image.

docker images
docker images
docker run 447

Instead of "447" you can write the complete image id.

docker build -t my-java-app-8:v2 .
docker build

Step 3: Push the Docker Image.

docker push dockit.azurecr.io/my-java-app-8:v2
Docker image

Step 4: Deploy the Container to Azure Container Instances.

az container create --name myapp --image dockit.azurecr.io/my-java-app-8:v2 --resource-group myresourcegroup

Step 5: Scaling the Container

az container scale --name myapp --resource-group myresourcegroup --instances 3

Implementing autoscaling: Setting up Autoscaling rules and Policies

Setting up Autoscaling using VMSS (old way)

Step 1: Under the Category section click on compute.

Step 2: Click on Virtual Machine Scale Sets and Click on create.

Step 3: Fill in the Details.

  • Provide the required details and under the Instance Details , "Image" will be Windows Server 2016 Datacenter x64 Gen2.
  • Write the username and password and click on next.

Step 4: Click Next:Spot> Next:Disks> Next:Networking

  • Click on the Pen icon to edit the network interface.
  • Select inbound ports- RDP(3389)
  • Enable the public IP address
Autoscaling

Step 5: Click on Next:Scaling

  • Initial Instance: 3
  • Scaling Policy: Autoscaling
  • Minimum number of Instances: 1
  • Maximum number of Instances: 10 ( depends on the traffic of your web app)
  • Scaling Mode: Scale based on CPU metrics
  • CPU threshold: 80 (Scale Out)
  • Duration in minutes: 5
  • CPU threshold: 35 (Scale In)
  • Duration in minutes: 1
Next scaling

Step 6: Click on Next:Management> Next:Health> Next:Advanced> Next:Tags > Next:Review+Create

We have to wait for a few minutes and then our vmss will be ready.

Step 7: In order to monitor the CPU performance

  • Click on Overview > Monitoring

Setting up Scale Up and Scale Out Rules (new way)

Step 1: Login into your Azure account

Step 2: Click on the Web App we created above

Step 3: Click on Scale Up (App service plan) in the side panel

Scale out rules

Step 4: Select the Pricing tier which provide us scaling options and Click on apply

Step 5: Click on Scale Out (App service plan) in the side panel

Step 6: Choose the type of scaling you want

We have two options for autoscaling -

Manual Scale: It has a fixed count of instances. You can have a maximum of 500 instances in our Standar Plan and the value of running instances changes when this value is changed.

Manual scale

Custom Autoscaling: In this we can scale our azure resources on any schedule or metrics .

Autoscling

Designing for scalability

  • Modular Architecture: We need to break down our web application into smaller, independent segments which will help us to scale specific components which will help us in scaling easily, for example - we can create a Microservice component and services segment separate.
  • Stateless Services: Stateless services do not need to maintain information and can be replicated easily, for example- the use of Azure functions or Restful API's.
  • Database Shredding: Distribution of database across multiple servers, we can divide our database into Horizontal Partitioning and Vertical Partitioning which will divide our database into smaller and multiple independent segments in order to scale quickly.
  • Caching: Cache stores the most frequently visited data by the user, it helps in reducing the load on the system and minimize the response time.

Using Azure Autoscale for Automatic Scaling

Configure the Scaling Rules

  • CPU based Scaling: We need to scale our application based on the CPU usage.
  • Memory based Scaling: We need to scale our application based on the Memory usage.
  • Request based Scaling: We need to scale our application based on the Request usage.

Set Scaling Targets

  • Minimum and maximum instances: In order to ensure that our application can handle sudden user traffic we set maximum and minimum instances.
  • Scale up and Scale down: Scale up helps us add more resources during the peak workloads and when we are done using the resources Scale down removes it and get back to the original state.

Monitor Performance and Adjust Rules

  • Azure Monitor: It helps us to track the performance of our web application and set the scaling rules accordingly.

Leveraging Azure Load Balancer for traffic distribution

Configure Load Balance Rules

  • Round Robin routing: It distributes the traffic across multiple servers and instructs the load balancer to go back to the top of the list and repeat the process again.
  • IP Hash routing: It uses the source IP address and using mathematical operation it uplinks each packet to a non-sticky traffic to the same backend server.
  • Session persistence: It directs all the incoming request from the user to a single dedicated backend server.

Usage of Multiple Instances

  • Azure Virtual Machine: It helps us to manage and run multiple virtual machines of our application which will help in improving scalability and availability, instead of Azure Virtual Machine we can also use Azure Container Instances too.

Additional Strategies

  • Use Azure Blob Storage: The use of Blob storage will serve static data which will reduce the load on our application.
  • Use of Firewall: We should never forget to add a firewall as they will protect us from cyber attacks.

Next Article
Article Tags :

Similar Reads