Which web server starts up the fastest? Java, Python, C#, NodeJS, or Go?
An experiment measures how long 5 programming languages take to start up a web server.
When your website is too slow, users leave. Maybe the home page takes too long to load. Maybe the effects of a button click take too long to see. Either way, a three second delay may trigger users to abandon your website find another, and your website makes less money.
Cold starts are one source of delay for web applications. A cold start for a web server refers to the process of initializing and launching the server from a state where it has not been running or is starting up from scratch. This typically involves tasks such as compiling source code or virtual machine code, establishing connections to databases or other services, and preparing to handle incoming requests from clients. During a cold start, the server may experience delays as it initializes, configures, and prepares itself to handle incoming traffic, which can impact response times for the first few requests.
Cold starts are uncommon when web applications run on persistent (virtual) machines like in Google Compute Engine, AWS EC2, or Azure Virtual Machines. With these platforms, cold starts happen only when a new version of the web application is deployed, or a machine is replaced or added to the pool of web servers. Otherwise, the web application may run for weeks without a restart, so very few users will experience a delay due to a cold start.
Cold start performance has grown more important with the adoption of serverless platforms like Google Cloud Run, AWS AppRunner, and Azure Container Apps. These platforms create and teardown instances of your web application in response to fluctuations in web traffic. The benefit is that you don’t pay for excess virtual machines when your website’s traffic is low. The drawback is many more users will experience delays due to cold starts, because the platforms frequently launch new instances of your web application when traffic increases.
Therefore, understanding how a programming language impacts your web application’s cold start time is more important than ever. It should never be the sole reason for choosing a programming language, but it’s essential data for making an informed decision.
We ran an experiment to measure cold start times of five different programming languages when run inside Docker containers on Google Cloud Run. All the source code is available here.
Here are the measured response times for fetching a simple “Hello world” page from web servers built with the 5 languages. All times are in milliseconds.
Go is the clear winner. Go’s response time at the 90th percentile is faster than all the other language’s 25th percentile. In this experiment, Go is more than 10 times faster than Java.
Surprisingly, the size of the docker image doesn’t seem to correlate with the cold start time. The two fastest languages, Go and NodeJS, have the smallest and largest docker images.
However, a “Hello world” application is of limited predictive value, because real web applications are much more complicated.
For the second experiment, we built more realistic web pages. The new web page runs a database query, and renders the result in the response. In this case, we used Firestore for the database. Running the database query entails loading the libraries to talk to the database, opening a connection to the database, authenticating, relaying the query, parsing the result, and rendering the result. This is much more similar to a real web application. Here are the results:
Compared to the “Hello world” example, response times grew slower by about 50%, except for Go. Python and C# swapped positions, but otherwise the rankings stayed the same.
All the raw data is recorded in this sheet.
It’s worth repeating: performance in general and cold start times in particular should never be the sole reason to choose a programming language when building a web application. However, ignoring performance also comes with the risk of slow websites that turn users away.
I hope this post helps you make an informed decision when picking a programming language for you next web application.
Special thanks to Taiga Narusawa who wrote the code and collected the data for this experiment.