Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

functional

Slide 3

Slide 3 text

functional ErlangVM

Slide 4

Slide 4 text

functional ErlangVM Parallelism

Slide 5

Slide 5 text

Who wants to go and build a system in Elixir?

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

You shouldn’t

Slide 11

Slide 11 text

Elixir, Your Monolith and You Tobias Pfeiffer @PragTob pragtob.info

Slide 12

Slide 12 text

Your Monolith and You

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

Your Monolith now?

Slide 15

Slide 15 text

Your Monolith?

Slide 16

Slide 16 text

Tear it all down and rewrite it

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Sooooon!

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

What nobody tells you...

Slide 22

Slide 22 text

Business Value?

Slide 23

Slide 23 text

Sooooon!

Slide 24

Slide 24 text

Replace it step by step

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 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 29

Slide 29 text

Replace a critical component

Slide 30

Slide 30 text

Damn our heater always breaks down when it’s cold!

Slide 31

Slide 31 text

Check out our sweet new heating system!

Slide 32

Slide 32 text

Write a new component

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

Write a new component Obvious in microservices

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

Reasonably separate and limited problem

Slide 37

Slide 37 text

Requirement that poses a problem for the current stack

Slide 38

Slide 38 text

Spark of Enthusiasm

Slide 39

Slide 39 text

Courier Tracking

Slide 40

Slide 40 text

Courier Tracking

Slide 41

Slide 41 text

Courier Tracking

Slide 42

Slide 42 text

Courier Tracking Websockets

Slide 43

Slide 43 text

Courier Tracking Websockets Basic Knowledge

Slide 44

Slide 44 text

How to make them talk?

Slide 45

Slide 45 text

Monolith Frontend Courier DB

Slide 46

Slide 46 text

Monolith Tracking Frontend Courier DB DB

Slide 47

Slide 47 text

Connect them?

Slide 48

Slide 48 text

Monolith Tracking Frontend Courier DB DB

Slide 49

Slide 49 text

JSON Web Token

Slide 50

Slide 50 text

Header Payload Signature

Slide 51

Slide 51 text

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

Slide 52

Slide 52 text

Monolith Tracking Frontend Courier DB DB Shared Secret

Slide 53

Slide 53 text

Monolith Tracking Frontend Courier DB DB JWT JWT Shared Secret

Slide 54

Slide 54 text

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

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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

Slide 60

Slide 60 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 61

Slide 61 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 62

Slide 62 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 63

Slide 63 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 64

Slide 64 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 65

Slide 65 text

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

Slide 66

Slide 66 text

Monolith Tracking Frontend Courier DB DB Locations Locations Websocket

Slide 67

Slide 67 text

Monolith Tracking Frontend Courier DB DB Locations Locations HTTP REST

Slide 68

Slide 68 text

Fulfillment

Slide 69

Slide 69 text

Fulfillment CRUD

Slide 70

Slide 70 text

Fulfillment CRUD Experience

Slide 71

Slide 71 text

Monolith Fulfillment DB DB

Slide 72

Slide 72 text

Monolith Fulfillment DB DB Own UI

Slide 73

Slide 73 text

Monolith Fulfillment DB DB OAuth OAuth

Slide 74

Slide 74 text

Monolith Fulfillment DB DB /current_user Who?

Slide 75

Slide 75 text

Monolith Fulfillment DB DB Products

Slide 76

Slide 76 text

Monolith Fulfillment DB DB Order Valid? Order

Slide 77

Slide 77 text

Monolith Fulfillment DB DB Packaging Create

Slide 78

Slide 78 text

Monolith Fulfillment DB DB HTTP REST Create

Slide 79

Slide 79 text

Railway Oriented Programming

Slide 80

Slide 80 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 81

Slide 81 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 “Success” Rail

Slide 82

Slide 82 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” Rail

Slide 83

Slide 83 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 84

Slide 84 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 85

Slide 85 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 86

Slide 86 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 87

Slide 87 text

No Kafka/ Message Queue/ GraphQL?

Slide 88

Slide 88 text

Be careful with new technologies!

Slide 89

Slide 89 text

Microservices!

Slide 90

Slide 90 text

Microservices! ”Macroapplications”

Slide 91

Slide 91 text

All challenges are clearly technical

Slide 92

Slide 92 text

All challenges are clearly technical

Slide 93

Slide 93 text

Stakeholders

Slide 94

Slide 94 text

Your team

Slide 95

Slide 95 text

First Major Version

Slide 96

Slide 96 text

Get the others on board

Slide 97

Slide 97 text

Workshops

Slide 98

Slide 98 text

To know it, you got to build it

Slide 99

Slide 99 text

No content

Slide 100

Slide 100 text

Pair Adopter with Alchemist

Slide 101

Slide 101 text

Pair Adopter with Alchemist Alchemist doesn’t touch keyboard

Slide 102

Slide 102 text

Knowledge

Slide 103

Slide 103 text

Knowledge

Slide 104

Slide 104 text

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

Slide 105

Slide 105 text

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

Slide 106

Slide 106 text

Your Apps

Slide 107

Slide 107 text

Enjoy Using Elixir effectively to Help Your Company Tobias Pfeiffer @PragTob pragtob.info