Stream Switched From Python To Golang

Reemi Shirsath
5 min readAug 5, 2020

Before we start with Why Stream Switched From Python to Golang let us understand what is Stream.

Stream is a platform that helps you in creating API for Scalable chat and feeds. This platform is used by millions of users. Using this platform one can scale their application in a fraction of the time and the cost of in house development is also reduced.

Stream helps customers with fast go to market product development these products are highly and easily scalable with a higher quality of user experience.

Stream has also launched its second product Stream chat in the year-end of 2019 after the successful traction for their chat products. The platform focuses on building reusable components for applications that are easy to integrate and consistently perform regardless of traffic. Some of the advanced features of Stream is Aggregation, ranking, real-time, and personalization.

Why Stream Switched From Python to Golang?

Switching to new technology is always a big step and this is major when the team you are working has only some people with prior experience with that technology especially when it is a programming language. Stream has Python as their primary language until the year 2019 but earlier in the year they decided to switch from Python to Golang.

Some of the reasons why they decided to leave Python and go with Golang is as following:-

  1. Performance:- As most of us are well aware that Golang is highly performant and since 2019 it has improvised a lot in many terms. For Stream, Golang proved itself to be 40 times faster than Python.
  2. Language Performance:- Programming language is a bond between the application and the DB, programming language performance doesn’t have much impact usually. Stream is an API provider for feeds and chat platforms and serves around 700 companies with more than 500 million end-users. They tried to optimize Cassandra, Redis, PostgreSQL for some past years but reached the limit of language. Python is a great language but comparative to Golang its performance is Sluggish for some use cases like aggregation, ranking, serialization, and deserialization, etc. Where Cassandra took 1ms to retrieve the data, Python took 10ms to convert it into objects.
  3. Productivity of Developer:- When compared other programming languages with Python, Python has more advanced features, it allows the developer to be creative with the code style for example: During code initialization, you can self-register the MetaClasses, Swap out True and False, Functions can be added to the list of built-in functions, Using magic methods you can overload operators, etc. These features are fun but at the same time harder to understand while working on someone else work. Where else Golang keeps it simple, as it forces the developer to stick to the basics which makes the code easy for anyone to understand. Then again it will vary as per the use case it is built for.
  4. Concurrency:- Golang prefers to keep things simple and doesn’t entertain any new theories or concepts in it. Golang focuses on simplicity and high performant application/system development. Golang has Goroutines which are lightweight threads, these goroutines communicate with each other using channels. Goroutines are cheap and occupy a few KBs of memory. You can hundreds or thousands of Goroutines at the same time. Complexity arise are handles by Go runtime. Due to goroutines and channels concurrency is easily achieved. Which helps you with 100% utilization of CPU without complicating the development. Goroutines requires minimal boilerplate code as compared to Python. Concurrency approach in Golang is easy to achieve where else in Node the developer needs to pay detailed attention to handle asynchronous code. In Golang concurrency there is one more factor that is a race detector which helps to identify race conditions present in your asynchronous code
  5. Fast Compilation:- Stream has written on of their larges microservice in Golang which takes 4 seconds to get compiles. Golang’s faster compilation provides major productivity as compared to Java, C++.
  6. Building Team:- As Golang is a relatively new language and getting a really good Golang developer is a bit difficult. However, the number of Golang developers is increasing as many of the developers have started adopting this new language as per the demand and hype Golang is getting. Golang is used more then Erlang, Scala, and Elixir but the adoptions of Golang is less than the popular language like Java and C++. Golang is comparatively simple and easy to learn the language. It has some basic features that you need to learn and other than these features there is defer statement, concurrency with goroutines, and channels. Golang is not the first language to provide these feature but after Golang these features got more hype. Developer with any prior experience in Python, Java, Scala, C++ can learn Golang within a short time span of one month or so.
  7. Ecosystem:- Golang has a strong ecosystem. The ecosystem plays an important role at least for the small team of around 15–25 members. Golang has appreciable support for its tools. Golang has many inbuilt libraries to name some, Redis, RabbitMQ, PostgreSQL, Task Scheduling, Template Parsing, etc. The ecosystem of Golang helps you with many basic needs for quality development.
  8. Gofmt, Enforced Code Formating:- Gofmt is a command-line utility in Golang which is built in the Golang compiler for formatting code. Gofmt is similar to autopep8 in Python. Gofmt has its own official way to format the code which is one the important thing in Golang in terms of consistency in code formatting.
  9. gRPC and Protocol Buffers:- Golang supports protocol buffer and gRPC. Protocol buffer and gRPC are used together to build microservices that communicate via RPC. Manifest is required to be written where RPC calls that can be made. After this server and client codes are generated automatically from this manifest. The code created is fast, easy to use, and has a small network footprint. From the same manifest client, code can be generated for different languages such as C++, Java, Python, etc.

Python vs Golang

As time passed Golang became more performant but Python didn’t. At Stream, they did an experiment of writing one of their pre-existing Python code functionality ranked feed into Golang.

Following were the takeaways from the experiment-

  1. Developing Python version of the code functionality took around 3 days. Around 2 weeks were spent to optimize the code
  2. Developing the same code with Golang took around 4 days but no further days were required for optimization
  3. Golang based version required substantially less work from the team
  4. Golang code performed around 40 times faster than the highly optimized Python code
  5. The Golang library for expression parsing was of exceptional quality

Stream team says

As a general trend, we see that developing Go code takes slightly more effort. However, we spend much less time optimizing the code for performance.

Read more about Stream here

You can also read more articles about Golang here-

--

--

Reemi Shirsath

𝘾𝙊𝙊 @ 𝙂𝙤𝙡𝙖𝙣𝙜 𝙎𝙥𝙚𝙘𝙞𝙖𝙡𝙞𝙨𝙚𝙙 𝘿𝙚𝙫𝙚𝙡𝙤𝙥𝙢𝙚𝙣𝙩 𝘾𝙤𝙢𝙥𝙖𝙣𝙮- Scalent.io