All of us who are responsible for developing high scalable, high available applications are very well aware of the infrastructure challenges. To achieve scalability and availability of the applications, we require high capability servers, high bandwidth network and dedicated infrastructure. This type of infrastructure adds significant cost overhead for all critical SLA based applications.
Today, we have a simple answer to these challenges - move such applications and their infrastructure to the Cloud!
Now the question is, before the Cloud, what was the situation? The answer is to have an On-Premises Server Infrastructure. This type of infrastructure is generally used by most of the big players in the industry to store, maintain and manage their data. Having this kind of infrastructure helps an organization in the following ways:
Since the data is locally available in their premises, they need not worry about ‘tenancy’ of data. The data is in self owned data centers.
At any point of time, companies can add new hardware, change software as per their business requirements.
However, there are some practical limitations and challenges in this infrastructure:
Such high performance infrastructure requires a dedicated maintenance and support team. This increases financial cost.
Since companies need to manage servers, the power consumption by the infrastructure increases cost of maintenance.
Any hardware failure can create problems of application availability and sometimes it is a challenge to rectify these failures.
To make data of the application available across various locations of the world, a company needs to implement data replication across various locations, which is non-trivial.
The above challenges can be broadly categorized into two buckets:
Introducing Windows Azure
Windows Azure is a cloud-based platform from Microsoft that aims to take the infrastructure challenges away from companies and provide a cost-effective way for hosting and maintaining demanding applications.
We as developers, must think about common applications that require scalability, high availability etc and some examples are listed below:
- Web Sites
SLA (Service Level Assurance) based service applications like source control (GitHub, Bitbucket), Media streaming (Netflix), CRM (Sales Force)
Online shopping based sites (like Amazon, Flipkart etc)
- Application that require clusters of high performance computers for adhoc CPU intensive computation.
- Global accessible WEB APIs.
- High traffic Social Sites.
What is the Windows AZURE platform?
Windows Azure is an operating system for the cloud. It provides a complete abstraction layer over the physical components of the system. It is responsible for managing the application hosted by the customer (or a developer). It provides scalability and fault-tolerance for the application developed by the customer. It provides load balancer and data replication so that the data will be always available.
Windows Azure provides complete virtual environment with abstracts set of servers. This provides a common platform for building application and services. Although as a developer you work with these servers, but you are not responsible for installing any software on it and although you deploy your application on it, you do not know where does your software get installed.
Windows Azure provides the below advantages to the developer:
No hardware configuration or installation by the developer.
No network or firewall configuration.
Not required to apply updates, patches or bother about hardware or software issues.
Azure is a Subscription based Cloud Platform!
Note: As a developer, you have to purchase a subscription for deploying an application to the cloud. Please visit www.azure.com for further details about the subscription, costing etc.
Services offered by Azure
The Azure Cloud offers the following core services:
Let’s quickly study these services one by one
This provides the number of instances required to manage the application. Here instances mean the virtual machines required for scaling the application.
In the Azure SDK tools, Windows Azure Compute emulator provides simulation of your application before deployment of the application on the Cloud.
The number of instances requirement for the application is specified in the configuration file of your cloud project.
It provides Web Role, Worker Role.
It is a general purpose host for executing the code.
Provides Run() method for executing the hosting code.
It is more similar to Windows Service and hence used for background Operations.
It provides all features of the Worker role. Typically it is designed for making Web Sites or services accessible over Http.
It also provides features of IIS 7.x.
One Web Role can contain multiple Web Sites or services in it.
This simple diagram given below explains the possible input required for compute:
The diagram above contains the following components:
The Service definition (.csdef) file defines the number instances required for the application, the default value is 1. You can change the value as per your requirements.
Note: More the instances, more the bill you need to pay.
The Service configuration file contains the service account name under which the application will be deployed. Here you get two service configuration files as shown below:
ServiceConfiguration.Cloud.cscfg - used to define the cloud storage account name and its key using which the cloud storage can be accessed.
ServiceConfiguration.Local.cscfg - contains Local storage by default which you get using Windows Azure SDK.
The Source code is the .NET language business logic which you write in the application.
The application deployment package to upload to the Windows Azure portal, where Compute service allocates the necessary instances and provides an access of the storage.
It provides a facility to maintain data published by the user in the storage.
The storage provides easy to use REST APIs and Storage client library for accessing storage in the client application.
The StorageClient library is a managed .NET abstraction over REST APIs because they are easy to use.
User can create a globally unique name. Storage account names are specific data centers provided by AZURE.
Following are the types of storage provides:
Blobs - This is typically a file system in the cloud. It is used to store Images, documents, audio and video files etc.
Tables - These are not database tables, instead they are highly scalable structured storage. These help to store entity data.
Queue - Conceptually similar to MSMQ and is used to provide Reliable storage and delivery of the messages.
Drives - This is a Durable NTFS volume for Windows Azure applications. Typically Blobs makes use of this.
This is a SQL Server Database over cloud.
This is more similar to SQL Server Management studio. It provides a facility to create database, tables.
SQL Server database technology is delivered as a service on the Windows Azure platform.
It is more ideal for simple and complex database operation applications e.g. Simple ADO.NET Code, ADO.NET Entity Framework etc.
Azure provides SQL Azure management portal where you can create a SQL Server Database.
Building a Simple Azure based Application
Visual Studio 2010 provides a template to create a Cloud project with Simple Web Role. Let us see the steps involved.
Step 1: Open VS2010 and create a new cloud project as shown below:
This action opens up the ‘New Windows Azure Project’ window
Step 2: Select ASP.NET Web Role and click on the right arrow in the window, as shown below:
Click on ‘OK’. An ASP.NET project with a Web Role project will be created as shown below:
Step 3: Click on the ‘ServiceDefination.cscfg’. You will see the following XML:
<?xml version="1.0" encoding="utf-8"?>
<WebRole name="WebRole1" vmsize="Small">
<Binding name="Endpoint1" endpointName="Endpoint1" />
<InputEndpoint name="Endpoint1" protocol="http" port="80" />
<Import moduleName="Diagnostics" />
The above xml shows that the ‘small’ virtual machine will be used to execute the application. It also specifies the protocol and the port used for the communication. You can change these values as per the requirements of the application.
Step 4: Open ServiceConfiguration.Local.cscfg file. The following XML will be displayed:
<?xml version="1.0" encoding="utf-8"?>
<Instances count="1" />
The above xml file shows that the instance used will be 1 and it uses the local development storage for storing Blob, Table etc. using the setting UseDevelopmentStorage=true. During the actual production deployment of the application over cloud, you will need to make use of ServiceConfiguration.Cloud.cscfg where you need to specific the Storage Account Name and the access key provided to the access of the Storage.
Step 5: Run the application using F5 and you will find the Windows Azure Compute Emulator will start as shown below:
Right click on it and select ‘Show Compute Emulator UI’. The Emulator will show the instances running as shown below:
Here since the Instance in .cscfg is 1, that’s why the Web Role ‘0’ is shown. Also right click on it and select ‘Show Storage Emulator UI’, the Emulator will show the Storage running as shown below
The Emulator UI helps you to diagnose the application and check whether the storage is accessible are not. Check if everything’s fine and deploy the application on cloud.
Conclusion: Windows Azure provides a comprehensive platform for developing Scalable, High available application. With the Visual Studio 2010 templates, any .NET developer can easily develop applications for the cloud.
This article has been editorially reviewed by Suprotim Agarwal.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this Book aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on the latest .NET Core 3.0, .NET Standard and C# 8.0 (final release) too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.
Click here to Explore the Table of Contents or Download Sample Chapters!