How we saved 85% of costs by moving AWS Lambda from Node.js to Golang

Alperen Keşkekoğlu
Insider Engineering
5 min readJun 19, 2023

Serverless computing has become an increasingly popular approach for building scalable and cost-effective applications. Amazon Web Services (AWS) Lambda is a serverless computing service that allows you to run code without provisioning or managing servers. When it comes to building serverless applications, choosing the right language can have a significant impact on performance, scalability, and cost. Two popular choices for serverless computing are Node.js and Golang (also known as Go). In this article, we’ll compare the performance, cost, and ease of use of Node.js and Golang on AWS Lambda.

AWS Lambda Overview

AWS Lambda is a compute service that lets you run your code in response to events and automatically manages the underlying compute resources for you. You can write your Lambda function code in several programming languages, including Node.js, Golang, Python, Java, and others. AWS Lambda supports a wide range of event sources such as Amazon S3, Amazon Kinesis, and Amazon DynamoDB, and can integrate with other AWS services to build serverless architectures.

When you create a Lambda function, you specify the code that will be executed, along with the runtime environment that will be used to execute the code. AWS Lambda automatically scales your application in response to the incoming traffic, and you pay only for the compute time that you consume. This makes it a cost-effective solution for building event-driven applications and microservices.

AWS Lambda supports multiple compute runtimes, including Node.js, Golang, Python, Java, and .NET Core. The Lambda execution environment is a container-based environment that provides isolation and security for your code. The environment provides a runtime, operating system, and pre-installed libraries and dependencies.

Performance Comparison

One of the main reasons why many developers are switching from Node.js to Golang for serverless computing is because of the significant performance improvements that Golang offers. Golang is a compiled language, which means that the code is translated into machine code before it’s executed. This results in faster execution times and lower memory usage compared to interpreted languages like Node.js.

Node.js Average
Golang Average

To compare the performance of Node.js and Golang on AWS Lambda, we ran a series of tests using different workloads and measured the execution time and memory usage of each function. The results showed that Golang functions had significantly lower execution times and memory usage compared to Node.js functions.

For example, we ran a workload that involved parsing a large JSON file and returning the result. The Golang function completed the task in less than half the time of the Node.js function and used less than half the memory. Similarly, we ran a workload that involved performing several CPU-intensive computations, and the Golang function completed the task in less than a third of the time of the Node.js function.

Here’s a graph that shows the performance comparison of Node.js and Golang on AWS Lambda:

Node.js Performance
Golang Performance

The graph shows that Golang functions have significantly lower execution times and memory usage compared to Node.js functions, across various workloads.

Cost Comparison

In addition to the performance benefits, switching from Node.js to Golang can also provide significant cost savings on AWS Lambda. This is because AWS Lambda pricing is based on the number of requests and the duration of the function execution.

Since Golang functions have significantly lower execution times compared to Node.js functions, this translates to lower compute costs on AWS Lambda. For example, if you have a function that is invoked 1 million times per month and has an execution time of 1 second, switching from Node.js to Golang can result in an 85% cost savings per month.

Node.js Cost
Golang Cost

Ease of Use

When it comes to ease of use, Node.js has an advantage over Golang due to its simplicity and ease of development. Node.js has a large and active community, and there are many resources available for learning and troubleshooting. Additionally, Node.js has a vast ecosystem of libraries and frameworks that make it easy to develop complex applications quickly.

On the other hand, Golang has a steeper learning curve and requires more effort to set up and deploy. However, once you get familiar with the language, Golang can provide significant benefits in terms of performance and scalability.

Conclusion

In conclusion, if you are experiencing performance issues with your Node.js Lambda functions, or if you simply want to optimize your serverless application, we highly recommend considering a switch to Go. Not only did we experience significant cost savings, but we also noticed a significant improvement in our application’s performance and responsiveness. We hope that this article has provided you with valuable insights into the benefits of using Go for AWS Lambda functions.

If you are about to make a decision about your career, please take a look at How we saved 90% of costs by moving from AWS Lambda to AWS Fargate post by Emre Kaya, Software Engineer at Insider.

Also, don’t forget to follow Insider Engineering Blog to see more articles ✍️

You can reach me on LinkedIn 📥

--

--