5 Reasons Why We switched from Python To Go

5 Reasons Why We switched from Python To Go

Python is awesome! Especially Python 3 with async functionality. But really Go is not giving any chances to survive in enterprise world…

If you got the idea of this quote, then you probably tried or just looked around Go programming language. Which is I think easiest programming language that can fit in any kind of application development. Yes! you read that right, for me Go is easier to learn than even JavaScript. I think this is the main reason why Go language become so match popular within a few years.

So What We Had Before Using Go?

 

TreeScale.com mainly dashboard and API based web application with some analytical stuff. Here is our technical stack.

  • React.js for Dashboard Frontend
  • Django Python for Dashboard Backend + Authentication service
  • Node.js for API Service
  • PostgreSQL for Database and Cassandra for Logging
  • Custom written Container Registry with Rust Language

As you can see the overall infrastructure is fully micro-service based and most of the logic completely separated, even with different technologies.

That’s the main reason why we started thinking about merging API Service and Backend into single project because they have a lot of things that are similar but codebase is duplicated over multiple programming languages and technologies. But it turns out that we need to work a lot to customize Django’s API services, especially with custom JSON responses.

Why Go?

 

As I told earlier Go Language is the most easiest languages that I’ve ever seen and used. But it was only the first attraction for me.

Here is the main 5 reasons why we choose Go over Python Django

#1 It Compiles Into Single Binary

Golang built as a compiled language and Google developers did great job with it. Using static linking it actually combining all dependency libraries and modules into one single binary file based on OS type and architecture. Which means if you are compiling your backend application on your laptop with Linux X86 CPU you can just upload compiled binary into server and it will work, without installing any dependencies there!

#2 Static Type System

Type system is really important for large scale applications. Python is great and fun language but sometimes you are just getting unusual exceptions because trying to use variable as an integer but it turning out that it’s a string.

# Django will crash process because of this
def some_view(request):
    user_id = request.POST.get('id', 0)
    # If this post request has "id" parameter then
    # user_id would be a string, 
    # but you really thinking it is integer
    User.objects.get(id=user_id)

Go will let you know about this issue during compile time as a compiler error. This is where you winning time for this kind of stupid issues.

#3 Performance!!

This could be surprising but in most of the application cases Go is faster than Python (2 and 3). Here is the results of Benchmarking Game, which are unfair, it depends on application type and usecase.

For our case Go performed better because of his concurrency model and CPU scalability. Whenever we need to process some internal request we are doing it with separate Goroutine, which are 10x cheaper in resources than Python Threads. So we saved a lot of resources (Memory, CPU) because of the built in language features.

#4 You Don’t Need Web Framework For Go

This is the most awesome thing about programming language. Go language creators and the community have built in so many tools natively supported by language core, that in most of the cases you really don’t need any 3rd party library. For example it has http, json, html templating built in language natively and you can build very complex API services without even thinking about finding library on Github!

But of course there is a lot of libraries and frameworks built for Go and making web applications with Go, but I’ll recommend build your web application or API service without any 3rd party library, because in most cases they are not making your life easier than using native packages.

#5 Great IDE support and debugging

IDE support is one of the most important things when you are trying to switch your programming language. Comfortable IDE in average can save up to 80% of your coding time. I found Go Plugin For JetBrains IDEA which has support also for (Webstorm, PHPStorm, etc…). That plugin is giving everything that you need for project development with the power of JetBrains IDEA you can really boost your development.

Based on our code base statistics, after rewriting all projects to Go we got 64% less code than we had earlier.

You really don’t need to debug code which doesn’t exists. Less code, less troubles!

Conclusion

Go gave us huge flexibility, single language for all usecases and for all of them it working very very well. We got about 30% more performance on our Backend and API services. And now we can handle logging real time, transfer it to database and make a streaming with Websocket from single or multiple services! This is awesome outcome from Go language features.

Don’t forget to “Recommend” this post and share your thoughts about this.

Related Post