REST API Performance Comparison Python vs Golang
Tags: flask, restapi, webdev, python
Published: 2020-01-08 06:53:25

---
title: REST API Performance Comparison Python vs Golang
published: true
date: 2019-12-30 10:33:58 UTC
tags: flask,rest-api,web-development,python
canonical_url: https://medium.com/innovation-incubator/rest-api-performance-comparison-python-vs-golang-dc4decbd0543
---

In this post, we’re going to explore building APIs with Python and GO. We’re going to put these two languages to the test and grade their performance based on response time. I’ll be using Postman for API testing. REST APIs in Python is powered by Flask and Mux for Golang

We are going to perform CRUD operations onto a PostgreSQL instance running on localhost using python and go and rate them across each category.

What is CRUD? It stands for Create, Read, Update and Delete, these are the basic operations performed on a database. Read more about it from the below reference.

[Create, read, update and delete](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete)

First, we have to set up the PostgreSQL instance and create a table onto which we can perform the operations.

![](https://cdn-images-1.medium.com/max/424/1*J9xAmVLISSo0slSr6F2nmw.png)

here we create a simple table called data with a single text field. We’re going to perform the CRUD processes on this table inside the Postgres database.

The code repo can be found at

[devpranoy/CRUD-pygo](https://github.com/devpranoy/CRUD-pygo)

The APIs have been built in a way that is similar to the following architecture.

![](https://cdn-images-1.medium.com/max/318/1*CRk1t9DP5TOQd9NTxhQTxw.png)

Now let’s Analyse the response times. Let’s fire up Postman and checkout the response times for

### CREATE

Python:

![](https://cdn-images-1.medium.com/max/1024/1*ohj_i-nFyFZMKaSffs3xiA.png)

Golang:

![](https://cdn-images-1.medium.com/max/1024/1*cpgnqhx2ScEEuMf1_MPbNQ.png)

Winner: **Golang** , while python was averaging 20 to 30 ms, Golang was doing 15 to 20 ms winning by a margin of 5 -10 ms

### READ

Python:

![](https://cdn-images-1.medium.com/max/1024/1*SAPSuS4AnBMhW0GAkM7sgA.png)

Golang:

![](https://cdn-images-1.medium.com/max/1024/1*lriGSWQb17PNmsRkyOtUog.png)

Winner: **Golang** , while python was averaging 15to 20ms, Golang was doing 12 to 15ms winning by a margin of 3 - 5 ms

### **UPDATE**

Python:

![](https://cdn-images-1.medium.com/max/1024/1*Nd2Ruqja5atX5Ryks8Ydfg.png)

Golang:

![](https://cdn-images-1.medium.com/max/1024/1*Cg2Zc9yL51vtR3dsyGWy9g.png)

Winner: **Golang,** while python was averaging 20 to 25ms, Golang was doing 15 to 20ms winning by a margin of 5 ms

### DELETE

Python:

![](https://cdn-images-1.medium.com/max/1024/1*l_izwxrTEriAflq5vxPdtA.png)

Golang:

![](https://cdn-images-1.medium.com/max/1024/1*bACa0bmU1NpUsFs5TlcKDA.png)

Winner: **Golang** by a small margin of 2 to 3ms when compared to Python

### Conclusion

GO is faster than Python, duh! but brownie points to Python for being soo easy to get up and running. But the goal of this experiment was to judge the impact that migrating to Golang would bring from a business perspective. Assume that 1 million API calls are made, Say python takes 20ms per request and Golang takes 15ms per request, Total processing time in Python would take around 5.55 hours and Golang would take 4.16 hours. The difference a few milliseconds make is huge. Since most businesses use AWS for building and deploying APIs, Golang will help save a huge sum of money as AWS charges per time taken for execution.

* * *