Cloud – another buzz word we hear almost every day. For the moment the providers that offer this service are: Amazon, Microsoft (Windows Azure), Google, Rackspace.
What comes to mind when we think about cloud? One, two or more instances that we keep on the cloud and when we need more resources we can grow the number of instances easily. In other words: Cloud Scability.
A cloud provider like Microsoft offers us some scalability points at the moment. In this article we will find out how to create a scalable cloud application and how to use the services that Windows Azure provides us with.
Content Delivery Network
Let’s say we have a web application that has a lot of static content. When we say static content we think about images, CSS, HTML that doesn’t change every second (at every request). Normally when we observe that the loading times on our machines are quite high we will try to increase the instance number. This seems to be a good idea for our problem, but in terms of costs it might not be the best one.
Even though we try to create some cache for the server content (through IIS or other methods) all the requests will still reach our machines. That’s why they will have to respond to every request and that is why they eat up our available resources.
A solution for this case may be to use the Content Delivery Network (CDN). This service allows us to cache the static content on different CDNs depending on the physical location of the client. All the requests for this kind of content will be solved by the CDNs. A CDN can normally only handle static content, but newer versions of CDN can also handle dynamic content. This service is also provided by Windows Azure and it can be easily integrated into our applications.
By using this kind of content delivery mechanism the machines that host our application will not be hit at every resource request. The load level will decrease automatically.
The next place in our application where we can easily introduce a scalability point is the cache. We can use a cache mechanism in order to avoid making numerous requests to external services or to recalculate different parameters.
Windows Azure provides this service in different ways. The advantage of using a service to cache data appears when we need to scale the cache mechanism and we don’t have to buy a machine, licenses or synchronise nodes.
Currently when we create a machine with Windows Azure we can specify how much RAM will be allocated to the cache. Another caching system is to dedicated machines and allocating the entire RAM for caching. Data synchronisation between two or more cache instances is natively supported in both cases. These settings are made before deploying the solution.
The third option available is to use a dedicated cache service. In this case, we don’t have to manage our instances; these resources are entirely seen as a service.
Using this type of caching mechanism gets rid of problems that can occur in traditional caching mechanisms. Problems like synchronisation or adding a new cache node disappear.
Until now we managed to analyse two classic problems that appear on every web application. But what can we do if we need a video stream? As we all know it is extremely costly not only in terms of resources consumed on the server side but also as far as bandwidth is concerned.
Normally we have machines that handle video streaming. The moments when we have a lot of active users can cause some pretty big problems. Windows Azure helps us with a dedicated service for these situations. Windows Media Services handles video streaming completely starting with the encoding and ending with encryption and content delivery (offline and online).
This service frees our instances which would have had to handle the delivery and processing part. Scalability is ensured from the start because it is a dedicated service.
Until now we’ve seen three methods we can use to scale different cloud services without the need of an increasing the number instances. Depending on the application we can expose different web services that collect information from clients.
What can we do if there are times when a large number of clients want to connect to us? Usually we would try to allocate a bigger number of instances to handle this situation.
One solution that Windows Azure offers is Service Bus Relay. Through this service we can expose any “fire and forget” web service. All requests will be stored in the form of messages and our service will be able to process them at any time. Even though the number of requests increases greatly, the service will always be available.
Windows Azure Service Bus Relay can be easily integrated into our application. The only change you need to carry out on your application that uses WCF is to alter the configuration file.
Communication Between Instances
A complex application usually has different types of machines which run the application’s different components. It will be necessary to ensure a persistent and independent way of communication between these instances.
We can try to implement a communication system through a database or through another instance which will only have to handle this issue. When we will have to scale it will be necessary to think about a way of resolving issues like synchronisation between instances.
Windows Azure helps us by providing different ways of sending messages. All these services are accessed using a URL which can be accessed from anywhere on the Internet.
Windows Azure Queues is the most basic service but it is also the cheapest one. This queue allows us to distribute messages in a very simple, quick and cheap way. If we have to distribute messages to more consumers, with support for death-letters or to guarantee the message order we would have to work with Windows Azure Bus Queues and/or Windows Azure Service Bus Topics.
A client-server application could mean a permanent exchange of data. This translates into exposure of various web services through which our clients can execute queries on a database. In these cases our application will have to contain instances that expose this service and a database (relational or non-relational). Besides keeping these instances we will also have to deal with web service maintenance.
We imagine our system from another point of view in these cases. We can stock and expose dates through the Windows Azure Table Storage Service. These non-relational tables allow us to stock hundreds of GB of content without any problems.
When we want to use such a solution we may end up with two questions: what information can each client access? What information can they audit? Using some tokens which we can generate for each client we can define what content the customer has access to, what kind of operations they can perform and how long a token is valid for. This functionality is called Shared Access Signature and it allows us to eliminate the instances that should offer data to the customers from the instance. These tables should not show how we internally store our data, they should show the data that we want to offers our customers.
Windows Azure Storage Service natively supports the audit, all we have to do is to activate it and specify what kind of operation we want to audit.
If we use such a solution we will also need a component that handles token generation and management. We don’t need other components.
We analysed different ways in which we can make our application scalable. From different cache systems or systems for sending messages, all the way up to services that allow video streaming without raising any allocation or security problems.
The most important thing we have to do when we think about a cloud application is to try to identify all the points where we need scaling and to look for services that can offer it. If we need features that are not already on the cloud we find it is better to separate them into different instances or at least different processes. If we will need to scale it will be easier for us to increase the number of instances that deal with a specific function.
A cloud solution today means more than several machines running our application with a load balancer – horizontal scalability. Cloud means a multitude of services that come to our aid to create more complex applications and to scale where it is necessary.
How do you use the cloud?