Slide 1

Slide 1 text

Who wants to go and build a system in Elixir?

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Can't go out and rewrite it all

Slide 6

Slide 6 text

You shouldn’t

Slide 7

Slide 7 text

Elixir, your Monolith and You (alpha-1) Tobias Pfeiffer @PragTob pragtob.info

Slide 8

Slide 8 text

Your Monolith and You

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

Your Monolith now?

Slide 11

Slide 11 text

Your Monolith?

Slide 12

Slide 12 text

Tear it all down and rewrite it

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Sooooon!

Slide 15

Slide 15 text

“We rewrote it all in Language x, now it’s 10 times faster and only 50% of the code!” Someone

Slide 16

Slide 16 text

“Language x, is 10 times faster and requires 50% of the code of language Y!” Someone Often implies...

Slide 17

Slide 17 text

What nobody tells you...

Slide 18

Slide 18 text

Business Value?

Slide 19

Slide 19 text

Sooooon!

Slide 20

Slide 20 text

Replace it step by step

Slide 21

Slide 21 text

We have a bedroom, for the bathroom please check out legacy!

Slide 22

Slide 22 text

Terraform allows you to incrementally transform an older API into one powered by Phoenix - one endpoint at a time. poteto/terraform

Slide 23

Slide 23 text

defmodule MyApp.Terraformers.Foo do alias MyApp.Clients.Foo use Plug.Router plug :match plug :dispatch get "/v1/hello-world", do: send_resp(conn, 200, "Hi") get _ do res = Foo.get!(conn) send_response({:ok, conn, res}) end end poteto/terraform

Slide 24

Slide 24 text

Replace a critical component

Slide 25

Slide 25 text

Check out our sweet new heating system!

Slide 26

Slide 26 text

Write a new component

Slide 27

Slide 27 text

Check it out we built a brand new high tech entertainment facility!

Slide 28

Slide 28 text

Write a new component Obvious in microservices

Slide 29

Slide 29 text

“Is the technology I’m choosing the right fit for the problem I’m trying to solve?” Everyone, hopefully

Slide 30

Slide 30 text

Reasonably separate and limited problem

Slide 31

Slide 31 text

Requirement that poses a problem for the current stack

Slide 32

Slide 32 text

Spark of Enthusiasm

Slide 33

Slide 33 text

Courier Tracking

Slide 34

Slide 34 text

Courier Tracking

Slide 35

Slide 35 text

Courier Tracking

Slide 36

Slide 36 text

Courier Tracking Websockets

Slide 37

Slide 37 text

Courier Tracking Websockets Basic Knowledge

Slide 38

Slide 38 text

How to make them talk?

Slide 39

Slide 39 text

Monolith Frontend Courier DB

Slide 40

Slide 40 text

Monolith Tracking Frontend Courier DB DB

Slide 41

Slide 41 text

Connect them?

Slide 42

Slide 42 text

Monolith Tracking Frontend Courier DB DB

Slide 43

Slide 43 text

JSON Web Token

Slide 44

Slide 44 text

Header Payload Signature

Slide 45

Slide 45 text

{ "role": "admin", "courier_ids": [1337, 55], "id": 42, "exp": 1520469475 }

Slide 46

Slide 46 text

Monolith Tracking Frontend Courier DB DB Shared Secret

Slide 47

Slide 47 text

Monolith Tracking Frontend Courier DB DB JWT JWT Shared Secret

Slide 48

Slide 48 text

Monolith Tracking Frontend Courier DB DB JWT JWT JWT Shared Secret JWT

Slide 49

Slide 49 text

def connect(%{"token" => token}, socket) do token |> JWT.verify_token |> respond_based_on_token_contents(socket) end Socket

Slide 50

Slide 50 text

defp login_user(%{"role" => role, ...}, socket) do {:ok, assign(socket, :user, %{role: role, ...})} end Socket

Slide 51

Slide 51 text

def join("courier:" <> courier_id, _, % {assigns: %{user: user}}) do if authorized?(courier_id, user) do # login else # unauthorizd end end Channel

Slide 52

Slide 52 text

defp authorized?("", _), do: false defp authorized?(courier_id, %{courier_ids: ids}) do Enum.member?(ids, String.to_integer(courier_id)) end defp authorized?(_, _), do: false Channel

Slide 53

Slide 53 text

Monolith Tracking Frontend Courier DB DB Locations Locations Most of the time

Slide 54

Slide 54 text

Fulfillment

Slide 55

Slide 55 text

Fulfillment CRUD

Slide 56

Slide 56 text

Fulfillment CRUD Experience

Slide 57

Slide 57 text

Monolith Fulfillment DB DB

Slide 58

Slide 58 text

Monolith Fulfillment DB DB Own UI

Slide 59

Slide 59 text

Monolith Fulfillment DB DB OAuth OAuth

Slide 60

Slide 60 text

Monolith Fulfillment DB DB /current_user Who?

Slide 61

Slide 61 text

Monolith Fulfillment DB DB Products

Slide 62

Slide 62 text

Monolith Fulfillment DB DB Order Valid? Order

Slide 63

Slide 63 text

Monolith Fulfillment DB DB Packaging Create

Slide 64

Slide 64 text

Rail-way oriented programming!

Slide 65

Slide 65 text

Railway Oriented Programming

Slide 66

Slide 66 text

defmodule Fulfillment.OrderCreation do def create(params, customer, auth) do with {:ok, order} <- validate_order(params, customer), {:ok, order} <- validate_in_backend(order, auth), {:ok, order} <- Repo.insert(order) do {:ok, order} else {:error, changeset} -> {:error, changeset} end end end

Slide 67

Slide 67 text

defmodule Fulfillment.OrderCreation do def create(params, customer, auth) do with {:ok, order} <- validate_order(params, customer), {:ok, order} <- validate_in_backend(order, auth), {:ok, order} <- Repo.insert(order) do {:ok, order} else {:error, changeset} -> {:error, changeset} end end end Validate internally

Slide 68

Slide 68 text

defmodule Fulfillment.OrderCreation do def create(params, customer, auth) do with {:ok, order} <- validate_order(params, customer), {:ok, order} <- validate_in_backend(order, auth), {:ok, order} <- Repo.insert(order) do {:ok, order} else {:error, changeset} -> {:error, changeset} end end end Validate externally

Slide 69

Slide 69 text

defmodule Fulfillment.OrderCreation do def create(params, customer, auth) do with {:ok, order} <- validate_order(params, customer), {:ok, order} <- validate_in_backend(order, auth), {:ok, order} <- Repo.insert(order) do {:ok, order} else {:error, changeset} -> {:error, changeset} end end end Save

Slide 70

Slide 70 text

defmodule Fulfillment.OrderCreation do def create(params, customer, auth) do with {:ok, order} <- validate_order(params, customer), {:ok, order} <- validate_in_backend(order, auth), {:ok, order} <- Repo.insert(order) do {:ok, order} else {:error, changeset} -> {:error, changeset} end end end Done

Slide 71

Slide 71 text

defmodule Fulfillment.OrderCreation do def create(params, customer, auth) do with {:ok, order} <- validate_order(params, customer), {:ok, order} <- validate_in_backend(order, auth), {:ok, order} <- Repo.insert(order) do {:ok, order} else {:error, changeset} -> {:error, changeset} end end end Error

Slide 72

Slide 72 text

No Kafka/Message Queue?

Slide 73

Slide 73 text

Be careful with new technologies!

Slide 74

Slide 74 text

Microservices!

Slide 75

Slide 75 text

Microservices! ”Macroapplications”

Slide 76

Slide 76 text

All challenges are clearly technical

Slide 77

Slide 77 text

All challenges are clearly technical

Slide 78

Slide 78 text

Stakeholders

Slide 79

Slide 79 text

Your team

Slide 80

Slide 80 text

First Major Version

Slide 81

Slide 81 text

Get the others on board

Slide 82

Slide 82 text

Workshops

Slide 83

Slide 83 text

To know it, you got to build it

Slide 84

Slide 84 text

No content

Slide 85

Slide 85 text

Pair Adopter with Alchemist

Slide 86

Slide 86 text

Pair Adopter with Alchemist Alchemist doesn’t touch keyboard

Slide 87

Slide 87 text

Knowledge

Slide 88

Slide 88 text

Knowledge

Slide 89

Slide 89 text

“We are still using this like Rails – we should use GenServers!” Someone on your team

Slide 90

Slide 90 text

You don’t need to kill your Monolith, Complement it

Slide 91

Slide 91 text

Your Apps

Slide 92

Slide 92 text

Enjoy using Elixir effectively to help your company Tobias Pfeiffer @PragTob pragtob.info