I’m a big fan of Elixir and Phoenix framework since 2016 and I still love it for its clean code and simplicity. In the beginning, I treated it as a natural next step on the learning curve but then I decided to make it my main area of development. Let me share my passion and a story based on the most recent case study. Once you get to the happy ending – you will have no doubt on why choose Elixir for your next project.
<div class="blog-posttoc"><div class="blog-posttoc--title">Table of Contents</div>
- Elixir – Why I Believed in Magic
- Technical Bottlenecks – A Never Ending Story Actually Ends Here
- Challenge Accepted – A Recipe With Secret Ingredient
- Metrics don’t lie
- Avoiding Pitfalls Just Got Easier
- Wrapping up - Case Study That Rocks</div>
Elixir – Why I Believed in Magic
Elixir may seem to be a relatively new programming language yet it has a very solid background. Its growing popularity in 2019 and extraordinary performance come from the fact that it was built on the Erlang virtual machine (BEAM) designed originally for the telecom industry. Its core aim was to handle thousands of concurrent connections. The real magic lies within Phoenix and Ecto open-source libraries. They offer a wide range of benefits - from intuitive DSL to outstanding architecture.
Technical Bottlenecks – A Never Ending Story Actually Ends Here
Effective Application Scalability guarantees long-term success. We all know this basic truth about apps but we sometimes seem to forget that simple truths are accompanied by even simpler solutions. Once you craft a first-class product, you always aim to get more and more users. As the traffic grows in time, your app needs to have a capacity to handle multiple requests per minute (RPM) which translates into dynamic performance. If you are not prepared for rapid volume growth, your app will inevitably lose the audience. The same old story happened in this case. The video processing tool which runs alongside application was designed to frame snapshots from a video stream. It might have been doing the job but at the same time, it significantly affected the entire app performance. The problems piled up due to the outdated code base and high memory usage. The latter is a true killer to most startup companies these days - it dramatically increases server costs.
Challenge Accepted – A Recipe With Secret Ingredient
When my key Client asked how to solve the issue I fired the answer right away. I proposed the Big Three solution to scale their Progressive Web Application (PWA) and cut down video processing time:
- Design simplified Data Flow
- Implement Elixir service
- Arrange AWS infrastructure
I believed that a mixture of all three ingredients would fix the problem and boost the entire app performance. The essential catalyst, however, was Elixir and Erlang environment with all advantages of their solid design. Big market players from several industries including banking, social media and instant messaging cannot be wrong. They already deployed Elixir, they rely on it and enjoy all the benefits it brings. Let me introduce two main features that make Elixir stand out from the crowd.
Concurrent Processes vs OS Threads
In the case of high throughput applications, the last thing we need is a headache of poor end-user experience. The problem occurs when the app is written in language using Global Interpreter Lock (GIL). It only allows one thread at a time to access the shared memory. This is always the case with languages based on OS Threads like Ruby. Elixir, on the other hand, uses Erlang Processes making concurrency its main goal. Its code runs inside lightweight threads of execution called processes. They communicate with each other through messages and use all resources to the most efficient extent. Moreover, Elixir has its own scheduler that is able to keep the system fully responsive even during high traffic peaks.
OTP and Fault Tolerance
Open Telecom Platform (OTP) is a library for Elixir. Its architecture resembles a set of building blocks. It is not only a set of standards that helps you build applications. OTP framework handles well all potential problems and creates a system of fault-tolerant computing. Special processes named Supervisors monitor the system. When they spot a fault, it is quickly identified and rectified. Such Let it Fail approach makes huge favour to developers since they can focus on their core tasks rather than on possible failure scenarios.
Metrics don’t lie
The solution saved the server costs which was a real lifesaver for the Client’s budget. The whole process was decoupled from API so it was quick and straightforward. Moreover, fast in-memory datastore that originally derived from Redis was no longer a case. This is where Erlang Platform proved its magic - it had plenty of useful built-in tools and ETS store was just at hand. Video processing time was reduced from 5 minutes to a few seconds and that was a sweet cherry on the cake.
Avoiding Pitfalls Just Got Easier
This cake was not entirely covered in sugarcoat - every process has its pitfalls and holdbacks after all. I encountered one when I realized that Elixir had no built-in package management for video encoding (FFmpeg). I managed to deal with the problem promptly because Elixir ecosystem isb. Integration with external services was easy as 1-2-3. I created a simple wrapper around the FFmpeg binary without a need for a more sophisticated solution like Native Implemented Function (NIF). I focused on quick MVP implementation and it worked perfectly.
Wrapping up - Case Study That Rocks
A recipe for boosting application performance turns out to be no rocket science. I just shared the formula with you and my story ends here. Now, I invite you to discover this great technology, give it a try and sign up for the upcoming events on ElixirConfEU.
If you want to find out more about Elixir development, get in touch with our development team.