Elixir — Phoenix for Decision Makers

Overview

Over the past several years, several innovative technologies and concepts emerged, making it possible for small players to compete globally, on a level playing field, with bellwether enterprises. Cloud computing turned the data center operations into a utility. It allowed start-ups and small enterprises to “pay as they go” instead of having to commit to substantial physical infrastructure purchases. Relieved of non-value added overhead duties, they can now focus solely on their core business instead of having to develop collateral expertise on servers.

In parallel, the Phoenix framework, running on Elixir, which is built on top of Erlang, emerged only four years later. The functional programming paradigm offers similar benefits to software development as cloud does for infrastructure management, getting more done with less. Companies that made the switch from Ruby to Elixir witnessed remarkable improvements in performance on a fraction of the infrastructure. Moreover, using far fewer lines of code, it reduced much complexity.

Combined with the emergence of 5G wireless, functional programming and cloud technologies will revolutionize the IT Services landscape and every sector within (Fintech, Gaming, Media, Social Apps). Newer and more agile entrants can reach the market with ease, competing alongside the established and long-standing IT services giants. This white paper, aimed towards IT business leaders and decision makers, delves into the benefits of Elixir-Phoenix, the current and potential use cases, and when it may be beneficial to consider a switch over. In addition to an extensive literature review, we also interviewed experts in the field and shared our experiences.

Scaling, Concurrency & Reliability

Elixir’s core strengths are scaling and reliability, handling concurrency with relative ease. Based on the very reliable and scalable Erlang platform, built by Ericsson in the 1980s to speed up telephony, it also allowed phone companies to “hot swap” or apply software updates on the fly. In essence, they could update software without having to disconnect users in mid-call. Erlang is also popular with game servers, running multiplayer games like Call of Duty and Game of War.

Source: Joe Armstrong — Author of the Erlang programming language

Several decades later, WhatsApp adapted Erlang, giving them a substantial edge over other VOIP competitors. Most other providers found it difficult to handle ten thousand connections per machine. WhatsApp, on a single server starting out, handled more than two million concurrent connections per server, allowing them to scale beyond the reach of their competitors. In 2014, Facebook bought WhatsApp for $19 billion. Mark Zuckerberg cited the simplicity, speed, and reliability, connecting 450 million people. Today, WhatsApp’s ten-person team, running on only ten servers, hosts well over 500 million users or 50 million connections per server!

Nevertheless, Erlang is relatively difficult and not intuitive for seasoned C, Java, JavaScript, PHP, Ruby, and Perl developers. Compared to Ruby, the key features were not as straightforward: package management, build tools, meta-programming, unicode handling, and web frameworks. It was like FORTRAN compared to C++; it could do the heavy lifting (and still does today) but arcane in appearance, offering little pleasure to coders.

Then in 2011 Jose Valim solved the problem, creating Elixir, which he built on top of the robust and proven platform. He introduced Ruby like constructs, documentation, and tools to interface with the Erlang Virtual Machine (VM). Moreover, the convenient features and the ability to reference the legacy Erlang libraries did not penalize performance. Several years later, in 2015, Chris McCord, a prominent member of the Ruby community, released the Phoenix Framework. The combined language and framework offers components and concepts familiar to developers using Ruby on Rails and Python’s Django framework. That heralded a new era in programming. Although debatable, there is a marked migration from Ruby to Elixir underway. Some experienced Rails developers found that it only took weeks to convert.

Community

The community is one of the most important considerations when choosing a technology, especially open-source ones. It ensures longevity and access to talent. The Elixir and Phoenix communities are active and welcoming. The accessible and friendly leadership are driven, continuing to put forth the effort required to ensure Elixir-Phoenix becomes a technological mainstay. The “Alchemists” (Elixir-Phoenix developers) hold active meetups in London, Berlin, Warsaw, Boston, and San Francisco among other places. When I posted questions about Elixir vs. other languages, asking for pros and cons, I received 46 objective replies in short order. Hence, they are even helpful to outsiders as well as newcomers.

Case Studies

Ruby programmers, who made the switch, immediately started to report dramatic improvements. Numerous tests, processing data, illustrated 8x more throughput (speed) with a quarter of the CPUs (resources). Within an industry context, IT leadership could not ignore the “rookie’s” attributes, quickly adopting the new technology that gave them a marked competitive advantage. The most notable early adopters are Bleacher Report, Discord, and Pinterest.

Bleacher Report:

This case study is perhaps the most referenced when discussing Elixir migration. Furthermore, they are perhaps one of the largest adoptions of the language as well. Bleacher Report, which reports real time sports news through both mobile and web interfaces, handles, in peak moments, over 1.5 billion pageviews and 250,000+ users. Originally written in Ruby on Rails, they hit the wall with scaling, unable to grow cost effectively. With a multitude of users logged in simultaneously, each with unique settings, concurrency posed the main challenge.

After exploring several options, the engineering team converged on Elixir, built on the rock-solid, 30+-year-old, telecom platform. The small group of engineers soon discovered that they could do things very fast (functional programming) using the familiar Ruby on Rails like syntax. After the project (August 2015), they discovered that they could handle 8x more traffic on only 5 of the original 150 servers!

Claudio Ortolina from Erlang Solutions, who offered advisement services during the transition, suggested that companies considering such a transition should start small and expect to see results in the first three to six months. Furthermore, he stated that Elixir (functional languages) could do many things at once, requiring developers to adjust to a new way of thinking.

Pinterest:

The popular app allows users pin images and other content to various boards. Originally written in Python and the notification system in Java, the company began the transition to Elixir in 2014, finishing up in 2015. In 2014, Pinterest delivered 14,000 notifications per second. The associated system runs on 15 servers whereas the previous one did with 30. Furthermore, they reduced the codebase from 10,000 lines to only 1,000.

The company, demonstrating enthusiasm and commitment to the fledgling language, not only makes routine contributions to the open source community but also released two new tools to the community: Elixometer — a logging library and Riffed — an Apache server adaptation.

Globo.com — 2016 Rio Olympics:

Globo.com is the internet subsidiary of Rede Globo: one of the world’s five largest media conglomerates and the largest in Latin America. The Online Video group inherited a Ruby on Rails based system, allowing logged-in users to mark videos for later viewing. They could also add it to their favorites and resume watching it from where they previously left off. Additional functions included preferences and other proactive functionalities, enhancing registered user experience.

Although the User Profile API was well written and functioning properly, it started to experience performance issues when the team adapted the system to Globostat Play in 2013 and Globo Play in 2015. Those platforms, more interconnected to mobile and TV apps, increased traffic 6-fold over the original Globo adaptation. They undertook the transformation in two phases: first migrating from physical infrastructure to the cloud (Tsuru PaaS) and then converting User Profile API’s most trafficked modules from Ruby on Rails to Elixir, capturing 80% of the throughput. Within two months they achieved the following:

Discord:

The popular and free voice and text chat app, has been an early adopter of Elixir. Discord, specifically focused on the online gaming community, offers specific features that enhance real time communications. Through research and experimentation, using Elixir, they managed to reach 5 million concurrent users. They took an experimental and iterative approach, learning as they went until they achieved the desired results. Like with Globo, they benchmarked their process, identifying the bottlenecks, and started with the low hanging fruit.

Summation:

Elixir, built on Erlang, yields tremendous results with high volume, rich user experience, use cases where parallelism and concurrency matter the most. The technology goes hand in hand with cloud migration. Even rewriting just a few modules from Ruby, Python, or PHP to Elixir could yield dramatic results in terms of performance and operating cost reduction.

Technology Comparison

However, is this a “one-size fits-all” solution, replacing Ruby on Rails, PHP, Java, Python, and others? Do situations exist where Elixir-Phoenix may not be suitable? What are the limitations and tradeoffs? Most developers and business analysts will rightfully say, “it depends.” Every project is different: functionality, deadlines, budgets, legacy system considerations, and most importantly, stakeholder commitment.

However, after surveying the community, interviewing senior members who have worked with several languages, and doing an extensive literature review, we came up with the following matrix:

Considerations:

There are five questions that must be explored before deciding on whether or not to start with or convert to Elixir:

1. Response Time: Is real-time or near real-time response important?

2. Userbase and Concurrency:

a. Will there be many users logged in at the same time?

b. Will there be video and chat?

3. Availability: What are the consequences of downtime?

4. Calculations: Does your app require number crunching?

5. Legacy Systems: If migrating, what is the database situation?

Not every situation requires Elixir-Phoenix. It is not a “one-size” fits all technology. If you do not require an immediate response, nor have a large userbase, and there is little consequence for occasional downtime (site updates and maintenance), then Ruby or PHP is a better choice. Brochure websites, blogs, and small webshops, experiencing modest throughput and traffic, are still best done with PHP (i.e. WordPress) or Ruby (i.e. Shopify or Casper).

Ruby on Rails

Ruby on Rails or Rails, considered the predecessor to Elixir, emerged in late 2005. Offering a faster and more methodical approach to web-based solutions than PHP, it quickly emerged as one of the dominant forces in the developer universe. Rails developers are rather abundant, compared to Elixir ones, who are generally backlogged. Hence, Rails still has its’ advantages in certain situations where the immediate return on investment is not clear.

Applications with low user throughput: Internal/Intranet applications, heavy on forms and collecting routine data are best made with Ruby. Those types of applications are not trafficked enough and generally, in such cases, the cost benefit analysis to reduce latency does not exist.

Prototyping: Working with Ruby is like working with Legos. It is relatively easy to put together a functioning program in a brief time and with a limited budget, using existing modules rather than writing original code. However, scalability concerns should be addressed up front, avoiding rewrite or additional costs associated with Rails scaling (Rails scales, albeit at significantly greater cost than Elixir).

Sub-dividable systems: Before deciding to switch over, due to scaling issues, explore the possibility to subdivide. Either the group of applications, running on a single server, can be broken down into separate ones, or the single large application can be subdivided into separate instances: each one serving a group of users, based on predetermined characteristics.

Caching workaround available: Ruby can work with high traffic, mitigating scaling issues, if caching is an option. Blogs, news, and brochure web pages can use this option. Nevertheless, caching offers challenges when systems offer personalized user experiences.

Challenges

Number Crunching: Relative to other languages, Elixir-Phoenix does not offer the full computational capability as Java or Python. Those and amazingly FORTRAN are still the best at dealing with very large and complex calculations.

Databases: Coupled mostly with PostgreSQL, the language and framework require additional and advanced expertise to integrate with Oracle, especially legacy systems.

Resource Availability: Currently, one of the greatest challenges is talent availability. Functional Programming concepts in general are more difficult to grasp, requiring more critical thinking and prior experience, than object oriented ones. Elixir-Phoenix developers tend to be veterans with several years’ experience and expertise in another language, namely Ruby on Rails. Nevertheless, the shift from Ruby to Elixir is in motion and the language and framework are on its way to becoming mainstream.

Core Strengths

Elixir-Phoenix is the go to language for real-time systems with many simultaneous users. Chat and video apps have the most to gain, benefitting from the concurrency and efficient use of cloud based infrastructure. Moreover, in those situations, getting up and running is much faster than in Ruby or PHP. Although difficult to quantify, experienced coders often find they can code the same application faster in Elixir than in Ruby or PHP, making it ideal for prototyping.

Security

All complex software, available to the public, is vulnerable to attack. Nevertheless, the greatest threats originate during the development process, often stemming from the least experienced software engineer who is working on a new and unfamiliar system. That is why SQL injections still pose a formidable threat: developers often forget to validate and sanitize inputs. Hence, security concerns must be addressed as much by corporate culture, driving a detail orientation and cross checking, as implementing technical solutions.

SQL injection attacks against license plate scanners

Kevin McNamee, working at Casper, a New York based software development company, examined Elixir’s security aspects in detail. Specifically focusing on web sockets, (the main transport mechanism), he concluded that the connections must be secured as with any other API or browser endpoint. Otherwise, the system will be vulnerable to “man in the middle” attacks where data can be intercepted while in transit. Web sockets can be tested with standard penetration testing technologies, like “Burp Site.”

The Phoenix.Token module is an out-of-the-box solution, validating authentication. In essence, following industry standard procedures and best practice will help secure your Elixir-Phoenix application in accordance with industry standards. Additionally, the European Union is currently researching security tools: QuickCheck, ConCourer CutER, and Dialyzer.

Summation

Elixir-Phoenix is on the way to becoming mainstream, seeing early adoptions with major players like Pinterest, Discord, and Bleacher Report. Leveraging the established Erlang technology (1986), coupled with a familiar Ruby like syntax, it is becoming difficult for app developers to ignore. There is already a movement underway: senior Ruby developers opting to learn Elixir rather than take on another Ruby on Rails project.

However, Elixir is only six years old: very young compared to Java (2000), Ruby (1995) and Ruby on Rails (2005). The Phoenix framework has only been out for two years. Hence, maturing is still underway. Nevertheless, the community is working fast to build libraries and tools that improve the developer’s productivity. Under strong and well-organized leadership, the community is organizing more and more conferences and events to spread the word. Elixir-Phoenix is not for every situation but some experts predict that, by 2020, the language and framework will be mainstream and the go to technology for tackling concurrency, speed, and scaling issues.

References

Overview:

1. http://www.creativedeletion.com/2015/04/19/elixir_next_language.html

2. http://blog.carbonfive.com/2016/04/19/elixir-and-phoenix-the-future-of-web-apis-and-apps/

3. http://www.telegraph.co.uk/finance/newsbysector/mediatechnologyandtelecoms/digital-media/10650340/Facebook-buys-WhatsApp-Mark-Zuckerberg-explains-why.html

4. https://www.youtube.com/watch?v=c12cYAUTXXs

5. https://www.erlang-factory.com/upload/presentations/395/ErlangandFirst-PersonShooters.pdf

6. http://www.moreisdifferent.com/2015/07/16/why-physicsts-still-use-fortran/

7. https://www.sitepoint.com/an-interview-with-elixir-creator-jose-valim/

8. https://pragprog.com/book/phoenix/programming-phoenix

9. http://www.phoenixframework.org/docs/overview

10. http://www.phoenixframework.org/versions

11. https://pragprog.com/articles/erlang

12. https://www.amberbit.com/blog/2015/12/22/when-choose-elixir-over-ruby-for-2016-projects/

13. https://dockyard.com/blog/2015/10/29/how-long-it-took-our-team-to-move-from-rails-to-phoenix

14. http://www.trevordjones.com/2017/why-elixir-is-my-next-language-of-choice/

15. http://insights.workshop14.io/2016/04/18/why-i-cant-leave-ruby-for-elixir.html

16. https://medium.com/@kenmazaika/why-im-betting-on-elixir-7c8f847b58

17. https://yalantis.com/blog/new-programming-languages-swift-kotlin-and-elixir-what-developers-think-about-their-future/

18. https://pragprog.com/book/phoenix/programming-phoenix

19. http://www.phoenixframework.org/docs/overview

Case Studies

1. https://littlelines.com/blog/2014/07/08/elixir-vs-ruby-showdown-phoenix-vs-rails

2. http://www.akitaonrails.com/

3. http://www.techworld.com/apps-wearables/how-elixir-helped-bleacher-report-handle-8x-more-traffic-3653957/

4. https://venturebeat.com/2015/12/18/pinterest-elixir/

5. https://www.netguru.co/blog/10-companies-use-elixir

6. https://blog.emerleite.com/how-elixir-helped-us-to-scale-our-video-user-profile-service-for-the-olympics-dd7fbba1ad4e

7. https://blog.discordapp.com/scaling-elixir-f9b8e1e7c29b

Technology Comparison:

1. https://www.slant.co/versus/112/1540/~java_vs_elixir

2. https://hmans.io/posts/2017/05/24/elixir-phoenix-use-cases.html

3. https://www.amberbit.com/blog/2015/12/22/when-choose-elixir-over-ruby-for-2016-projects/#.WTmmAT550pc.mailto

4. https://robots.thoughtbot.com/elixir-for-rubyists

5. http://9elements.com/io/why-we-bet-on-elixir-and-phoenix/

6. https://hackernoon.com/elixir-the-new-wave-or-an-elegant-niche-5e38b4de0783

7. http://weblog.rubyonrails.org/2005/12/13/rails-1-0-party-like-its-one-oh-oh/

8. https://restack.io/blog/conversational-commerce-and-chatbots-overview/

9. http://codefol.io/posts/why-do-they-say-rails-doesnt-scale

Security:

1. https://www.reddit.com/r/elixir/comments/48ljs7/security_aspect_on_beam/

2. https://www.reddit.com/r/elixir/comments/4l1ho5/securing_elixir_applications_bram_verburg/

3. https://medium.com/casper-crafted/securing-websockets-in-elixir-770cbd2da043

Summation

1. http://blog.carbonfive.com/2016/04/19/elixir-and-phoenix-the-future-of-web-apis-and-apps/

2. https://medium.com/@kenmazaika/why-im-betting-on-elixir-7c8f847b58

3. https://hackernoon.com/elixir-the-new-wave-or-an-elegant-niche-5e38b4de0783

Acknowledgements:

1. The Elixir Community, especially:

a. Alisina Bahadori

b. Peer Reynders

c. Diana Olympos

2. Dimitri Roche — Software Engineer and Technology Writer in New York City

3. Zach Kessin — Finch Software in Beersheba, Israel

4. Emerson Macedo — Sr. Software Engineer at Globo.com

5. Dragos Musetescu –CEO and Senior Software Engineer at Restack(Romania)

6. Dima Don — CEO and Senior Software Engineer at Fotki