DEV Community

Cover image for Azure Functions vs Firebase Functions
Osinachi Chukwujama
Osinachi Chukwujama

Posted on

Azure Functions vs Firebase Functions

This article is part of #ServerlessSeptember. 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/

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



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);
  });
}


Enter fullscreen mode Exit fullscreen mode

Serverless function on Google Cloud

Here's the function that will execute on gcloud.



{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);
  })
};


Enter fullscreen mode Exit fullscreen mode

Ensure you set your entry point as longRunningFunction

Serverless function on Azure

Below is the function that will execute on Azure



{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,
  };
};


Enter fullscreen mode Exit fullscreen mode

Results

Running these functions and testing their results on this repl gives this result



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


Enter fullscreen mode Exit fullscreen mode

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

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

Google cloud functions edit interface

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. โœŒ๐Ÿฝ๐Ÿงก

Top comments (0)