In December of last year, we released a new version of our risk questionnaire. This allows clients to input some information, answer 10 questions, and get a portfolio which matches their risk tolerance - all from their computer or smart phone. See this blog post for more information and a short video if you're interested in why it exists.
All of the infrastructure for this relatively simple web app lives in "the cloud". Having someone else take care of the servers, operating systems, etc is great from a management perspective but obviously outsourcing that stuff usually comes with a cost. In light of this, I thought it might be interesting to show how we host this app for free (basically).
It's honestly pretty simple. I can separate it into two parts:
- Cloudflare sits in front of Azure Blob Storage, which hosts static files and assets (HTML, JS, CSS, and images).
- An Azure Function, which notifies SEM when someone completes the questionnaire.
Azure Blob Storage
Our risk questionnaire is mostly a static website (which has a chunk of javascript for interactivity) and a small Azure Function (which we'll get to later). This means it's pretty easy to host the bulk of it inside of Azure Blob Storage. The documentation is quick and easy to follow, but to summarize: Deploy a storage account, enable static web hosting, and upload your website into the $web blob container. You get a public-facing URL which you can add to a CNAME record and that's it. We're using Azure here but you can probably do something pretty similar with an Amazon S3 bucket.
Calculating the cost can be sort of complicated, but especially for something as small as our risk questionnaire it's going to be pretty cheap: https://azure.microsoft.com/en-us/pricing/details/storage/blobs/
I did a rough calculation of the size of our $web container: 432KB. At $0.0184 per GB, it should cost about $0.0078 / month. That's just under eight-tenths of one cent per month to store the static files.
There are also costs involved with reading, writing, listing, and other data operations. Bandwidth is a separate charge too. These costs are already pretty small (e.g. $0.05 per month for every 10,000 write operations), but if you put a CDN in front of the blob container the costs become even more negligible.
Cloudflare
I'd be surprised if you hadn't heard of Cloudflare before reading this. One of the services that Cloudflare offers is a CDN (if you're not sure what a CDN is, check out this article). This is perfect for our risk questionnaire, which again is pretty much just static files. No matter where in the world you are, you can go to https://risk.semwealth.com and you will hit the nearest Cloudflare data center instead of the Azure data center on the East coast of the US where our storage account lives. Cloudflare's goal is to be within 10ms of everybody who uses the internet, so our questionnaire should always load pretty quickly.
As I alluded to above, another benefit is pricing. We use the free tier of Cloudflare so there is no cost here, and it will actually save us money at Azure too. Since Cloudflare serves the files most of the time, the number of read operations in the blob container is dramatically smaller - most of the read operations will come from Cloudflare updating their CDN from our blob container.
Setting up the Cloudflare's CDN is pretty straightforword as well, so I won't go into it here but you can look at this documentation if you're interested.
Azure Function
When you get to the results page of the questionnaire, a POST request is made to an Azure Function. There's some C# code in there which takes care of notifying the appropraite personnel that a new risk questionnaire was just submitted.
Azure Functions are dirt cheap too. You pay for execution time + number of executions per month. Execution time is billed at $0.000016/GB-s and number of executions is billed at $0.20 per million executions. If you're wondering what the heck a "GB-s" is, this may help.
Not only is this insanely cheap to begin with, but you get a free grant of 400,000 GB-s and 1 million executions per month. This Azure Function will probably never exceed either of those, but even if it did we wouldn't exactly be hurting for cash. I believe the equivalent of Azure Functions in Amazon-land is called AWS Lambda, and it looks similarly inexpensive
Obviously Azure Functions is a developer thing, but if you know enough C#, Python, Powershell, or other languages to get the job done then the Microsoft documentation should be able to get you up and running.
The Cost
Putting it all together:
- Cloudflare: $0/month
- Azure (Storage and Functions from last month's invoice): $0.01
I don't have to concern myself with maintaining physical servers, virtual machines, operating systems, or application frameworks (for this application, at least) and it costs us one cent per month.
When used appropriately, serverless is pretty cool.