Why I chose Elixir & Phoenix for UneeBee
Tags: elixir, phoenix
Published: 2023-11-23 14:38:28

_This post is the answer to a [question I got on Twitter](https://twitter.com/tanatip_/status/1727643577730400333)._

I established the following criteria for choosing a framework for [UneeBee](https://github.com/zoonk/uneebee):

1. It should allow me to move fast without much external help.
2. It should allow me to easily customize things according to my needs.
3. It should have a good performance that allows me to save money on servers.
4. It should allow me to create interactive pages with minimal effort.
5. It should provide good tooling.
6. It should be type-safe.

## Frameworks

I considered the following options:

- [Next.js](https://nextjs.org/)
- [Remix](https://remix.run/)
- [Ruby on Rails](https://rubyonrails.org/)
- [Laravel](https://laravel.com/)
- [Django](https://www.djangoproject.com/)
- [Phoenix](https://www.phoenixframework.org/)

## Moving fast

I've been working with JavaScript for 14 years and I had lots of experience with Next.js. So, that was my initial choice. But, even though I love Next.js, I don't consider it a really full-stack framework since it doesn't come with the model layer and I wanted to reduce the work I have to do. Plus, Next.js uses a lot of RAM when using `npm start`. I'd need a serverless solution but they can get quite expensive. 1TB of extra bandwidth on [Vercel, for example, costs $400](http://vercel.com/pricing). I wanted something more cost-efficient.

Rails, Laravel, Django and Phoenix seemed much more robust solutions for moving fast as they have more full-stack features working out-of-the box. Database, Auth, Mailing, Background jobs, etc.

## Customize

Requirements often change. Problems happen all the time. I wanted something that was easy to debug and customize. Rails favors "convention over configuration". That's good for moving fast but not so good for customizing. There are certain ways to do things and I wanted more flexibility.

Phoenix, Laravel and Django felt easier to customize. I love how flexible Phoenix is. Their generators, for example, just write the code for us. This means we can easily customize all the generated code.

## Performance

Built on top of the Erlang VM, Phoenix deals much better with concurrent connections. It's very efficient RAM-wise. I've been quite impressed how much I'm able to accomplish with just 256MB RAM. I had some issues with other frameworks when using low RAM.

Its performance is so good that I didn't even feel the need to use something like Redis for caching.

## Interactive

This one was hard and almost made me move back to JavaScript. I'm building an application to create interactive courses. Even though it looks simple now, it will have much more interactivity in the future.

Laravel has [Livewire](https://livewire.laravel.com/), Rails has [Hotwire](https://hotwired.dev/), and Phoenix has [LiveView](https://github.com/phoenixframework/phoenix_live_view). Django has some community alternatives but nothing that seems much popular. I worked with Django in the past and we usually had JS frameworks for the frontend.

I love how smooth Livewire and LiveView are. I'm still a little bit concern about LiveView using WebSockets because it requires a permanent connection with the client, which could be bad if your connection is unstable. But, overall, I liked how little JS I need to write with LiveView.

## Tooling

I think they all provide good tooling but I was quite impressed by how many things Elixir provides out-of-the-box, especially testing, formatting, and even documentation.

[Jason Stiebs](https://twitter.com/peregrine) wrote a good [blog post about it](https://fly.io/phoenix-files/elixir-and-phoenix-can-do-it-all/).

## Type-safe

Even though Elixir isn't a typed language, it provides good tooling to make it type-safe. Using a combination of [Typespecs](https://hexdocs.pm/elixir/1.15.7/typespecs.html) and [Dialyzer](https://github.com/jeremyjh/dialyxir) has been good enough.

## Conclusion

Phoenix provided a great cost-benefit. Excellent tooling and performance, I can easily create interactive UIs using LiveView, it has good enough type-safety with `Typespecs` and it's highly customizable. Plus, it's a functional language, which is my favorite paradigm.

The main down sides are:

- Learning curve: Elixir can be a hard language to learn. There's a lot of concepts to grasp and I don't think I even understand them all yet. The good thing is that you can get pretty far knowing the basics only.
- Community/Resources: It's not as big as the other programming languages. This means fewer learning resources out there.
- Contributions: Since the community isn't as big as others, this means the project will probably get fewer contributions. The adoption would probably be much higher using Ruby, JS, PHP or Python.