Slide 1

Slide 1 text

Phoenix after 100,000 lines Renan Ranelli

Slide 2

Slide 2 text

whoami Renan Ranelli (also known as Milhouse) Senior Software Engineer @ (previously worked with Ruby & C# mainly)

Slide 3

Slide 3 text

whoami Renan Ranelli (also known as Milhouse) Senior Software Engineer @

Slide 4

Slide 4 text

Objectives ➔ Share my last 2 years experiences Working with Elixir in a "big" app ➔ Present & address concerns People have when considering Elixir for more "critical" projects ➔ Convince you it's great (& safe!) to use Elixir & Phoenix for big projects

Slide 5

Slide 5 text

First, a little context: What are we talking about?

Slide 6

Slide 6 text

Our context - Early stage startup (money was short) - B2B SaaS, "Enterprise application". We're not a "scalability" case. Sry. - Early stage ecosystem -- june 2015 - Elixir: 1.0.5 (1.5.1 today) - Phoenix: 0.14 (1.3.0 today) - Ecto: 0.13.1 (2.2.1 today) - No previous experience with Elixir in the "founding team"

Slide 7

Slide 7 text

Why we chose Elixir?!

Slide 8

Slide 8 text

Why we chose Elixir?! - Because it looks like Ruby? - No - Because it is super fast? - No - Because we needed to scale to a billion users overnight? - No… if we scaled to a million we would be rich - Because we were spending a lot of money on machines? - No. We didn't even have a product! - Because we understood the Erlang platform, weighted its pros and cons and found out that it was the best fit for our needs? - No. Definitely No.

Slide 9

Slide 9 text

Why we chose Elixir?! **Hireability**

Slide 10

Slide 10 text

Hireability We wanted a small but very effective & invested team. We then decided to use Elixir as a lever: "We are going to give you a great opportunity to work full time with Elixir & incredible people"

Slide 11

Slide 11 text

Some (common) concerns What are the risks of that choice?

Slide 12

Slide 12 text

Our fears concerns - Will we find libraries & other ecosystem related stuff? Will we need to build the world? - Will this whole thing turn into abandon-ware? - How productive is this framework? Should we be settling for something like Rails instead? - Will this be good for "complex" business logic? (which we do have lots) - Will this be stable in production? - (more particular to our case:) Will our hiring strategy work?

Slide 13

Slide 13 text

Our conclusion then: We won't know unless we try. Maybe in 2 years we'll be able to answer that

Slide 14

Slide 14 text

As expected, we had problems along the way.

Slide 15

Slide 15 text

Interacting with other databases - Interacting with "non-conventional" databases: In the beginning, we couldn't find good libraries to interact with Cassandra and ElasticSearch. - We ended up writing our own... - Today, we've got Xandra for Cassandra, but I don't know of any good alternative for ElasticSearch. Ping me if you do.

Slide 16

Slide 16 text

Authentication, Accounts, Users ... - At the time, we couldn't find anything ready for use… - We ended up writing our own... - Today, we've got a whole section in awesome elixir...

Slide 17

Slide 17 text

Massive Recompilations - With more than a thousand modules, we discovered that it is quite easy to get in a situation where a big chunk of the project is recompiled after changing just one file. - We suffered a lot, but got to understand the causes... - See http://milhouseonsoftware.com/2016/08/11/understanding-elixir-recompilation/ or my (unreleased) empex.co talk on this theme ~ demo ~

Slide 18

Slide 18 text

Timex many major updates - We started with Timex 0.15, and we're on 3.1.24; - We started before `Date`, `NaiveDateTime` and `DateTime` even existed. - That hurt. And we had **lots** of complex logic depending on time… and we also kind-of misused timezones... - Thank you core team for `{Naive,}DateTime.diff/3`

Slide 19

Slide 19 text

Dependency clash - Because Erlang lacked a hex.pm alternative for quite some time, some different libraries declare the same dependency name :/ - Unfortunately… there is no solution to this.

Slide 20

Slide 20 text

Deployment a lá "12 factor" - Deployment was a big unknown in the early days. - We had *lots* of trouble trying to mold releases into a "12 factor compliant" setup. Weird behaviours with environment variables... - We ended up running mix in production and we're doing exactly that until today. No problems since then :thumbs_up:

Slide 21

Slide 21 text

(and now some problems that were exclusively our fault)

Slide 22

Slide 22 text

Joining the "umbrella party" late - Our app started as a single phoenix app. - As the app grew large, we felt the need to split it into an umbrella application. - As you guessed, we weren't very well modularized. - Lots of pain to get this done. (It was our fault)

Slide 23

Slide 23 text

Fat Controllers - Is a terrible Idea. Don't do it. - See Chris' talk on Phoenix 1.3 ! https://www.youtube.com/watch?v=tMO28ar0lW8

Slide 24

Slide 24 text

Coarse testing - We started breaking down the fat controllers. - We got lazy and did not write much of unit tests as we were factoring out stuff from "fat controllers". Partially because things were too coupled, partially because of deadlines. - And that burned us. Bad. *Don't* ignore the testing pyramid. - In the beginning, everything was fine because the code in the controllers was concise and short. But that didn't last long.

Slide 25

Slide 25 text

Not using Ecto.Type - We reimplemented most of Ecto.Type functionality (very poorly) because we did not read the documentation thoroughly. - ~ code ~

Slide 26

Slide 26 text

Migration to a full SPA + GraphQL - We decided to reimplement the frontend as an SPA. Consuming a graphql api. - Rewriting was *not* a good idea. (it rarely is…) - **LOTS** of problems with React, ClojureScript, GraphQL, reinventing HTTP, yadda yadda. - IMHO that was our biggest mistake problem. It was not Phoenix or Elixir related at all. I will come back to this latter.

Slide 27

Slide 27 text

Incidental problems :s

Slide 28

Slide 28 text

But we also had awesome surprises!

Slide 29

Slide 29 text

Platform & operability! See https://www.youtube.com/watch?v=5SbWapbXhKo

Slide 30

Slide 30 text

Performance! (not only in production) See http://blog.plataformatec.com.br/2017/07/the-fallacies-of-web-application-performance/

Slide 31

Slide 31 text

Evolution! - Evolution of libraries, ecosystem, events and people interested. We started prior to phoenix & ecto 1.0; Both have come a *long* way. - Stability! Phoenix & Elixir we're beyond stable. We even forgot to add `Restart=on-failure` on systemd! - Even though the app got *really* big, it was much simpler to work with than {Rails,Spring} apps of similar size we worked with before

Slide 32

Slide 32 text

Contribution! - We landed a *lot* of patches in many popular libraries! (ecto, phoenix, erlcloud, plug, ja_serializer, timex, etc, etc) - We found a bug in the Elixir compiler! - We wrote some cool libraries! (like a stream-able zip encoder) - (and we also got some other stuff that we should be able to extract & open-source too)

Slide 33

Slide 33 text

Our hiring strategy... - It Worked! It really did! - We've got an awesome team of people (and growing!)

Slide 34

Slide 34 text

So, after 2 years, what about our initial concerns?

Slide 35

Slide 35 text

Our fears concerns - Will we find libraries & other ecosystem related stuff? Will we need to build the world? A lot before, a lot less today (always try not to!) - Will this become abandon-ware? Hell No! - How productive is this framework? Should I be settling for something like Rails instead? Phoenix is very productive! - Will this be good for "complex" business logic? Yep. No big issues - Will this be stable in production? As "stable" as "stable" can get. - (more particular to our case:) Will our hiring strategy work? It did.

Slide 36

Slide 36 text

Conclusion

Slide 37

Slide 37 text

Conclusion - Our biggest problems had nothing to do with Phoenix itself. - In 2015/2016 phoenix was enough to handle all our needs. Today it is even more so. Still lots of work to do, lots of opportunities to contribute. - Although Phoenix is new, it is *very well founded*. - The community *is* growing, the ecosystem *is* growing. Things are more and more *production ready & stable*.

Slide 38

Slide 38 text

If I were to build it all again, today, would I use Elixir & Phoenix? Hell YES!

Slide 39

Slide 39 text

Takeaway Phoenix *is* good for big "enterprise apps". The following estatement used to be very true: "you're trading maturity & productivity for performance". The amount of "maturity & productivity" we're trading is getting smaller and smaller. The future is bright. (and faster)

Slide 40

Slide 40 text

Obrigado!

Slide 41

Slide 41 text

Where to find me: Twitter: @renanranelli Github: /rranelli Blog: milhouseonsoftware.com