Phoenix for Rubyists - Rubyconf Brazil 2016

Post on 11-Feb-2017

128 views 0 download

Transcript of 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

@MichaelLNorth

My Perspective

@MichaelLNorth

@MichaelLNorth

OriginsChris McCorddockyard.com

@MichaelLNorth

Origins

@MichaelLNorth

Concurrency +

Rails

@MichaelLNorth

@MichaelLNorth

@MichaelLNorth

📱📱

📱📱

🗼

@MichaelLNorth

Ericsson AXE Switch (1976 - Present)

@MichaelLNorth

📱📱

📱📱

🗼

@MichaelLNorth

🖥📱

💻☁

@MichaelLNorth

🖥📱

💻☁ ☁

@MichaelLNorth

Concurrency📱📱

📱📱

🗼

@MichaelLNorth

Performance

RubyErlang

@MichaelLNorth

Fault Tolerance

@MichaelLNorth

Beautiful Syntax & Developer Ergonomics

@MichaelLNorth

Beautiful Syntax & Developer Ergonomics

@MichaelLNorth

@MichaelLNorth

@MichaelLNorth

TL;DR

@MichaelLNorth

TL;DR Functional

@MichaelLNorth

TL;DR Functional Immutable

@MichaelLNorth

TL;DR Functional Immutable

BEAM

@MichaelLNorth

TL;DR Functional Immutable

BEAM Extensible

@MichaelLNorth

Apps

@MichaelLNorth

S

S

W W W

Hierarchy of Apps

@MichaelLNorth

|>

Pipe Forward

@MichaelLNorth

|>

Pipe Forward

@MichaelLNorth

val |> func

Pipe Forward

func(val)

@MichaelLNorth

val |> func(b)

Pipe Forward

func(val, b)

@MichaelLNorth

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

Pipe Forward

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

@MichaelLNorth

Connection

@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

@MichaelLNorth

Phoenix, Abbreviated

new_conn = conn |> MyApp.handleRequest

@MichaelLNorth

@MichaelLNorth

Start your app

Start your app (w/ CLI)

Create your DB

@MichaelLNorth

RakeBundler MIX

An Elixir App (with Phoenix 1.2)

Beam files

An Elixir App (with Phoenix 1.2)

App configuration

An Elixir App (with Phoenix 1.2)

Dependency Source Code

An Elixir App (with Phoenix 1.2)

Application (non-web)

An Elixir App (with Phoenix 1.2)

Elixir Package Manifest++

An Elixir App (with Phoenix 1.2)

JS Dependency Source

An Elixir App (with Phoenix 1.2)

JS Package Manifest

An Elixir App (with Phoenix 1.2)

DB stuff, Static assets

An Elixir App (with Phoenix 1.2)

Guess what this is

An Elixir App (with Phoenix 1.2)

Application (web)

An Elixir App (with Phoenix 1.2)

98% of your time

An Elixir App (with Phoenix 1.2)

@MichaelLNorth

Start the server

HTTP://LOCALHOST:4000

@MichaelLNorth

What’s going on?URL

Pipeline Parameters Controller Action

@MichaelLNorth

Endpoint

@MichaelLNorth

Multiplexing Socket

@MichaelLNorth

Serve static assets

@MichaelLNorth

Request ID

@MichaelLNorth

Request Logging

@MichaelLNorth

Request body normalization

into JSON

@MichaelLNorth

AJAX DELETE/PATCH/PUT

@MichaelLNorth

AJAX HEAD

@MichaelLNorth

Session

@MichaelLNorthYour app’s router

@MichaelLNorth

Phoenix, Abbreviated

new_conn = conn |> Lots of plugs |> Router

@MichaelLNorth

Routing

@MichaelLNorth

pipeline(chain of plugs) Content-type

Use sessionNotificationsCSRFx-frame, etc…

@MichaelLNorth

Scope

@MichaelLNorth

ActionControllerPathVerb

@MichaelLNorth

Controllers

@MichaelLNorth

RENDER

•Can specify a view, but we didn’t

•Default behavior: name-matching

render(conn, view, template, assigns)

RENDER

•Can specify a view, but we didn’t

•Default behavior: name-matching

render(conn, template, assigns)

Implied: use view with the same name

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

@MichaelLNorth

Base Controller

@MichaelLNorth

Filters

@MichaelLNorth

View Layer

@MichaelLNorth

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

web/views/page_view.ex

@MichaelLNorth

@MichaelLNorth

Model Layer

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

Model Name

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

Table Name

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

Schema

model test

model

db migration

SCHEMA

CHANGESET STUFF

WEB/MODELS/USER.EX

@MichaelLNorth

Migrating

@MichaelLNorth

Migrating

• One-shot rewrites are expensive and dangerous

• You suffer, your company suffers, your users suffer

• Incremental change makes everyone happier

@MichaelLNorth

Reverse Proxy

Rails Phoenix

@MichaelLNorth

Reverse Proxy

Phoenix Rails

@MichaelLNorth

Terraformpoteto/terraform

@MichaelLNorth

Phoenix is the future

@MichaelLNorth

You have an advantage

Phoenix is the future

@MichaelLNorth

You have an advantage

Phoenix is the future

Learn it, try it, use it!

@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!

michael.l.north@gmail.com