Slide 1

Slide 1 text

Individualised Content at Web-scale How Elixir and Phoenix helped us deliver individualised content to millions of users per month.

Slide 2

Slide 2 text

Michael Schaefermeyer • ❤ Elixir, Ruby • Senior Software Engineer at Bleacher Report (until last month) • Co-Founder, Software Engineer at Full Stack Media (since last month) mschae mschae

Slide 3

Slide 3 text

Disclaimers 1. This talk may contain traces of ruby 2. Not everything you are about to hear about is live yet 3. This talk is “full stack” - not very technical - I won’t show much code

Slide 4

Slide 4 text

The product

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

• Merged stream of tweets, instagrams and articles • Desktop and native mobile apps • Streams for leagues, teams, division, … • In the mobile apps: User can subscribe to teams, leagues, players, etc.

Slide 7

Slide 7 text

• Merged stream of tweets, instagrams and articles • Desktop and native mobile apps • Streams for leagues, teams, division, … • In the mobile apps: User can subscribe to teams, leagues, players, etc.

Slide 8

Slide 8 text

Status quo • Lots of requests • Two monoliths (UI, API), multiple services • Ruby on Rails, node.js • Persistence layer consists of relational databases (MySQL, PostgreSQL) • Caches, caches everywhere (Memcached and Redis)

Slide 9

Slide 9 text

Why Elixir? What about caching?

Slide 10

Slide 10 text

–Phil Karlton “There are two hard things in Computer Science: cache invalidation and naming things.”

Slide 11

Slide 11 text

“Brochure benefits” of Elixir • Scalability • Fault-tolerance • Functional • Meta-programming

Slide 12

Slide 12 text

“Brochure benefits” of Elixir Source: flick.com / Lisa Yarost Not very specific

Slide 13

Slide 13 text

Benefits of Elixir for our app • We are manipulating lists ➡ Functional Programming + (Linked) Lists = ❤ • We are merging multiple lists ➡ Fetch and build multiple lists in parallel • We have an extremely high dispersion (no two lists are the same) ➡ No reasonable caching possible • We potentially want to re-order list based on additional data ➡ “Just-in-time” list creation necessary

Slide 14

Slide 14 text

Sequencial approach

Slide 15

Slide 15 text

Parallel approach Extremely easy to implement thanks to Ecto’s Repo- based approach

Slide 16

Slide 16 text

Ecto’s Repo-based approach

Slide 17

Slide 17 text

Hurdles Source: flick.com / Robert Voors

Slide 18

Slide 18 text

“Immaturity” of Elixir • Elixir has been stable for ~ 6 months • Few SaaS integrations (e.g. error tracking, …) • Not “proven” like ruby, node • No official Docker image • …

Slide 19

Slide 19 text

Small ecosystem • Ruby = great ecosystem • We don’t want to replicate existing functionality • Fear of “having to build it all yourself” • Fear of “having to solve the complex problems” Source: githut.info

Slide 20

Slide 20 text

Training developers • We are a Ruby shop = lack of functional programming experience • Recruiters: “We are hiring Elixir developers with at least 5 years of experience” • San Francisco is one hell of a market Source: hbo.com

Slide 21

Slide 21 text

Monitoring • Crucial to keep track of the app’s health • No New Relic, no Skylight • No insights = flying blind • No metrics = hard to debug Source: newrelic.com

Slide 22

Slide 22 text

Solutions Source: flickr.com / Shaun Fisher

Slide 23

Slide 23 text

“Immaturity” of Elixir • Surprisingly mature tooling (mix, ExUnit, hex.pm, ExDoc, …) • Erlang has been proven! The language is as old as I am. • People have been using it in production for about a year now • Very extendable architecture (Plugs, Ecto datatypes, …) • Extremely smart people working on it

Slide 24

Slide 24 text

Small ecosystem • Lots of Erlang packages to choose from • Great web framework with Phoenix, great ORM with Ecto • Great packages already exist • HTTPoison, Poison, ExVCR and many more • Fewer engineers but extremely smart people • Super helpful community

Slide 25

Slide 25 text

Small ecosystem (cont.) • It’s very straightforward to add missing pieces: • Plug for “trailing formats”:

Slide 26

Slide 26 text

Training new developers • Findings: • Similarity to ruby lowers perceived entry barrier • Excellent online resources available (elixir-lang.org, Elixir Sips, Dave Thomas’ book, …) • Languages like Elixir are a big plus for applicants! • Measures: • Live coding sessions • Start with easy tickets

Slide 27

Slide 27 text

Lack of monitoring • Surprisingly simple to build your own monitoring • Use Exometer (and don’t forget to thank @bltroutwine) • Use StatsD (integrates with great SaaS tools like Datadog, Librato, etc.) • Integrate BEAM statistics (run queue, garbage collection, memory sizes, …) • Integrate server statistics (CPU usage, load, memory, available disk space, …)

Slide 28

Slide 28 text

Lack of monitoring (cont.) • Stats I’m interested in: • DB queries per minute, execution times • Web requests per minute, response times • Health of the VM (memory stats, GC stats, …)

Slide 29

Slide 29 text

Lack of monitoring (cont.)

Slide 30

Slide 30 text

Ongoing challenges • Keeping everything up-to-date (lots of packages < 1.0) - has gotten a lot easier thanks to mix hex.outdated • Recruiting more people to join the Elixir express • Richer SaaS-ecosystem needed • Ops challenges (file descriptors, nginx config, …)

Slide 31

Slide 31 text

Gotchas • Nginx config (options like worker_processes, worker_rlimit_nofile, …) • Watch your file descriptors • Watch your log files • Don’t convert user input to Atom (use existing_atom) • Use OTP whenever possible • Beware of Erlang’s binary data collection

Slide 32

Slide 32 text

Results • Performance: • Complex lists and multiple DB accesses ~ 50ms • Simple list: ~ 30ms • Quality: Very high test coverage, very maintainable code • Robustness: No runtime errors, no beam errors • Elixir perfect language for web applications ➡ Allowed us to build the product fast, secure and reliable

Slide 33

Slide 33 text

Epilogue • I’m not very smart • I had the chance to get engaged in a super vibrant community very quickly • Use the abundance of help: • #elixir-lang • Mailing lists on Google Groups (Elixir, Ecto, Phoenix) • Best-in-class documentation and resources