How I created an Azure Serverless Application that cost me less than a dollar a month to run.

David Lee
4 min readOct 23, 2019

Recently, I had a need for a simple quiz application where I can enter questions and answers to test my knowledge as well as help as a study aid for a few upcoming exams. I needed something that will be simple to maintain and low cost to host. I knew I wanted to host it on Azure (as a personal preference). As I started looking at various open source quiz projects out there, I thought about the application being serverless, where not only would I pay only for what I consume and nothing more, I wouldn’t have to maintain it because there is no infrastructure to manage. That is where I started on a path to write one. But first off, I needed to think about the different pieces I need to make this work.

In my mind, the choices were quite simple. I knew Azure Table Storage would be the perfect choice for my storage repository. I would just need LRS because I do not require durability (and it is the cheapest option). Even better, I can use the same storage account to host a static SPA website (Single Page Application) for my front-end. For the back-end, I needed something similar — and Azure Functions came to mind immediately. For security, I needed to ensure that my SPA application would have login capability and also be able to send a valid JWT back to my back-end Azure Functions once I am logged in. My thoughts are to secure it with Azure Active Directory (AAD), so I can login with my existing AAD username and password. This is not a problem because I already have a library that does all of that.

With the different pieces in mind, I started writing two projects, one for the back-end: https://github.com/seekdavidlee/eklee-quiz-api and https://github.com/seekdavidlee/eklee-quiz-ui for the front-end piece.

Let’s talk a little more about the front-end. We have a SPA application using Angular 8 as the front-end framework. In order to secure the front-end, I added a NPM package called microsoft-adal-angular6 which will perfectly integrate into the Angular framework. The way it works is that we are securing the Angular routes with this library. What this means is that we will be redirected to login (to Microsoft) if we don’t have a valid token (initially) when our application launches. Specific with this library, we will need to configure Client Id and the Tenant Id from AAD.

For the back-end, I have a whole separate article written about it which I shall not repeat here.

The outcome of these two projects is a simple functional quiz application that cost me less than a dollar a month to run. By the way, I would also like to credit bulma for making the quiz application look so good. Check out the following quiz application in action!

Dashboard showing all quizzes you can take.
Add or edit quiz.
Questions are tagged.
Choose tagged questions or answer all questions.
Taking the test.
Your score will be displayed and you can review the questions for answers.
You will be shown which are the correct answers.

Here’s a overview of what I have been paying for the past two weeks. Most of my cost is for Storage and for Log analytics where I am monitoring my Azure Function with Azure Application Insights. So, technically, it is way less than a dollar a month but it makes for a good title for the article!

The combination of the two serverless services, Azure Storage and Azure Function does represent a pretty good cost savings when used for my particular scenario. However, I would like to call out that this is also because I do not worry about high availability (HA) where I may require CDN for my static website, disaster recovery (DR) using GRS instead of LRS, security from the perspective of having services such as Azure Application Gateway in front of my endpoints to prevent attacks like DDoS etc. I may also have a higher level of logging in Application Insights and end up paying more.

Thus, to be fair, when designing enterprise grade services where we have a certain level of SLA, it is important to note that cost can also add up too . Of course, we will have paying customers in those scenarios, where in my case, I have none. I do hope you enjoyed this article.

--

--

David Lee

Cloud Solution Architect/Software/DevOps Engineer