Node vs Go for a REST API | Which is best?

Posted on

This articl is about which is best Golang or Go and Nodejs when you’re making a rest API.  When would someone choose one over the other for REST API’s and I think that’s an excellent question, you see the thing that I consider when I use Golang versus Nodejs, it basically just boils down to two main things and that is whether or not, I need what node is offering as opposed to what nodejs is offering now.

I know that’s a little bit fuzzy but let me walk you through the same, so the benefits of you seeing something like nodejs, it’s all JavaScript and depending on your viewpoint, that’s a good thing and a bad thing will touch on exactly why that is in just a moment. But what is fundamentally good about nodejs is, that there are a lot of resources both learning resources, there are tons of libraries, there are tons of tutorials, there’s so much.

Golang really shines when it comes to REST APIs

Node vs Go

Now go comes into picture that JavaScript does well, it’s easy to access, it’s easy to learn, and it’s also very easy to find people who know it the amount of people that you will find that know JavaScript is going to be failed, like there is a lot more people who know JavaScript and there are people who know go now.

When would you use Golang, if javascript is such a good great thing, the thing is that Golang really shines when it comes to REST API’s. If you’re looking for performance and types, why in the world would this thing matter! Well performance if we look at performance for example go has the ability to actually leverage more of the machine that it’s running on, you can run multiple threads, you have all these different like Golang routines.

For example, it can actually squeeze more out of each container because I’m assuming that you’re running things in a container than node will be able to do. Now you can do certain things like you can create multiple thread workers and so forth nodejs, but in general, you don’t! That’s where go really comes in and it kind of comes into its own. Go is really great for a small service that needs performance and a REST API depending. It kind of depends of course, on the size of the REST API as well, but for the most part it’s a really great choice for that sort of work.

JavaScript doesn’t have a type system at scale

Node vs Go

Second thing, I mentioned was types now the biggest problem with JavaScript is that, it doesn’t have a type system at scale, trust me guys at small-scale it may not matter so much but it becomes a really important at scale and it also becomes important in very specific sort of situations, where you really need a type system to work effectively.

I’ll give you a great Example, never ever if you can avoid, it create any type of application that uses JavaScript, you have to do money calculations with a lot of rounding and stuff of that nature because it simply is not good at that sort of work, if you are simply taking in data saving it to a database and sending it back to somebody then node is perfect but go has a typing system and it doesn’t have all these sort of issues, so for me it really boils down to what type of application that you’re writing if you are making a REST API it read.

As I said, it really depends on your setup if you are making a standard simple REST API, for you that does not have a very specific type of use case then I would choose nodejs because as I said there are a lot of other benefits to using nodejs.

NodeJs is great for boilerplate

Node vs Go

In theory, you could use something like typescript for example, or flow to get the typing system but on average that’s the way that I think about it.  I said nodejs is great for boilerplate like you suddenly some standard type of rest API, but if you need to squeeze the absolute living out of the performance or you need a typing system to help you out.

In other words you have a really large rest API or maybe you’re doing something like stripe for example like a payment providing type of rest interface then go every single day of the week because, it’s going to handle more load over time and as I said with the typing system you can actually maintain your code and keep it good for longer that’s at least how I feel about it.

So that’s a kind of where it boils down to you go with nodejs if you’re making something small or something very standard that doesn’t need any type of specific thing, it’s just a normal old application or normal old rest API and you go with go if you need extra performance and a typing system that’s at least how I feel about it, this actually exactly what uber found to be true for them when they switched over, they have a lot of nodejs microservices in their ecosystem and one of them was specifically under a lot of stress because it was needed in order to make a lot of other services work.

So it was like bombarded by tons and tons and tons of requests every second so they rewrote that in Golang in order to improve the overall performance because they could actually realize that they could actually squeeze more out of the hardware that the  container was running on by simply leveraging go. So that’s my answer to you use nodejs if you don’t have anything specific in mind and use Golang if you need a type system, in other words you’re dealing with money or some type of very advanced rest  API and you need the extra performance.


Leave a Reply

Your email address will not be published. Required fields are marked *