Victor Jonah I am a Software Developer with over 3 years of experience working with JavaScript and its frameworks. I currently work as a remote Software Developer for a tech agency.

Why is Go overtaking Node.js?

4 min read 1196

The Golang and Node logos.

Both Go and Node.js were first released in 2009 to enable the development of server-side and networking applications.

Go is able to solve a lot of problems ranging from system, big data, machine learning, video editing and audio, among others. Go has the same performance as C because it actually compiles to machine code and doesn’t need a virtual machine or interpreter.

Before you dismiss this article as another tech war, I suggest you slow down a bit and read on. This is just a comparison between Go and Node.js, where I will share the pros and cons.

So, Go is a powerful tool but I’m not here to dismiss Node.js just because some people said so. Besides, it depends on what you do. Node.js and Go are insanely fast and cool, and they’re both good with multi-threaded programs (Node is single-threaded, but it does the job very well, which makes multi-threading unnecessary).

Okay, let me quit playing around. In this article, we will take a look at the strengths and weaknesses of these two powerful tools. We’ll see how they approach different situations, understand their scalabilty, and ultimately arrive at some conclusions about why Go is overtaking Node.js.

Intro

Node.js has been the most popular environment to build cross platform applications using JavaScript for a long time. It helps you build fast and scalable server-side applications. With features like event-driven and non-blocking I/O models, it’s a great environment.

Go on the other hand is an open source, statically typed, compiled, cross-platform, fast and multi-purpose language providing concurrency at its peak. It accommodates automatic memory management and dynamic interfaces for a structural type-checking. Go is similar to C in terms of syntax and speed as well.

Not to bore you with these introductory or basic details, but both of them are popular, evolving, and work best based on different projects.
We will be looking at the pros and cons so we know which one is suitable for your choice of project.

Concurrency

Go handles concurrency using coroutines, which are called Goroutines in Go. Goroutines are functions or methods that run simultaneously with other functions or methods. Communication in Go is done using channels to avoid race conditions when having to deal with a shared memory.

Goroutines is a strong side in Go in the sense that a large project that needs a couple of requests to be handled simultaneously will perform well. This is not the case for Node.js.

We made a custom demo for .
No really. Click here to check it out.

Node.js is a single-threaded tool and uses the event-callback mechanism, which means that every function or method gets executed in a linear order. A callback is a function that is executed after a function has finished executing. So, Node.js lacks that concurrency ability.

WINNER: Go.

Error handling

Unlike Node.js, which uses the exception method to handle errors, Go uses the explicit style. There are no unexpected uncaught exceptions. Basically, for every Go project, you will see the below code more often than not:

if err != nil {
    return err
}

This might sound redundant to an outsider who isn’t familiar wth Go, but it is one of Go’s main goals: to take in errors as first class citizens of each function. In other words, plans for failure, not success.

Using if err != nil returns (value, error) helps you note that failures must come or should be treated first. There’s no need to wrap around try catch, which handles every possible exception.

Another beautiful thing about linters is that they will catch you when you ignore an error.

In regards to Node.js, error handling is indistinct and not explicit. Let me show you what I mean:

try {
    operation1();
    operation2();
    operation3();
} catch (e) {
    console.error(e);
}

The above handles the error properly. However, there is no explicit or proper handling of what went wrong. The error just goes to the console, disallowing full responsibility.

Comparatively, Go uses a disciplined and methodical way of coding when dealing with errors.

WINNER: Go.

Scalability

Go beats Node.js in terms of scalabilty because of its supports for concurrency, which helps with handling side by side tasks. Go can manage 1000 concurrent requests per second. This makes Go superior in this respect.

Node.js has a weakness that makes it less scalable. It works on the single-threading mechanism, which means that tasks are performed one after the other. However, it allows concurrency with event callbacks (not effective), but this is far from parallelism.

WINNER: Go.

High pay

According to the Stackoverflow 2019 Developer Survey G developers have a higher earning potential than most other developers:

Highest paid salary by language.

$80k for a Go developer. Pretty amazing.

WINNER: Go.

Performance

When it comes to raw performance, Go developers have said that Go shows the same characteristics of C and C++ in terms of speed and performance, which is really good.

With its memory management (garbage collector), which helps clear up unused memory, it has lower security risks due to memory leaks.

Go is even suitable for building microservices due to its ability to handle heavy loads, high speed, and support for concurrency. The fact that it compiles down to a relatively small, statically linked native binary that has relatively small fixed runtime costs makes it a good fit to be installed in a Docker container.

In terms of raw performance, Node.js isn’t that great compared to Go. However, in life performance, everything works the same with Go.

WINNER: Go.

Development tools

Go has a fewer development tools than Node.js. Node.js has more libraries and packages. This alone means a lot of manual setup still has to be done by the developer using Go. Go developers also have to do thorough research.

Node.js has a large community that has provided a lot of libraries and packages for the developers. This large community also gives enough support on platforms like Stackoverflow. This factor provides the developer with higher productivity when building a product.

WINNER: Node.js

As you can see, Go wins a few of these side-by-side comparisons, but it is still hard to give the prize to Go because it is hard to say which is better. It just depends on the application you want to build.

An application that will be required to handle a thousands requests simultaneously will be better off on Go to scale.

Also, while Go is perfect for microservices and enterprise projects that will need to handle high loads, Node.js still has a ton of development tools for every challenge. These development tools reduce development time.

Conclusion

Having compared both tools, Go and Node.js each have their own pros and cons. We can confidently say both have their setbacks.

Notwithstanding Go’s performance, it seems more reliable than its counterpart. Go developers tend to get higher pay than Node.js worldwide, and error handling seems to be excellently handled by Go. We should not forget Go’s race condition detection, which is a good thing when having to deal with creating multi-threaded applications because some processes might be completed in an unexpected order.

Also, Go is a compiled language, which gives your app a lot of speed.

200’s only Monitor failed and slow network requests in production

Deploying a Node-based web app or website is the easy part. Making sure your Node instance continues to serve resources to your app is where things get tougher. If you’re interested in ensuring requests to the backend or third party services are successful, try LogRocket. https://logrocket.com/signup/

LogRocket is like a DVR for web apps, recording literally everything that happens on your site. Instead of guessing why problems happen, you can aggregate and report on problematic network requests to quickly understand the root cause.

LogRocket instruments your app to record baseline performance timings such as page load time, time to first byte, slow network requests, and also logs Redux, NgRx, and Vuex actions/state. .
Victor Jonah I am a Software Developer with over 3 years of experience working with JavaScript and its frameworks. I currently work as a remote Software Developer for a tech agency.

9 Replies to “Why is Go overtaking Node.js?”

  1. Article is very inspirational to learn Go language. Yeah i am inspired.

    But Go is a language and nodejs is a framework.
    Why do we compare both?

    The proper way to do this is Go vs Python or Go vs Js or Go vs C# Or any other language comparison 🤔.

  2. I believe such comparison between languages is quite deceptive especially the title. A programming language may have better performance or better error handling than others. However, it’s pointless declaring it the winner if its an uphill battle doing certain projects with it. Its better to compare frameworks that solve similar problems than it is to compare programming languages.

  3. Stopped reading at the description of Nodejs concurrency model. Anything to say about async/await or worker threads?

  4. First koodos for writing article. People dont realize how much effort that takes i think.
    I dont disagree with you overarching statement, dont think any programmer would. The tool is often decided by the projects needs. However you seem to make some false assertions on node end of things. Node while default is single threaded worker threads were added since mid 2018 giving it the ability for concurrence for example. Can also use clustering to take advantage of multi processor systems.
    No intentions of starting a “no my language is better” war lol. Just trying to help inject information that was missing. Thanks again for article was good read.

  5. With all due respect, this comparison lacks depth and it’s misleading. It’s mixing language characteristics with runtime engines.

    For concurrency, Node is designed to be deployed in production as a cluster for HA. Something like PM2 will run a node process on each core allowing maximum parallelization and independent recovery. Error handling is a JS spec not Node. Anyway, it is much better in JS because you can have custom error types extending from Error and you can catch each type independently and handle as you wish. Also, you can have a global error handler. High pay might be true, but there are many more Node jobs. Go is a pretty sweet language, but JavaScript is way more flexible.

  6. Go biased article I would say.
    But appreciate the efforts put in .
    Every language has its pros and cons we all can agree on that.
    Node.js is a runtime for that matter.
    Paypal, uber and many companies use node.js for their tasks because of its scalability and being able to handle much more requests in single thread which results in consuming lesser memory.
    Where in traditional web servers every request is handled by a different thread this is much more efficient when it comes to i/o intensive application.

  7. I must strongly disagree about Go being the winner in error handling. This is very application specific. While Go might be more disciplined, it also forces you to clutter your code with loads and loads of error handling scopes.
    Javascript’s types errors allow you to keep your business logic flow completely clean and handle all errors by some error handler at the top of the scope. You can define different handling strategies for each error (DbError, ValidationError, AuthError, etc.) at a single point in the application.

Leave a Reply