Using Elixir and Phoenix for a new project - any tips?

Hello,

I am currently using elixir for a side project, I plan to kick off a significantly large project (2-3 Devs / 6 months) Phoenix and Elixir fit the use case without a doubt. The only thing holding me back is the lack of experience I have with running elixir in production, I am not sure if the learning curve for Elxir/Phoenix will be an issue for onboarding other developers etc

Has anyone done something significantly large who started using Phoenix/Elixir from a non Ruby background ( I mainly use PHP) as a first project. Any challenges faced, and questions that you wish you knew the answers to before you started would really help.

Thanks,

Gayan

2 Likes

My team have been redeveloping a group of related apps which rely heavily on websockets and a lot of state in Elixir. Originally they were developed in Golang. We definitely like Golang for its simplicity and performance. But we feel more confident now when we rearchitected the solution using Elixir (GenServer, GenStage), Phoenix (REST, WebSockets). Also, we were able to put part of the solution in small hardwares like Raspberry pi. For the usecase we are not impacted by performance. In fact it improved a lot with Genservers keeping state in ETS. And definitely the immutable data and functional programming made things a bit easy. We have a strong background in Groovy/Grails, NodeJS and Golang. And what we have found out is we could do any app that we developed in the past in Elixir if we know how to do it the Elixir way!

5 Likes

I was a longtime C++/Java/C# developer who moved to elixir pretty much full time back in 2014 (though I did spend most of 2013 doing Ruby/Rails).

Without a doubt, the biggest hurdle for adopting Elixir was getting out of the OOP mindset. In my experience, OOP-like Elixir code is the hardest Elixir code to test and debug, so I would definitely suggest starting out with non-critical or even “toy” projects first, if time allows, so developers coming from another paradigm can have a little bit of time to adjust.

Also, reading code (and taking the time to understand what it’s doing) is really helpful for internalizing “patterns”, so spend a little time looking at some different well-regarded elixir projects and just poking through the code. Plug (https://github.com/elixir-plug/plug) is a good one.

With a few resources (there’s lots of good books and some good screencasts/videos) and spending a little time looking at existing elixir projects, I really don’t think the learning curve will be too bad at all.

Back in 2014/2015, deployment was also kind of a big hurdle, but nowadays distillery (https://hex.pm/packages/distillery) has made big parts of the deployment process relatively painless. I’d recommend getting used to building and using releases as early on as possible. The longer your “deployment” consists of "scp the code to the server and run mix phx.server", the harder it will be to switch when the time comes.

7 Likes
3 Likes

Thanks for sharing this. This was an eye opener.

We are replacing a lot of services written in nodejs with Elixir services. For one large service we replaced 27 nodejs servers with 6 Elixir servers (and could probably go to 3) with much faster response times. Some things we learned:

Work out deployment early. It will take you longer than you think. Especially if you are using docker containers.

If you are using phoenix put everything in plugs. The only thing you should be doing in your controller render method is calling render(“template.html”, conn: conn). Put anything needed in a template on the conn using assigns.This allows you to isolate functionality and share them across controllers.

As @jordon0day said above, don’t write OOP code. You will regret it.

Really grasp pattern matching. Not just in case expressions but in function heads too. If you are writing if something do you probably should be writing 2 functions with function signatures that choose between the two options.

Don’t make everything a GenServer. Most times a Module should just be a Module.

Consider breaking your application into several apps in an umbrella application and/or putting them into their own git repository (on github or source control service of your choice.) This isolates functionality so you can use it in other applications/services.

That should get you going. Once you get comfortable using Elixir you will be amazed at how productive you will be and how easy it is to change and extend what you have built.

Have fun!

7 Likes