The application itself is a website that allows students to resell books that they no longer use. At the moment, users can submit books and view books. Additional functionality will be added in the future.
Although submitting items and viewing them are pretty straightforward features to implement, we can get creative and utilize the power of the cloud to break the what-cloud-have-been-a-monolith-app into components that can be scaled and configured independently.
For example, the image processing that is required by the app is performed by a separate process (WebJob) which processes images asynchronously. Before we can go into the details, let's take a high-level view of the cloud infrastructure used by the app.
The Web App Cloud Infrastructure
As depicted above, the App utilizes the following Azure services and features: Azure Web Apps, Azure WebJobs, Azure Storage (Table, Queue, and Blob). Let's take a look at how each is used by the app.
Azure Web Apps
This one is straightforward - Web Apps is a platform optimized for hosting websites and web applications and we use it to host our app.
The reference app allows users to upload images of their books but those images must be processed before they are displayed. Imagine that someone uploads a 10 MB image - it is usually a good idea to reduce the size as much as possible. In addition to that, maybe you want to generate thumbnails which are a lot smaller than the original image.
You can do all this processing on your web server but if you start getting a lot of traffic it is usually better to offload all expensive processing to a separate process that deals with image resizing exclusively. The reference app does just that - it offloads the image processing to a separate process using Azure WebJobs.
Azure Blob Storage
Blog storage is a service that stores unstructured data in the cloud as objects/blobs. The app uses this type of storage to store all users images. Yes, you can always store the images locally on the web server but you can easily run out of space. By using Blob Storage you can be sure that you will not run out of space. Additionally, storing images in Blob Storage is many times cheaper that storing them on your web server or in an SQL database (who does that?).
Azure Table Storage
All business applications have some sort of domain entities that have to be stored. In our case, there is this BookListing class that represents books submitted on the site. There are various options for storing structured data. While very powerful, SQL servers are quite expensive and in many cases using SQL might be an overkill. That sure is true for the reference app.
Table storage is a service that stores structured NoSQL data and is perfect for our scenario. It is many times cheaper than using a SQL Server and at the same time it is super fast.
Azure Queue Storage
App components need a way to communicate in order to do something useful and Queue Storage is one such way. Queue storage allows one component to publish messages that can be read by another component. But how is that useful? The reference app has two main components - the web app and the image resize process. Whenever a new book is submitted (along with its image), the web app will submit a message to one queue. The message signals that there is a new image that needs to be processed. The image resize process (WebJob) listens for messages on that queue and processes them one by one.
All this sounds very good but it might be a little fuzzy until you have the chance to examine the code and experiment. So where is the code?
Running The Azure Reference Web App
The code of the app is available on Github but before you can run the app you need to create the required Azure infrastructure. Fortunately there is a PowerShell script that will create everything for you. Once you clone the Git repository, navigate to the "azure" folder and execute create-azure-resources.ps1. You will have to enter your Azure subscription id where the resources will be deployed.
Once the infrastructure is in place, you can deploy the app to Azure using Visual Studio or any of the other methods available.