Why Elixir works magic?

(and Ruby does in limited amounts ;))

Hubert Łępicki

2015-10-17

  • Hubert Łępicki
  • @hubertlepicki
  • @amberbit

I work with web apps

Web apps suck

Why?

JavaScript

Server-side

Why making it work is hard?

  1. shared mutable data
  2. no built-in crash recovery mechanisms
  3. GC is hard
  4. threading is hard
  5. preempting is hard
  6. monitoring is hard

if only was there better VM

taking care of all those issues...

Let's discuss memory allocation

Stack

  • LIFO structure
  • each function called adds stuff on top
  • each function finished removes stuff from top
  • VMs handle 1 stack per thread

Heap

  • shared memory between all threads
  • classes and types metadata
  • dynamically allocated memory

Heap of problems

  • global state needs synchronization
  • slow access by different CPUs/cores
  • single point of failure
  • GC is a rocket science

Entirely different VM

There is no shared heap

There is no problem synchronizing access to one

Elixir

Writing supervised code

Hardware failure

OTP app cluster

  • connect N nodes via (fast) web
  • concurrency / message passing just works
  • minimal changes to your code
  • yay, you wrote distributed app by accident
  • production-ready (remember dRB?)
  • failover
  • load balancing
  • sleep well

Zero-downtime deployments

  • elixir/erlang allows code hot-swapping
  • your app is modular
  • replace individual parts of system (applications)
  • do not miss a single message
  • do not loose a single HTTP request 

Less infrastructure is more

Ruby on Rails

  • [web] unicorn/puma + nginx/apache
  • [worker] resque
  • [scheduled tasks] cron + rake
  • [websockets] faye/pusher

Elixir

[web] elixir

[worker] elixir

[scheduled tasks] elixir

[websockets] elixir

Application server

- bloat
+ speed

http://elixir-lang.org

Thank you!

@hubertlepicki

Why Elixir works magic?

By Hubert Łępicki

Why Elixir works magic?

  • 1,731