This page looks best with JavaScript enabled

Golang vs. NodeJS for Web Apps - A Small-scale Developer View

 ·   ·  ☕ 7 min read

If you had enough of single threaded behaviour of Node and are ready for the next level (/s) - I strongly recommend you evaluate Go for your next project.

Javascript is the most used language in the world and that status will not change in a hurry - thanks to its frontend nature. NodeJS is super useful since we can use the same language for server and stand up a production grade server using frameworks like ExpressJS or Fastify in a matter of hours. I absolutely am in love with NodeJS -

  1. Light weight
  2. Easy to create, deploy and maintain applications
  3. Many, many packages that make it easy to add new functionality (yes, I love them packages)
  4. Decent performance

However, there are a few concerns -

  1. Single threaded nature can be a cause for concern at some level. Yes, there are promises but with due respect to them - there are going to be transactions that can still make the engine “stuck”. CPU-bound, high performance tasks can be a problem in Node
  2. Treatment of numbers as floats are perceived to be harmful for applications that treat such transactions as sacred
  3. Types help in development-time and runtime validations that avoid all that additional code checks. Medium to high complexity projects can be (arguably?) easier to maintain with typed languages.

I am a small-scale developer + entrepreneur who creates a number of SaaS applications and also builds applications for my clients. I do not quite share any of the outlined concerns of Javascript, but I was actively looking at an alternate “fast to develop” platform about an year back. That led me to do some quick research by developing “to do” apps like there was no tomorrow. Here’s a highly opinionated view of a small-scale entrepreneur and developer on how Golang can be super useful as part of your tool-set.

Aside: While I use Typescript in many projects, I cannot firmly switch over to that camp. I love the “type less” nature of JS and it keeps my productivity high for smaller projects. Also, I found it easier to switch all the way to C# or Go.

The Alternatives

The alternatives I evaluated were -

  1. Rust: Seems to be everyone’s darling nowadays, but is hard to learn and is certainly not a “highly productive” language for something like web development
  2. ASP.NET and C#: I love the way C# has been developed over the past many years. I have used C# only for amateurish desktop applications, and am not afraid of extending it to web. Web assembly support and Blazor make this an exciting space
  3. Golang: Simple to learn, code and deploy (thanks to the highly touted “single executable” nature of Go). Really light-weight and quite exciting async programming experience

Finally what drew me to use Go was the “promise” of easy async programming using go routines and the promise of better & consistent performance. Though I doubt whether I can put either of these to active / practical use and see exponential gains for any of my applications in the near term.

golang-gopher

Advantage Go for web applications

Here’s a quick take on why you should consider Go in your toolset for web development.

Simplicity

Go lang is easy to learn.

Despite the strictly typed nature of Go and more complex concepts like channels, coroutines, et. al, one can easily start identifying everything that a given program is trying to do quite easily. I found this easy to pick up nature quite invaluable when trying to evaluate the complexity of web applications which were created by others but I had to go in and make changes.

Light weight

light-weight-apps-golang.jpg

Yes, Go is as light-weight as they come despite being “decently productive”.

I can run more production applications, even more POCs and then some on a single VPS without any problems. While I did not quite have any issues per se with NodeJS based apps, I would love to imagine a not-so-distant future where I can deploy hundreds of smaller applications without spending a fortune using Go.

Performance

I am not going to lie. Despite reading up quite a bit and finding for myself on how performance of applications can be specific to a given use case, the promise of high performance in Go applications is a strong one.

speed-performance-application

After looking at Techempower benchmarks for a few years, I had resigned to the fact that my favourite frameworks are not going to be burning rubber on the road anytime soon. Go (and to a certain extent C#) is one of the ways of “future-proofing” my products and re-assure to myself that I can build “fast applications” for thousands of users.

Do note -

  • often times, performance is a concept highly specific to your use case
  • using a language does not ensure automatic high-performance, but the language features like async programming, “ability to make the machine work to its fullest” help. Compiled languages are often better here
  • Web applications often do not have the same issues as their desktop / mobile counterparts. For e.g. Fastify + Postgres ranks higher (#148) as compared to ASP.NET + Entityframework Core + Postgres (#149!). Using an ORM in Fastify can of course throw a spanner in these results. A highly productive framework like Nest + Fastify + Mysql is not far behind (#189)

* Performance rankings are good as of 2020

Scalability

Go has lower memory footprint. It also compiles to a specific platform and occupies lower space (the latter is not quite an evaluation factor in this day and age). For me low memory usage translates to better scalability.

Concurrency and the ease of using async programming also contributes to better scalability. You could potentially use Go routines to start hundreds or thousands of threads on a 1 GB VPS without issues.

Developer-friendly

Go is easy to learn, comparatively easy to develop, and easy to deploy. Go also features in-built code formatting rules, good support in code editors and a good packaging system.

The Bad of Golang

While I would love to use Go for command line applications, I am not too sure I will switch over my web apps really soon.

  1. There’s a lot of typing/copy-paste involved. Go’s simplicity also means fewer functions that provide good abstractions for common tasks. While I would love to use for loops for every problem, Javascript and C# have really good shortcuts to solve problems that are too elegant and productive to resist
  2. I don’t particularly like the error handling (if err != nil). I grew up thinking the world of try/catch - so this may be an “old-man problem”
  3. Golang was blessed on us a while back, but there are far few gigs on Go. SMBs stay away from the Go world since they don’t see enough developers available (= expensive to create and maintain). This is a problem for my “develop everything despite severely limited resource” mentality

I could not avoid a direct performance to NodeJS and the thousands of frameworks therein.

  • Node was more productive - thanks to Javascript, and many useful packages in the Node ecosystem
  • Node frameworks offer “more”. I can completely switch to Typescript and code like Angular in NestJS, or go kaput with my own structure using Express/Fastify
  • Examples, demos and learning resources are bountiful in NodeJS. For e.g. integrating your favourite payment gateway is made easier with examples and possibly a SDK for NodeJS, not so for Go (though you could use their APIs as easily)

Conclusion

  • Learn Go
  • Use Go for side projects
  • Don’t completely switch over (unless of course if you are in a Go-friendly company)

Are you sold and want to try out Go?

  • Start with the “tour of Go
  • Once you are ready, start with Fiber framework. While frameworks are not as important in Go as in Node, Fiber makes transition easy since it follows the same concepts as ExpressJS

Also see: start on golang with Fiber.

Stay in touch!
Share on

Prashanth Krishnamurthy
WRITTEN BY
Prashanth Krishnamurthy
Technologist | Creator of Things