Azure Functions vs Firebase Functions
Tags: serverless, azure
Published: 2020-09-27 16:32:39

This article is part of [#ServerlessSeptember](https://aka.ms/ServerlessSeptember2020). You'll find other helpful articles, detailed tutorials, and videos in this all-things-Serverless content collection. New articles from community members and cloud advocates are published every week from Monday to Thursday through September. 
 
Find out more about how Microsoft Azure enables your Serverless functions at [https://docs.microsoft.com/azure/azure-functions/](https://docs.microsoft.com/azure/azure-functions/?WT.mc_id=servsept20-devto-cxaall)

## Introduction
Serverless functions are microservices which run on preconfigured servers that scale according to demand. Serverless functions are used to perform tasks such as running chatbots and database sanitization.

Azure and Firebase both offer serverless functions as part of their cloud offering. Firebase functions can be seen as part of Google Cloud Platform (GCP). I tested the code on this article directly on GCP. You should obtain the same results if you go through Firebase. We would compare the speed, ease of development and ease of deployment of serverless functions than run on Azure and Google Cloud.

## Computation Speed
When comparing the execution speed, we must note that one machine running the function may be closer to us than the other. We must also note that different machines are used to execute the function. Therefore, we would run the function several times, then calculate the percentage range of their results.

We would use this long-running task function in both scripts

```js
function longRunningTask() {
  return new Promise((resolve, reject) => {
    const start = new Date();

    let a = 0;
    for (let i = 0; i < 90000000; i++) {
      a += i;
    }

    const end = new Date() - start;
    resolve(end / 1000);
  });
}
```
### Serverless function on Google Cloud
Here's the function that will execute on gcloud.

```js
{Add longRunningTask function here}

exports.longRunningFunction = async (req, res) => {

  return new Promise((resolve) => {
    const loopCount = req.query.loopCount || 10
    const runTimes = [];

    for (let i = 0; i < loopCount; i++) {
      longRunningTask()
        .then((data) => {
          runTimes.push(data);
        })
        .catch((error) => {
          console.error(error);
        });
    }

    resolve(runTimes)
  }).then((data) => {
    res.status(200).send(data);
  })
};
```

Ensure you set your entry point as `longRunningFunction`

### Serverless function on Azure
Below is the function that will execute on Azure

```js
{Add longRunningTask function here}

module.exports = async function (context, req) {
  const runTimes = [];

  for (let i = 0; i < 10; i++) {
    longRunningTask()
      .then((data) => {
        runTimes.push(data);
      })
      .catch((error) => {
        console.error(error);
      });
  }

  context.res = {
    body: runTimes,
  };
};
```

### Results

Running these functions and testing their results on [this repl](https://repl.it/@Vicradon/relative-range#index.js) gives this result

```
Azure
Min: 0.278
Max: 0.672
Percentage Range: 108%
GCloud
Min: 0.619
Max: 0.705
Percentage Range: 12%
```

From the result, we can conclude that azure runs the function faster than google cloud.

Status
Azure: 1
GCloud: 0

## Ease of development
In this section, we compare how easy it is to write, test and debug functions on the two platforms. Azure offers an intuitive interface for editing and testing functions.

![Azure function development interace](https://dev-to-uploads.s3.amazonaws.com/i/w0unsgnvqtvpzq5of6vz.png)


GCloud's interface doesn't allow for immediate testing. You must redeploy a function after edits are made.

![Google cloud functions edit interface](https://dev-to-uploads.s3.amazonaws.com/i/x4xwpgq3wzmpnorg8b6n.png)

Status:
Azure: 2,
GCloud: 0

## Ease of deployment
Deploying functions on these platforms depends on your deployment pipeline. If we solely compare deployment using the dashboard, we can conclude that they are both intuitive. So we have a tie.

Status:
Azure: 3,
GCloud: 1

## Conclusion
In this article, we made an attempt to compare the speed, development and deployment of serverless functions on Google Cloud and Azure. Using the metrics above, we can conclude that working with serverless functions on Azure gives you a better experience than Google Cloud. This isn't the absolute conclusion. We didn't consider a whole lot of metrics. But this can be a start. Thank you for reading. ✌🏽🧡