Skip to main content

Why Switch?

GB and Smith has an internal REST API app that is currently running on AWS EC2. We discovered AWS Lambda and saw an opportunity to reduce costs linked to this application by moving it from EC2 to Lambda.

What is AWS Lambda?

AWS Lambda is a cloud solution that allows users to deploy functions without the hassle of dealing with the infrastructure. For instance, once a function has been deployed, it can be called through an endpoint or triggered by a scheduler. This comes at almost no cost and saves time on server management.

How to Switch?

Changing from a hosted environment to a serverless one is a pretty big move, so we decided to think about the language used for this application at the same time. Currently it is a Java application. Choosing the best language for Lambda is not easy, but Javascript / NodeJS seems like a good pick.

This led to the following question:

What is the best solution — in terms of maintainability, time consumption, and development time — for deploying a NodeJS application on a serverless service, such as AWS Lambda?

We then looked for existing serverless deployment solutions and discovered that multiple solutions are already available. After evaluating our options, we focused on the three solutions described below.

What Solutions?

Serverless Framework is an open source solution that aims to make serverless deployments easier and platform-independent (agnostic approach). It makes it possible to deploy a given function on AWS Lambda, Azure, Google Cloud, etc. It also support several languages (e.g., Java, NodeJS, Go, Python, PHP, Swift, .NET).

We tested this solution by developing a NodeJS function and using the native power of Serverless Framework to deploy it.

ClaudiaJS is not a framework but rather an open source deployment tool that aims to make Node.js deployments to AWS Lambda easier. Unlike Serverless Framework, ClaudiaJS is specific to Node.js and AWS Lambda. As a result, it cannot be used to deploy a Node.js function to any other serverless solution.

We tested this solution by using Express Framework, which is a Node.js Web Framework.

The last solution we tested was a combination of Serverless Framework and ExpressJS to deploy a Node.js package developed using Express (similar to deployments using ClaudiaJS). This solution is an alternative to ClaudiaJS for deploying existing express apps, and helps measure performance differences on serverless deployments on the basis of how the project is developed.

How to Benchmark?

We developed a simple application that aims only to query an external API to return the output as JSON, acting like a REST endpoint. Therefore, when accessing the Lambda function endpoint using a web browser, the web page displays the JSON output only. It’s as simple as it sounds.

The external API mentioned above is homemade. We developed a simple app that returns a JSON array. We then deployed this API on an Amazon EC2 instance in order to avoid network issues/poor performance. In other words, a Node.js server was running on a dedicated EC2 instance.

Two different test cases are possible, so we performed each test twice. Lambda functions were first configured with 128 MB RAM, and then with 1024 MB RAM.

Load Test

The load test aims to figure out how the three deployments react to being spammed with a large number of queries in a short time frame. We sent 60k queries within a minute and monitored the reaction of each solution.

Usage Test

The usage test aims to find out how the three deployments react to receiving recurring queries within two hours to simulate actual usage. It also identifies ‘cold start’ issues that can arise with AWS Lambda.We sent a single query every two minutes for two hours and monitored the reaction of each solution.

Best Solution

Serverless is probably the “best” solution, but not because it performs better during benchmarking tests. We chose Serverless Framework because it is a “native” solution, and not a mere wrapper. This makes it possible to develop serverless projects from the ground up, rather than forcing developers to adapt existing solutions to a serverless design.

In addition, the Serverless app does not include ExpressJS and therefore performs better. Finally, developing a serverless project with Serverless Framework results in a single endpoint per lambda function, which eases project management and maintenance..

Serverless Framework allows Infrastructure as Code by defining several functions in a single serverless.yml file. Each function constitutes a single AWS Lambda function, which enables developers to split their projects. In contrast, deploying an app using ExpressJS deploys only a single Lambda function, and routing for each endpoint is then managed by ExpressJS Framework.

Julien Bras

Author Julien Bras

More posts by Julien Bras

Leave a Reply