Go vs Python – clash of backend titans

Today, with dozens of available languages and frameworks, development teams are challenged to make educated choices based on the requirements for stability, performance, or concurrency. Nonetheless, working with tens of startups and developing companies, we’ve seen too many times how a choice made on wrong assumptions can end in the architecture being unscalable or the technology debt being too expensive to pay.

Sometimes, the only way to get out of the aforementioned trouble is to rewrite the entire application from scratch. Bearing such a scenario in mind, you’d probably rather think twice before choosing the tech stack for your project. After all, backend is the heart and soul of every software. It needs to be strong and well-tailored to the requirements as well as the nature of the product you’re about to develop.
 
Recently, more and more backend teams are wavering between Golang and Python. To help you decide on either of these, we’ll dive into the characteristics of both languages and set one against the other. Specifically, we’ll be looking at the Go vs Python competition in the following fields:

  1. Origins
  2. Type system
  3. Frameworks, libraries, and community support
  4. Use cases: how to match the product with the right technology
  5. Performance
  6. Readability
  7. Popularity
  8. Real-life comparison

So without further ado, let’s see how the backend titans compare.

Go vs Python: Origins

Python has been around for almost 30 years now. Designed and released in 1991 by a Dutch programmer Guido van Rossum, it was initially used in data science. However, from the moment it started its career in web development, Python has been crashing popularity rankings. For instance, in 2018 and 2019, it was announced the number one backend language.
 
Compared to the good old Python, Go (aka Golang) looks like a toddler. Released in 2012 by three Google developers (Rob Pike, Robert Griesemer, and Ken Thompson), it was supposed to deal with the difficulties that programming for large and scalable software systems entails. Since then, Go has been challenging Python big time, especially in terms of performance and speed.

Merixstudio Python ebook

Type system

Go is a statically typed language, which means it binds variables with their types. It signals errors at compile time. This way, the compiler is able to identify even the most trivial bugs right away.
 
Python, on the other hand, is a dynamically typed language. Instead of a compiler, it uses an interpreter that parses the commands in the program and executes them. The difference between Go and Python in this respect may look insignificant at first glance. The truth is, however, since the latter leaves more freedom to interpret the correctness of the code, there’s a risk of the interpreter overlooking some of the bugs due to incorrect interpretation.
 
What does this mean for you?

As far as the code execution is concerned, Go seems more old-fashioned but robust at the same time. What’s more, it’s definitely easier to handle the code written with Golang when the scale and complexity of the application bump up.

Go vs Python – frameworks, libraries, and community support

Python comes with a wide range of packages covering web development (such as Django or Flask), data analysis (Panda), image processing (OpenCV), visualization (matplotlib), or machine learning (like TensorFlow, Scikit-Learn, or PyTorch). What’s more, with the rise of web frameworks, Python’s popularity and community has grown exponentially, leading to the language becoming the world’s second most loved technology among developers.

Most loved technologies

% of developers who are developing with the language or technology and have expressed interest in continuing to develop with it according to Stack Overflow

Go’s in-built libraries, though much fewer than in the case of its competitor, still cover almost the same usage fields as those of Python. There are Go libraries made for encryption, concurrency programming, database handling, and web development. Some of the most known include Revel, Iris, Echo, Macaron, and Buffalo, though none of them is as prominent as, let’s say, Django.
 
What does this mean for you?

Frameworks and libraries significantly speed up the software development process which is an added value for many businesses, especially startups. So if you’re looking to save time and money while maintaining the high quality of your product, it may turn out that Python is a better choice. After all, when it comes to the richness of the framework and library ecosystem available for both Golang and Python, the latter wins big time.

Use cases: how to match the app with the right technology

To avoid comparing apples with oranges, we need to think about the Go vs Python competition in terms of different application types they are best suited for.
 
As a general-purpose language, Python can be used for almost every kind of application, from nice and entertaining logo creators to data-loaded financial apps.

Check how we harnessed Python powers to create a logo maker fuelled with Machine Learning.

Thanks to the insane number of available libraries, Python-fuelled backend works well for machine learning, data analysis, deep learning, and web development. We can observe more and more companies using it in banking and insurance projects, mostly because of its ability to handle big data sets.
 
Go, on the other hand, is used mostly for system programming as well as cloud and cluster computing that require high robustness and safety. As we’ve mentioned earlier, even though the number of libraries available for Golang is not (and probably will never be) as rich as for Python, we’re still talking about a powerful and easy to use set that allows supporting web application development.
 
What does this mean for you?

In this category, there are no winners or losers. It all boils down to your vision, objectives, market needs, and the type of product you want to build. While Python will be a better choice for web development and machine learning, Go is surely going to perform much better in lower-level programming.

Performance

Both Python and Go are super-efficient when it comes to web development. To be honest, performance issues are a rarity if you’re using either until a significant scale of the project is achieved.
 
Go has an inbuilt concurrency handling which means it’s able to handle multiple requests at the same time. Python, on the other hand, being deprived of this feature, executes calculations of high-level complexity much slower than Go.
 
To prove my point, let me introduce you to an experiment of solving three different but widely known complex problems named Mandelbrot equation, n-body, and fasta. What they all have in common is that they take an insane amount of computation and require stunning performance and memory management.
 

Mandelbrot, n-body, fasta

Source: Edureka

The numbers speak for themselves: Golang performs on average 40 times better than Python when making the same calculations. Does this fact discredit Python? Not really – unless you’re planning to build a system as complex as Google itself or a SaaS serving hundreds of companies with millions of end-users. In those cases, optimizing with Cassandra, Redis, and other tools might be insufficient.

What does this mean for you?

It’s worth considering Go when you’re building multi-tenant applications that process big amounts of data and serve millions of users. For every other application, the final choice between Golang and Python will most likely depend on factors other than performance.

Golang vs. Python: Readability

It’s never enough to emphasize how important it is to keep one’s code clean, in accordance with the best practices, and readable. When choosing a programming language for web development, you need to take into account that readable languages can make it a lot easier to understand and maintain the codebase even for a hundred-men-strong development team.
 
Things can get complicated in Python as it leaves a lot of freedom when it comes to programming. Developers, of course, can see it as an advantage; however, the possibility to say the same things in many different ways can easily lead to confusion and result in impediments for future analysis and fast development.
 
Go comes with a specific approach that has a direct impact on its readability. Let’s take class inheritance as an example. As it’s not directly available in Go, whenever you try to add your own implementation of an existing part of the code, you need to deal with lots of code copying.  As a result, you can find the code much less elegant and readable than in Python.
 
What does this mean for you?

Programming with Go will save you a lot of time on optimizing the code. However, it might feel much less elegant, less structured and even less readable.

Popularity

Comparing Go and Python in terms of popularity might be a bit unfair to the former. All due to the fact that, as an older and more established language, Python has 20 years of advantage over Go.
 
According to Google Trends, the last 5 years have been generous for Python’s popularity, whereas Go’s audience has been rather stable. It’s not surprising when taking into account a broader set of potential application types Python is suitable for.
 

Go vs Python Google Trends

Source: Google Trends

What we can’t see on this graph is how interest over Golang has been growing over the last five years. If you take a closer look at it, however, Google Trends indicates that the number of searches for Golang is now on average four times bigger than it used to be in 2015. This gives hope that the popularity of Google’s child for introducing scalability and concurrency to systems and applications will continue to grow, bringing to life robust and secure cloud applications.
 
What does this mean for you?

Python is not going anywhere. As a multi-purpose language, we expect it to still rock in the top programming languages, next to Java and C.
 

IEEE Top Programming Language List 2019

Source: IEEE Top Programming Language List 2019

Real-life comparison

Enough of the theory – let’s look at how Golang and Python compare in actual commercial projects. Some time ago, we were approached by a client who wished to alter the architecture of their product to enable scaling it once the need for doing so arises. To achieve this goal, we decided to build an API gateway proxying data to and from application instances.

The main challenge we faced in this project was choosing a solution that will ensure the high response speed of our API proxy. To decide between Go and Python, we run a series of tests using the following default parameters:

  • API Gateway machine: 16vCPU, 64GB RAM and 32vCPU, 128GB RAM
  • Backend APIs machines: 2vCPU, 8GB RAM
  • Backend APIs were referred by their Private IPs and they were always returning a list of 50 objects
  • Duration: 1 minute

To give you the idea of what outcomes we were dealing with, let me present the results of two tests (whereby “buckets” refer to backend applications with REST API):

  • 16vCPU Golang version - 100rps (requests per second) - 10 buckets vs 16vCPU Python version - 65rps - 10 buckets
Go vs Python test
  • 32vCPU Golang version - 175rps - 10 buckets vs 32vCPU Python version - 140rps - 10 buckets
Go vs Python test 2

As you can see, Python’s response time is longer. In the same timeframe (which in our case is 1 minute), we're able to handle even 10500 requests in Go, whereas in Python we arrive at as much as  2000 requests fewer. Of course, one may try to achieve performance results similar to those of Go; however, success in this regard is unlikely regardless of the type of tools or the amount of effort put into it. As far as the response speed is concerned, Google’s language wins bit time and one of the reasons for that is the built-in mechanism for handling concurrency: Goroutines.

Go vs Python: Conclusion

Being in charge of a new software project or even an entire startup, you already know that the decision which programming language to choose is a serious dilemma. Today, with tens of available languages and frameworks, it’s bigger than ever.

Check our top 3 choices for backend development in 2020

Powerful backend technologies are the right direction to look at for maintainability, performance, and scalability; however, they might be an overkill for simple CRUD applications. Go would be a good choice for performance optimization measured in milliseconds, Python - for bigger applications the require a proven and readable project structure.
 
When it comes to more complex and data-rich systems, we have some good news for you. Go and Python don’t have to be direct competitors. Both can be used for building independently deployable microservices that require particular performance or readability levels. Contemporary applications can, in fact, use a mighty combination of Go’s performance and Python’s framework ecosystem.


 
Keen on leveraging both? Check our experience in implementing them and discuss your options with our experts.

Navigate the changing IT landscape

Some highlighted content that we want to draw attention to to link to our other resources. It usually contains a link .