Phoenix for Rubyists - Rubyconf Brazil 2016

97
@MichaelLNorth Phoenix for Rubyists Rubyconf Brazil 2016 Mike North CTO, Levanto Financial image credit: http://phoenix-mask.deviantart.com/art/Ruby-Heart-s-Cutie-Mark-600784264

Transcript of Phoenix for Rubyists - Rubyconf Brazil 2016

Page 1: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Phoenix for Rubyists

Rubyconf Brazil 2016

Mike North CTO, Levanto Financial

image credit: http://phoenix-mask.deviantart.com/art/Ruby-Heart-s-Cutie-Mark-600784264

Page 2: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

My Perspective

Page 3: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Page 4: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

OriginsChris McCorddockyard.com

Page 5: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Origins

Page 6: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Concurrency +

Rails

Page 7: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Page 8: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Page 9: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

📱📱

📱📱

🗼

Page 10: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Ericsson AXE Switch (1976 - Present)

Page 11: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

📱📱

📱📱

🗼

Page 12: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

🖥📱

💻☁

Page 13: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

🖥📱

💻☁ ☁

Page 14: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Concurrency📱📱

📱📱

🗼

Page 15: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Performance

RubyErlang

Page 16: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Fault Tolerance

Page 17: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Beautiful Syntax & Developer Ergonomics

Page 18: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Beautiful Syntax & Developer Ergonomics

Page 19: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Page 20: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Page 21: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

TL;DR

Page 22: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

TL;DR Functional

Page 23: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

TL;DR Functional Immutable

Page 24: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

TL;DR Functional Immutable

BEAM

Page 25: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

TL;DR Functional Immutable

BEAM Extensible

Page 26: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Apps

Page 27: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

S

S

W W W

Hierarchy of Apps

Page 28: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

|>

Pipe Forward

Page 29: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

|>

Pipe Forward

Page 30: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

val |> func

Pipe Forward

func(val)

Page 31: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

val |> func(b)

Pipe Forward

func(val, b)

Page 32: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

val |> func(b) |> other(c) |> more(d)

Pipe Forward

more(other(func(val, b), c), d)

Page 33: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Connection

Page 34: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

conn

Request Body Request Params Request Headers Request Origin

Response Body Response Status Code

Response Headers

new_conn

Request Body Request Params Request Headers Request Origin

Response Body Response Status Code

Response Headers

Page 35: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Phoenix, Abbreviated

new_conn = conn |> MyApp.handleRequest

Page 36: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Page 37: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Start your app

Start your app (w/ CLI)

Create your DB

Page 38: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

RakeBundler MIX

Page 39: Phoenix for Rubyists - Rubyconf Brazil 2016

An Elixir App (with Phoenix 1.2)

Page 40: Phoenix for Rubyists - Rubyconf Brazil 2016

Beam files

An Elixir App (with Phoenix 1.2)

Page 41: Phoenix for Rubyists - Rubyconf Brazil 2016

App configuration

An Elixir App (with Phoenix 1.2)

Page 42: Phoenix for Rubyists - Rubyconf Brazil 2016

Dependency Source Code

An Elixir App (with Phoenix 1.2)

Page 43: Phoenix for Rubyists - Rubyconf Brazil 2016

Application (non-web)

An Elixir App (with Phoenix 1.2)

Page 44: Phoenix for Rubyists - Rubyconf Brazil 2016

Elixir Package Manifest++

An Elixir App (with Phoenix 1.2)

Page 45: Phoenix for Rubyists - Rubyconf Brazil 2016

JS Dependency Source

An Elixir App (with Phoenix 1.2)

Page 46: Phoenix for Rubyists - Rubyconf Brazil 2016

JS Package Manifest

An Elixir App (with Phoenix 1.2)

Page 47: Phoenix for Rubyists - Rubyconf Brazil 2016

DB stuff, Static assets

An Elixir App (with Phoenix 1.2)

Page 48: Phoenix for Rubyists - Rubyconf Brazil 2016

Guess what this is

An Elixir App (with Phoenix 1.2)

Page 49: Phoenix for Rubyists - Rubyconf Brazil 2016

Application (web)

An Elixir App (with Phoenix 1.2)

Page 50: Phoenix for Rubyists - Rubyconf Brazil 2016

98% of your time

An Elixir App (with Phoenix 1.2)

Page 51: Phoenix for Rubyists - Rubyconf Brazil 2016
Page 52: Phoenix for Rubyists - Rubyconf Brazil 2016
Page 53: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Start the server

Page 54: Phoenix for Rubyists - Rubyconf Brazil 2016

HTTP://LOCALHOST:4000

Page 55: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Page 56: Phoenix for Rubyists - Rubyconf Brazil 2016

What’s going on?URL

Pipeline Parameters Controller Action

Page 57: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Endpoint

Page 58: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Multiplexing Socket

Page 59: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Serve static assets

Page 60: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Request ID

Page 61: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Request Logging

Page 62: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Request body normalization

into JSON

Page 63: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

AJAX DELETE/PATCH/PUT

Page 64: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

AJAX HEAD

Page 65: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Session

Page 66: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorthYour app’s router

Page 67: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Phoenix, Abbreviated

new_conn = conn |> Lots of plugs |> Router

Page 68: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Routing

Page 69: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

pipeline(chain of plugs) Content-type

Use sessionNotificationsCSRFx-frame, etc…

Page 70: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Scope

Page 71: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

ActionControllerPathVerb

Page 72: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Controllers

Page 73: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Page 74: Phoenix for Rubyists - Rubyconf Brazil 2016

RENDER

•Can specify a view, but we didn’t

•Default behavior: name-matching

render(conn, view, template, assigns)

Page 75: Phoenix for Rubyists - Rubyconf Brazil 2016

RENDER

•Can specify a view, but we didn’t

•Default behavior: name-matching

render(conn, template, assigns)

Implied: use view with the same name

Page 76: Phoenix for Rubyists - Rubyconf Brazil 2016

RENDER

•Can specify a view, but we didn’t

•Default behavior: name-matching

render(conn, template_or_assigns)

Implied: use view with the same name

Page 77: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Base Controller

Page 78: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Filters

Page 79: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

View Layer

Page 80: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

web/controllers/page_controller.ex web/templates/page/index.html.eex

web/views/page_view.ex

Page 81: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Page 82: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Model Layer

Page 83: Phoenix for Rubyists - Rubyconf Brazil 2016

mix phoenix.gen.model User \ users \ name:string \ username:string \ password_hash:string

Model Name

Page 84: Phoenix for Rubyists - Rubyconf Brazil 2016

mix phoenix.gen.model User \ users \ name:string \ username:string \ password_hash:string

Table Name

Page 85: Phoenix for Rubyists - Rubyconf Brazil 2016

mix phoenix.gen.model User \ users \ name:string \ username:string \ password_hash:string

Schema

Page 86: Phoenix for Rubyists - Rubyconf Brazil 2016

model test

model

db migration

Page 87: Phoenix for Rubyists - Rubyconf Brazil 2016

SCHEMA

CHANGESET STUFF

WEB/MODELS/USER.EX

Page 88: Phoenix for Rubyists - Rubyconf Brazil 2016
Page 89: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Migrating

Page 90: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Migrating

• One-shot rewrites are expensive and dangerous

• You suffer, your company suffers, your users suffer

• Incremental change makes everyone happier

Page 91: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Reverse Proxy

Rails Phoenix

Page 92: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Reverse Proxy

Phoenix Rails

Page 93: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Terraformpoteto/terraform

Page 94: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

Phoenix is the future

Page 95: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

You have an advantage

Phoenix is the future

Page 96: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

You have an advantage

Phoenix is the future

Learn it, try it, use it!

Page 97: Phoenix for Rubyists - Rubyconf Brazil 2016

@MichaelLNorth

•https://www.toptal.com/erlang/a-cloud-at-the-lowest-level-built-in-erlang •https://en.wikipedia.org/wiki/Moore%27s_law •https://theerlangelist.blogspot.in/2013/05/working-with-immutable-data.html •https://www.amberbit.com/blog/2014/2/14/putting-ruby-on-rails-on-a-diet/ •https://www.technologyreview.com/s/601441/moores-law-is-dead-now-what/

IMAGE & DIAGRAM CREDITS

Thanks!

I’m available for elixir training & consulting!

[email protected]