The following guide shows a step-by-step process of creating a scalable web application and it’s deployment to Microsoft Azure. It assumes you have no prior experience using Microsoft Azure.
The voting app we’ll create will allow users to vote between two options. It’ll be comprised of two web applications (vote and result) and a worker:
Before we start, you’ll need a couple of things:
With this tutorial, you can get away without running any of the applications locally, but it is highly recommended that you download the tools such that you can debug them applications locally if necessary.
A Storage Account is one of the fundamental building blocks of Azure. In designing applicatiosn for scale, it is important to decouple applications such that they can scale independently. As such, we’ll be using two aspects of Azure Storage:
As users vote through the web application, each vote will be pushed to a queue whereupon it will later be processed by a worker and finally persisted into table storage.
To create an Azure Storage account, head on over to the Azure portal and follow these instructions.
*Tip: A free tool that you can use to take a look at what’s inside your Azure Storage account is Azure Storage Explorer. It’s free and works on Windows, MacOS, Linux.
Once created, take note of the Azure Storage Name and Azure Storage Key, we’ll need these later.
The voter web application issues a cookie to the end-user that serves as the voter_id
. When a vote is registered, the voter_id
and vote
are pushed to the Azure Queue.
cd voting-app-voter
storage_account
and storage_account_key
with the Azure Storage Account that you had created. You can put the values here.Setup virtualenv
pip install virtualenv
virtualenv env
source env/bin/activate
pip install -r requirements.txt
Run the app
python runserver.py
AZURE_STORAGE_ACCOUNT
and AZURE_STORAGE_ACCESS_KEY
with the Azure Storage Account that you had created earlier
One feature of an Azure Web App is that you can have it run jobs at no extra cost using Web Jobs. We’ll upload a C# webjob that will run continuously to process the Azure Storage Queue.
Connection strings
The result web application retrieves the vote count from the Azure Table and displays it on the page. The instructions for deploying the result web application are very similar to the voter web application.
cd voting-app-admin
npm install
node server.js
AZURE_STORAGE_ACCOUNT
and AZURE_STORAGE_ACCESS_KEY
with the Azure Storage Account that you had created earlier