Top 5 Reasons Why Switched From Python To Go

By Kimberly Cook |Email | Nov 21, 2018 | 11607 Views

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 becomes so match popular within a few years.

So What We Had Before Using Go? 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 the single project because they have a lot of things that are similar but the 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.

After 1 month of building API service with Django, I felt that Django is great until you building something very usual, but when you want more performance and some custom modules things getting more and more complicated.

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

Here are 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 a 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 the server and it will work, without installing any dependencies there!

2. Static Type System
The 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 a 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

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 are the results of Benchmarking Game, which are unfair, it depends on application type and uses case.

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 is 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 the programming language. Go language creators and the community has 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 the 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 building 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 exist. Less code, fewer troubles!

Go gave us huge flexibility, single language for all use cases 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 the database and make a streaming with WebSocket from single or multiple services! This is an awesome outcome from Go language features.

Source: HOB