Why did Pinterest Move to Elixir

Setting up an Elixir Server

C. L. Beard
OpenSourceScribes
5 min readSep 7, 2023

--

Photo by Dima Solomin on Unsplash

Elixir has several advantages over Python when it comes to server development, which can be grouped into the following categories:

1. Concurrency and Scalability

Elixir, built on the Erlang Virtual Machine (BEAM), is designed to handle many users or growing audience sizes without the extra cost of additional servers slant.co. This is due to its lightweight process architecture, enabling Elixir to handle many concurrent processes without affecting performance invozone.com, serokell.io.

2. Performance

Elixir can solve complex tasks faster than Python because it relies less on object orientation due to its functional programming nature. This results in better-performing code without sacrificing readability invozone.com.

3. Fault Tolerance

Elixir has a high degree of fault tolerance, preventing network, compute, and other hosting issues from affecting application operations. Its use of multiple concurrent nodes mitigates risks associated with incorrect data, logic bugs, and other sources of code faults techtarget.com.

4. Functional Programming

Elixir's functional programming nature makes it easier to debug and test, with built-in support for concurrency. If your program relies on multiple tasks happening simultaneously, Elixir would be an excellent choice invozone.com.

5. Syntax and Productivity

Elixir's syntax is similar to Ruby's, making it expressive, concise, and productivity-oriented. This results in less code to write and faster development cycles erlang-solutions.com, serokell.io.

6. Use of Erlang VM and OTP

Elixir leverages the Erlang VM (BEAM), known for running low-latency, distributed, and fault-tolerant systems stackshare.io. It also uses the Open Telecom Platform (OTP), part of Erlang's standard library, that provides a solid foundation for concurrent programming serokell.io.

7. Phoenix Framework

For web application development, Elixir's Phoenix framework is as easy to use as MVC web frameworks like Django in Python but backed by the BEAM. It enables efficient creation of web apps without compromising speed or maintainability serokell.io.

So, while Python is praised for its readability and has a mature ecosystem, Elixir stands out in terms of concurrency, scalability, performance, and fault-tolerance, making it a strong choice for server development, particularly for applications that require high performance, reliability, and scalability.

Elixir allows the making of things that were unthinkable just a few years ago, like creating online games that are fully rendered on the server side.

Pinterest, a popular social media platform, made a significant saving by switching from Python and Java servers to Elixir servers. The company managed to save over $2 million per year in server costs paraxial.io.

One of the primary reasons for this saving was Elixir's ability to efficiently handle high-volume, high-impact services, particularly around performance tooling and monitoring. Steve Cohen, a software engineer at Pinterest, noted that when he started on the spam team, they had close to 1,400 servers running. After converting several parts to Elixir, they reduced that number by around 95% paraxial.io.

For example, a system that initially ran on 200 Python servers was reduced to run on just four Elixir servers. This reduction was not only due to Elixir's efficiency but also due to better architecture. Despite running on drastically less hardware, the performance and reliability of the systems increased paraxial.io.

Another significant factor was the reduction in the number of servers needed. When Pinterest's notification system was running on Java, it was on 30 c32.xl instances. After switching to Elixir, they could run it on 15 instances. Despite running on less hardware, the response times dropped significantly, as did errors paraxial.io.

Elixir's ability to provide such cost savings while improving reliability and performance is due to its design. Elixir is built on top of Erlang, a platform designed for concurrent software that must stay online. This design makes it ideal for applications like Pinterest that require high reliability and performance paraxial.io.

In addition to these savings, using Elixir also allowed Pinterest to clean up its codebase. The Elixir code was about one-tenth of the size of the old code, making it more maintainable and easier to work with venturebeat.com.

These improvements can be attributed to Elixir's efficient handling of concurrency, its functional programming nature, and its use of the Erlang VM and OTP for building scalable, reliable systems.

How did using Elixir allow Pinterest to clean up its codebase and make it more maintainable?

Pinterest's decision to switch to Elixir for certain parts of their system resulted in a significant reduction in the size of their codebase, making it cleaner and more maintainable venturebeat.com.

Elixir's syntax is clean and easy to read. It's a functional programming language, which encourages a different way of thinking about programming compared to object-oriented languages like Python. In functional programming, data and functions are separated, which can lead to more predictable and easier-to-debug code. This can result in less code being written overall, as was the case with Pinterest, where their code size went down from 10,000 lines to just 1,000 lines mlsdev.com.

The functional programming nature of Elixir also encourages immutability, which can reduce bugs caused by mutable state. Functions in Elixir are pure, meaning they only depend on the input given and do not affect or depend on the outside world, leading to more predictable code mlsdev.com.

Elixir also supports pattern matching, which can replace complex conditional logic and lead to more readable and maintainable code. It allows developers to destructure data and match patterns, making it easier to understand the flow of data through the application appunite.com.

Elixir comes with built-in tools for testing, which can improve the maintainability of the codebase. These tools make it easier to write tests and to ensure that the code behaves as expected, which can lead to fewer bugs and more maintainable code mlsdev.com.

In addition to these language features, the Elixir community has created a variety of tools to improve code maintainability and readability. These include tools for static code analysis, automated testing, and code formatting, which can help enforce consistent code style and detect potential issues before they become problems tech.findmypast.com.

In summary, Pinterest was able to clean up its codebase and make it more maintainable by leveraging the features of Elixir, such as its functional programming nature, clean syntax, pattern matching, and built-in testing tools, as well as tools created by the Elixir community.

--

--

C. L. Beard
OpenSourceScribes

I am a writer living on the Salish Sea. I also publish my own AI newsletter https://brainscriblr.beehiiv.com/, come check it out.