Going Serverless Azure
Tags: azure, serverless, lambda, firebase
Published: 2020-01-11 14:23:23

---
title: Going Serverless Azure
published: true
description: Focusing on Azure as a Serverless Service.
tags: Azure, serverless, lambda, firebase
canonical_url: https://jordanfinners.dev/blogs/going-serverless-azure
---


Continuing from my previous [post](https://dev.to/jordanfinners/going-serverless-2o9p).

I want to focus on a few serverless providers, this time [Azure](https://azure.microsoft.com/en-us/overview/serverless-computing/).

As a major cloud provider Azure offer all the serverless services you would expect:

*   Blob Storage for serving images and [now websites](https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website) too!
*   Functions for creating web services/API’s
*   Cosmos DB for Database As A Service
*   Azure B2C/B2B/Active Directory for Authentication

[And loads more…](https://azure.microsoft.com/en-us/overview/serverless-computing/)

* * *

I’m going to focus on a few key services that I use and really like.

Azure Cosmos DB
===============

This is [Azure’s premier database](https://docs.microsoft.com/en-us/azure/cosmos-db/introduction) as a service offering, it offers multiple different API’s to interact with it including MongoDB, Cassandra, Gremlin and SQL Core API. If you want NoSQL data but to be able to query it with SQL like API then Cosmos also offers this, and because it supports many different API’s migrating to Cosmos is really straight forward.

The JavaScript SDK for it is great, and handles lots of things that can usually be a pain including back offs and pagination. The storage is unlimited and you only pay for the throughput so it scales really well, especially using the SDK as if you get more requests than your throughput it’ll back off and handle the load.

Downside — Price
----------------

Let me skip right to the point, the only real downside I’ve found is cost, it is not cheap, but depends on your usage and having to take into account not managing anything.

* * *

Azure Storage
=============

This is the blob storage offering from Azure, and now offers serving a website straight from storage! This is great for single page applications and means you will never have scaling issues, its also super cheap to run!  
Here a link on how to set one up [https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website](https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-static-website).

**However** if you want to use a custom domain, you’ll need to also use a CDN as well. This also allows you to set custom headers on your website, which is helpful so you can set security headers on, like you can with [HelmetJS](https://helmetjs.github.io/docs/) and Express. But it does mean there is a little increase in costs, but again its small and you only pay for what you use!

* * *

Azure Functions
===============

This is the serverless API’s offering, it works very similar to Azure Web App offering. In my opinion this is the best dev experience out of all the cloud providers, its amazingly easy to get started and you can run the functions locally including all the cloud triggers as well. [Here are the dev docs](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference).

There’s also a [VSCode plugin](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions), where you can deploy functions, view existing functions and stream logs from any of your functions.

The functions also support for [many languages and runtimes](https://docs.microsoft.com/en-us/azure/azure-functions/supported-languages). Awesome for if you want to use a NodeJS version of your choosing, so you can use async/await for example.

There are [loads of integrations](https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings) across both the Azure and Microsoft ecosystems for example Office 365, Azure Cosmos DB, Twilio and SendGrid.

The cost is also great, as you would expect from a serverless offering, with 1 million invocations free per month!

I’m going to talk about logging and monitoring below as its by far and away the best experience I’ve seen from a cloud provider and is its own offering that can also be used for Web App’s etc.

Downsides
---------

The downsides are pretty standard for serverless offerings, there’s always the issue of cold start times which can vary quite a lot I’ve found. And depending on your applications nature serverless might not be the right choice for you at this time. The integration with Azure B2C is okay, as you do get the user’s ID as a header but if you want further information you have to make another request and it would be nice if this was handled for you in the auth layer.

Azure Monitor
=============

This is a series of tools that used to be separate but have recently been brought together under [Azure Monitor](https://azure.microsoft.com/en-us/services/monitor/).

This tool is amazing, simply plug either the lines of code from the [docs](https://docs.microsoft.com/en-gb/azure/azure-monitor/platform/agents-overview) or if your using one of the Azure services simply enable it and it will begin collecting pretty much all the metrics you could want! It will automatically detect where calls are made to, between servers or API’s and give you information about how many have failed, average time for a request and more, this lets you jump straight into seeing where the weak points are in your service or where a third party API is suffering.

You can collect your logs with it too, drill right down into the detailed stack traces or get a high level view by viewing the number of each log level. Using this for debugging is fantastic, once you’ve got an error you can view all the logs 5 minutes either side of the error which gives you a great picture across all your services or view the logs just for that request, it gives request a correlation id in Azure Functions for example, allowing you to really quickly debug what has happened.

You can also add Azure Monitor to you frontend applications so that you get a full overview of every part of you stack, from the [frontend](https://docs.microsoft.com/en-gb/azure/azure-monitor/app/website-monitoring) all the way through to your stack to the [servers themselves](https://docs.microsoft.com/en-gb/azure/azure-monitor/insights/vminsights-overview). Not only can you collect the built in metrics but you can also collect custom metrics and information, and build your own visuals and dashboards with it too!

You can set up alerts on any metrics or log you want including any custom metrics you want, so if anything is going wrong you can jump on it straight away!

The pricing is also fantastic, it starts from totally free (including a free uptime checker) and you can set limits on collection so you don’t go over the free limits. But after the free allowance its not that [expensive](https://azure.microsoft.com/en-gb/pricing/details/monitor/), and pays for itself in time spent debugging.

I cannot rate this highly enough, if you are running any application in Azure or not (you can totally use this with any application running anywhere) I would highly recommend checking out Azure Monitor!

Azure Authentication
====================

I’ve only used Azure B2C as an auth provider, again serverless as you don’t need to manage anything yourselves. I’ve blogged about this in detail previously, check it out [here](https://dev.to/jordanfinners/azure-b2c-and-msal-4e2n).

That’s my experience with some of Azure’s serverless offerings, its one of my favourite cloud providers and one I’ve played around with most. Let me know what your experiences are, and get in touch if you want to chat about serverless any more! 😄