Gopher in Healthifyme

Anil Kumar Nayak
HealthifyMe Tech
Published in
4 min readJul 29, 2020

All tech stacks in HealthifyMe revolve around Python. It is undoubtedly the best language to start a new project. One of its best features is that it enables more work with lesser lines of code. With frameworks like Django and Flask, development has been easy and fast. The journey and growth of our company on ‘python is the best’ road has been super smooth. Our user base has been growing, and over last six months, users have become even more active pushing the overall traffic on our application up by 50%. Our systems were designed to take on the extra load. But we realised we reached real cross roads looking at the resources consumed.

Either we choose to continue the same way and pay the price, or find efficient way to run, we chose the later. In spite python being slower language compared to its peers, main issue was concurrency. It was time to switch to one of the alternatives. In our journey moving from monolithic to micro service architecture, python became a hindrance here as it did not have the required concurrency mechanism.

In search of alternatives

We started looking at alternatives. We started building sort of a checklist of our expectations from our new language, inspired from the processes that have been working well for us in our experience with Python. We needed an alternative that would be:

Looking for alternatives

Fast: Obviously, it should be much faster than python and be able to handle CPU intensive tasks efficiently.

Easy to learn and implement: Which would make coding on par, if not, faster than python. This was important as we were investing time and resources into a language that might not have had similarities with python.

Flexible Typing system: Flexible typing to make development faster and less frustrating. This was a key concern as most low level languages come with a static typing support with very rigid terms.

Very good at concurrency: Transition to microservice based architecture meant having several small services talking to each other, Concurrency is very important in this case. This will also help in handling a large number of users efficiently.

We narrowed down our options with these strict parameters. Now the choice and decision was even more difficult. Our available options were:

Rust, C++, Golang and Nodejs.

Working on choosing the best

All of them had good concurrency. Now the task was to find which one would be the fastest. We did a simple test: a CPU based task by writing 8 queens game algorithm.

What we found: The fastest was C++, followed by Rust, Golang and Nodejs. These are brief observations we made on each of them:

Rust: Rust is a relatively new language, sometimes touted as an alternative to C. What makes it a lot faster is the absence of its own garbage collector. Rust also has a different approach to programming inorder to work without garbage collection which makes things difficult. Also the syntax of the language is not quite intuitive.

C++: C++ is very fast and good for applications of all kinds. But memory management becomes the responsibility of the developers. Though in a way this is good, the developers have to be very careful while writing codes to avoid problems like memory leaks, runtime time errors etc. which hampers the productivity of the developer.

Nodejs: Nodejs has proven itself to be a very good language for concurrency. But it comes with the quirks of javascript. Hence it wouldn’t be wise to write a core system with a dynamic typing system as it gets difficult to maintain. We could opt deno instead. But it is not mature enough at this stage. However Nodejs’ single thread concept is not always advisable for CPU intensive tasks. Though we use nodejs sometimes in the front-end server, we wanted to see any better alternatives.

Golang: Golang comes with first class concurrency support. It can handle a large number of tasks at the same time due to its goroutines support. It moves away from the concurrency with threads concept. It has a flexible typing system and does not enforce OOPS.

Finally decided to take a chance on golang.

Why Golang?

From our benchmarking experiment we found that golang could handle 1.5x more requests than nodejs. Flexibility in the typing system ensured that we could work with it almost as we had worked with python. Added bonus: it came with inbuilt code formatting, testing framework, profiling etc. Code looked intuitive and the language was easy to learn. And most importantly: it produced a single executable which helped in deployment without much hassle.

Golang had everything we needed. Though it was a bit slower than C++ and Rust, we wanted to find if this drawback could be made up in terms of developer productivity. We were all set to write a production ready application using golang and see how it is in practice.

https://medium.com/@anil.k.nayak8/working-with-golang-our-first-steps-34dc38a2ee92 describes our initial experience with golang.

--

--