On the other hand, Next.js has become the de-facto standard for full-stack development, but it’s still far from becoming a kind of “React on Rails”, and compared to other frameworks, a Next.js project is definitely not smooth sailing either.
Because of Phoenix and LiveView
Phoenix is basically Rails for Elixir, but unlike Rails, it scales really well. And just like Rails, it comes with a powerful code generator: you simply define your data model, and a full-stack CRUD feature is generated for you with migrations, models, basic business logic, templates, components, and forms. It uses Ecto, which provides migrations, query builder model definitions, and validations for those models… and forms too! You can create forms based on your Ecto models, and Phoenix handles the form validation for you automatically, so you don’t need to repeat the same thing in multiple places.
But Phoenix provides much more: Do you need authentication? Just run `phx gen.auth`, and you have everything from registration through login to email validation and forgotten password. You need to notify a subset of clients of events? Use Phoenix.Channel. Need to see who’s online? Phoenix.Presence tells you exactly that. And the list goes on.
To explain why LiveView is awesome, we’ll need to dig a bit deeper into why it’s superior to SPAs first. But long story short, the speed and simplicity provided by Phoenix and LiveView are just unimaginable after working on SPAs for almost a decade. How fast, you ask? Look at this video where a live twitter clone gets implemented in 17 minutes.
So just to answer my own question: Why Elixir? Because of Phoenix LiveView.
What’s wrong with the Web today?
We used to build backends for web pages. They were simple but weren’t really interactive.
Then came mobile apps, and we loved the interactivity. We wanted to have the same in the browser, so we started building web Single-Page Apps (SPAs).
And why? Because we have to.
Well, if it changes so rarely, we can statically generate it, can’t we? But for now, most frameworks handle SSG in an “all or nothing” manner, so if the data behind one-page changes, we need to regenerate the whole site. So in those cases, we better rely on Incremental Static Regeneration (ISR), where the page only gets generated when it’s requested for the first time and gets cached for a given period of time. If the page gets accessed after its TTL has expired, the stale page gets served to the user, but a new version is generated in the background. So we’re juggling with SSR, SSG, and ISR, which makes it even more difficult to reason about our system. Mind you: this whole complexity is there so we can have some interactivity while forgoing the need to show our users a loading bar when they first navigate to our page.
Web development really got out of hand in the last decade.
LiveView to the rescue
The whole problem arose because our toolset is binary: A site is either interactive or simple. No middle ground, while the majority of the apps we build could do with some sparkle form validation, navigation, and filtering and could leave the other parts static.
Why we’ll help you learn Elixir
So if you’re a startup or working on side projects and you build web apps, you should definitely start learning Elixir, Phoenix, and LiveView. It might take a couple of weeks to get productive, but the fact that with them, one person can achieve what 3-5 other engineers can do in the same amount of time with other tools starts to pay dividends quickly. Not to mention that they make web development fun again.