Flirting with Elixir

Fellow Localytics engineer, Michael Macasek, and I just got back from ElixirConf and we are pumped. The things people are doing with Elixir are incredible.

We heard talks on distributed computing, self-healing architectures, embedded systems, and web development. The last time I saw this much enthusiasm for new tech was back when the Ruby & Rails rocket was preparing to launch.

"I loved what I saw, but hated what I didn't see." – Jose Valim

We'd both been dabbling in Elixir before the conference, and after meeting the community, we knew Elixir was about to take off.

So what exactly is Elixir?

It's a programming language that runs on the Erlang virtual machine. Elixir's creator, Jose Valim, famously said that when he looked at Erlang, "I loved what I saw, but hated what I didn't see." So he built a language that has all Erlang's strengths, plus more—macros, a nicer syntax, and a mature toolchain. Elixir is Erlang with more strengths and fewer weaknesses.

Erlang (pictured below) is language that's been around since 1986 and open-sourced in 1998. It's known for powering telecommunications systems that have achieved nine nines of uptime—that’s not a typo.

![](/content/images/2015/10/erlang-gedit.png)

So is Erlang only for telco stuff?

Nope! Erlang was built to create systems that are fast, responsive, and reliable. It’s well-suited for messaging systems, high velocity/volume big-data systems, web applications, etc. For example, Phoenix is a web framework for Elixir that is gaining serious traction. It's being touted as the next-generation replacement for Rails, complete with an elegant ORM called ecto. It supports WebSockets out of the box and was measured to be 15x faster than Rails.

In the same way that JavaScript has evolved beyond its web-browser roots, Elixir has built on top of Erlang to evolve in a similar way.

OK, so what's the downside?

Elixir isn’t magic. There are a few reasons it may not be the right tech for your use case:

  • Not as fast as C or Java at cpu-intensive workloads
  • You probably don’t want to write your desktop app’s GUI in Elixir
  • The community of third-party libs is still small (but it’s growing!)
  • It’s relatively new, so hiring for “Elixir programmers” may be difficult

What do engineers like about Elixir?

Elixir is a pleasure to use. It's functional, which makes testing, debugging, and concurrency easier. It has expressive, Ruby-like syntax, complete with the magical pipeline operator |> that reinforces the "pipeline of data" paradigm.

It's also got a polished suite of language tools:

  • mix—a versatile build tool
  • iex—a super-powered repl that shows you documentation, loads your code, reloads your code, and autocompletes both Elixir and Erlang functions
  • ExUnit—a test builtin test framework
  • EEx—a templating library
  • Exrm—a lib that allows you to trivially version and build your production release

Docs are a first-class citizen of the Elixir ecosystem, brought to you by ExDoc. If you've clicked any of the links above, you've noticed the beautiful and thorough documentation. Diving into the Elixir ecosystem is like unboxing something from Apple.

What does Localytics like about Elixir?

We process about three billion data points a day, so our backend systems must be high-throughput, fault-tolerant, and always responsive. That's Erlang's bread-and-butter. The secret sauce to highly-available, distributed systems is the Open Telecom Platform. OTP is a library of abstractions that makes building such systems straightforward. Elixir wraps OTP and interops with the rest of the Erlang ecosystem with zero overhead. Elixir gives us all of Erlang's battle-tested libraries, abstractions for writing concurrent code, and experience running in production.

We run several high-traffic Rails apps that require all the bells-and-whistles of any respectable production code. This includes background jobs, caches, multiple application servers, monitoring systems, etc. Elixir allows us to replace each piece of infrastructure with a single technology in a single repo using the Elixir concept of an "umbrella project". Since we're dealing with a single technology, it’s easier to debug and less code to manage. OTP makes it trivial to write code that not only alerts us when things go wrong, but restarts things from the last known good state.

Elixir is also compatible with Erlang's mind-blowing observer tool, which allows detailed remote debugging wrapped in a GUI. If you're a dev who has ever had to jump through hoops to see what your app is doing, :observer.start will change your world. There are also considerable performance gains. Phoenix is a lot faster than Rails, which means we can use cheaper hardware to support equivalent traffic.

What's next?

It’s still early in our exploration of Elixir at Localytics, but the language has gone viral among our developers. We’re considering breaking up our monolithic backend into services and using channels in our web dashboard for real-time data feeds. As we ramp up, we're looking forward to watching and contributing to the budding Elixir community. If you're inclined, below are a few Elixir resources that should help you get started: