320 points · by wickwavy · 7y ago · 171 comments
Elixir is a very cool and powerful language for building web apps.
Having built my first product (https://retrochat.xyz) in Elixir, I can wholeheartedly recommend it to anyone who is not happy with their current backend language(Ruby, Python, Js, etc).
Docs, functional programming, OTP, ecosystem(Phoenix, Ecto, Mix) are really top notch. In my opinion, you will be able to reach much higher productivity (especially long term) in Elixir than in Ruby, which is known for it's high level of productivity. Sounds like a fairy tale, right? Well, that fairy tale can become a reality with Elixir.
The only thing that is a bit of pain is a good release support, but that has been changing for better.
We use a multistage Dockerfile to build the release and run it on a barebone alpine image, and it's never given me a single issue since I set this system up almost 2 years ago when Distillery was still the release library of choice.
And it's never crashed once, but that's the magic of OTP :-)
Simple case: Adding a new column to a table Phoenix: 1. Migration 2. update schema 3. update changeset Rails: 1. Migration
Complex case: Add a new column with validation only on update Phoenix: 1. Migration 2. update schema 3. update changeset Rails: 1. Migration 2. add validation with only on update 3. pray it won't break anything in other parts of app :/
The complex case sounds like a simple one, but in a big codebase adding validations could be troublesome for a fee reasons, but let's not dig into them. In Phoenix you can have multiple changeset definitions with different validations for each of them, which makes it much easier to control when and what data is validated.
It's just one of the examples, there are many others...
I'd say, if you are content with Rails, it's great then! No reason to change a technology stack, because some random person is saying it's worth it. If you found a good enough solution for your problems, stick to it :)
1. The stuff that never goes down (gets automatically restarted with last-known good state) and the amazing runtime in general. Not to mention it's much faster than Ruby or Python or PHP... In some cases it's faster than Javascript although JS and Erlang/Elixir are, on average, tied on performance.
2. A switch in philosophy and the way you troubleshoot your app: from magic/implicit to explicit. Many people cannot cope with this one because the force of habit is extremely hard to overcome. I for one enjoy knowing what exactly is going on in my app and exactly where but many others disagree. Again, it's a philosophical thing; you either are into it or you are not. There is also the objectively technological aspect: zero magic and implicitness mean much easier bug fighting. You no longer have to dig around in callbacks and installed on-start handlers.
Make no mistake: it's harder to start with an FP language. Nobody is disputing that. The benefits to be sown after the initial culture and brain shocks however are a lot.
I'll dispute it. For me, the functional paradigm clicked much easier than OOP and it's zillion abstrations and patterns. I'd argue that the best thing about functional programming is it's actually easier to reason about.
By what metric? Phoenix on Elixir doesn't perform any better than Ruby and a similarly lightweight framework like Roda: https://www.techempower.com/benchmarks/#section=data-r18&hw=...
NodeJS is also much faster than Elixir in other circumstances thanks to the V8 JIT.
Elixir's and Erlang's strengths over other dynamic languages aren't really performance. It's mostly just that Phoenix performs much better than Rails.
The pain in Elixir releases I've seen has nearly always been self-inflicted. You can just run "mix phx.server" on the server and have basically an identical deployment experience as if you were running Rails, Django or similar.
Releases are an option that brings some power you don't get in other languages (particularly if you're using Distillery, which makes hot upgrades possible).
I wrote a guide on Elixir deployment that covers a way to use the new mix releases and deploy to Render in minutes. It also links to guides covering a number of other patterns, including the one I currently use for Alchemist Camp. It might be useful for others feeling some of the pain you did in the past!
https://alchemist.camp/articles/elixir-releases-deployment-r...
Or, finding developers.
I actually completely agree that Elixir developers aren't many. What I observed however is that people who want programmers that know FP and can apply it to real world problems where teams of web devs can be reduced from 20 to 3... get treated like coding monkeys and not given much respect and creative freedom.
You can't replace a pile of clueless juniors banging their heads at the latest Node fashion with several experienced craftsmen and treat them exactly the same. It just doesn't work -- people get discouraged and leave. I've had that happen to three acquaintances of mine (and myself, although I don't dare including myself because, you know, our ego gets in the way of properly gauging our own competence).
I've been rejected with the generic "poor cultural fit" excuse enough times on interviews to realise that most managers and shareholders simply want soldiers blindly obeying orders and not captains that can successfully make a team pull through a tough challenge on their own terms as long as schedules and business priorities are respected.
So, to me, the problem is also in the attitude of the shot-callers -- not only in the scarcity or quality of the Elixir devs.
But then again, who does not write unit tests to get 100% coverage against 110% of possible user inputs, in case you made a typo somewhere. Right ? Right ? </sarcasm>
Interestingly, coming to Elixir from another dynamically typed language (Python), I tend to do much fewer runtime/typing errors than ever before. I might be more experienced, or the tooling and compiler are good enough to catch the most common bugs.
I get a few "no matching clause" with my data ingestion tool on my Sentry log because external APIs are flaky and a cosmic ray flipped a bit so that I'm reading incorrect data. A GenServer somewhere crashes, restarts and the data comes back clean, without any user disruption at all.
But again, I'm completely ready to hear that it's just my setup, or how we failed to build the app.
Just wanted to confirm that it's completely possible to shoot yourself in the foot, which I'm surprised hardly anyone mention when talking about elixir.
Anyone interested should give it a try.
However, this is not my experience. When something bad happens in my situations, it's usually in response to a bad input that is going to be repeated a couple milliseconds later. So the app just crashes in loops.
I don't understand how the "let it crash" philosophy is supposed to happen when the only thing that can happen after a crash is... Another crash. Maybe my case is just too strange.
If allowed me to learn the paradigm of functional programming and build systems quicker than ever before. Combined with the Phoenix framework, I prototyped a tool within a few days that would end up changing my life. I turned it into a SaaS business (called FeedbackPanda) with my partner, and it has been turning my life around for the better.
Thank you Jose for being such a key person in all of that without knowing it. Your insights and determination to leverage new tech combined with a proven software paradigm. Spot on!
It's really hard to figure out how useful it is because people always build up hype when it's not always worth it. All I ever see is how wonderful and magical elixir is and how it's literally life changing. I want to believe but I've seen technologies with lots of hype that didn't live up to it. Plus elixir is different enough that I have a really hard time jumping into it to try it out.
----
I'll also add that recently I had to build a backend for a long term project I've been working on. I seriously looked at elixir/phoenix, but from my research it didn't seem like the pros outweighed the cons. Like there are some technologies that are so useful they're worth the lack of a robust ecosystem or the steep learning curve that may be necessary. And I am not sure Elixir meets that criteria.
There's already existing technologies like python/ruby for fast development, java/groovy for stability and groovy for modern features, and finally golang which is really good for concurrency and building web related microservices. Golang in particular is nice because it solves issues like python's slowness and it's slimmer than java in many ways. And these solutions are already pretty good. It's not like it's all that hard to write a backend. Like the productivity gains from js to typescript are huge because js can be bad enough that there's a lot of room for improvement. Whereas how much faster and MORE productive can someone really be in elixir?
And I am not even going to get into functional programming which is a whole other beast. It requires significantly different style of thinking, making a lot of my experience less valuable, I don't think it solves solutions for an oop system that's well designed, and often times the implementation can be bad if the right tools aren't there. From my limited experience, FP provides some really powerful features, but at the builtin cost of being more rigid when I don't need it to be.
* No mutation support means that for some CPU-heavy tasks, it's not as performant as languages that allow mutation. Some optimized algorithms that rely on mutation can't be expressed directly in Elixir or Erlang, and instead need to be linked in through a foreign function interface.
* It's not on the JVM so we don't get to piggyback on the thousands of dev-years of VM optimization and ecosystem around it.
* It isn't invented at, supported at, and marketed by a FAANG-type company. Money moves mountains and Ericsson doesn't spend as much on Erlang/BEAM as, say, Google spends on Go.
* Comparison across types is not a runtime exception, so you need to guard against crap like `nil > 1 == true` yourself.
* Erlang standard library, which is idiomatic to use from Elixir in the same way of using Java classes from Clojure, is a bit of a junk drawer of tools. There's good stuff, but you may have to dig for it.
* Elixir still hasn't nailed the balance between creating small, independent pieces of code ("applications" in Erlang-speak) and wrangling them so they can be used as dependencies from monorepos, multi-repos, etc. Umbrella projects were an attempt, I don't like them.
* There is an impedance mismatch between Erlang/Elixir's configuration system and 12 Factor® ENV-style configs. (Full disclosure, I wrote a library for this: https://github.com/appcues/config_smuggler)
* The built-in Elixir code formatter removes trailing commas from multiline lists. I mean, come on!
Take Haskell for example, which is also immutable but doesn't require you to spin up processes to do computations. It handles CPU intensive tasks significantly better, but is a worse choice for highly concurrent low latency soft real-time apps because of the scheduler and garbage collector mechanisms.
Edit: Btw thanks for bringing up that comparison across types issue. Never realized that. What's your solution to it? I'd write guards on functions that filter input based on types, then have a final fallback with no pattern matching that throws an error explicitly.
Pros :
- Elixir is fun. It's hard to describe why, but it is. Piping is additive, so are genservers and supervisors (which lead to anti-patterns but still).
- Phoenix is well thought out, documentation is good. Plugs are so simple.
- Websocket support is great, obviously (and LiveView is a gift).
- Ecosystem is not that big, but mostly quality and the automatic hex docs is a great feature.
- Concurrency is obviously good and, most of all, only there when you need it (looking at you, Node).
- Speed.
- Coming from PHP, having the ability to easily run tasks outside the current request is so freeing and eliminates the need of many third party components.
- Testing is good.
- Mix is great.
Cons:
- I don't care about static vs dynamic types but I do miss the type hinting of PHP 7. Typespecs are helpful but not the same (and Dializer reports are not fun).
- As a follow up it's hard to beat the IDE support of popular languages. (the Elixir plugin for Jetbrains' IDEs is good though).
- Not anybody will like functional programming I guess (it did kick my butt at first)
- Phoenix doesn't provide that much. If I compare to Symfony (and I guess RoR, Django etc) it's really noticeable. Authorization/Authentication, Cache, Mails etc. Also I'm not a fan of the templating (again, compared to Symfony's Twig).
- Also Phoenix speed of development seems slower (I guess the team is small and also currently a lot of work goes on LiveView)
- What I would give to have the cross-build capability of languages like Go, or the simple deployment story of PHP etc.
- Obviously a smaller ecosystem and less support online (StackOverflow is not useful, better luck on the Elixir forum)
- Speed (for some things).
- I do miss the return keyword.
- I do miss constants (modules attributes are not a replacement).
- None of your colleagues want to use it (some people just hate VMs).
I could probably write a novel about the things I like about Elixir, but here's what I'd caution about for someone looking at adopting it over another alternative.
- Elixir is not statically typed and probably won't be. If static types are a tool you value, Elixir's success typing and runtime assertions might feel inadequate.
- Pattern matching requires discipline to not create heinous coupling. Pattern matching is wonderfully convenient for control flow and helps a ton with readability and avoiding deep nesting in complex situations. It's so convenient, though, that it invites reaching through abstractions into data structures in ways that make code brittle. The language doesn't really provide any guards against this, so it requires care and policing to keep things manageable.
- Because OTP is so powerful, it's tempting to avoid industry standard tooling and "just do it in Elixir." This is great for moving fast, but has the risk of pushing problems down to the line to the point that bigger system rework might be necessary. Background processing is a good example here. In Elixir/OTP it's easy to do everything in memory, but once you start needing failover guarantees, or need split out worker processes from a web server for independent resource utilization, you may end up getting rid of the initial implementation and doing the work to move over to a setup similar to what you might using for Ruby or Node anyway.
Learning to be productive in Elixir isn't really a huge investment, even for someone with a strict OO background. It's pretty light conceptually compared to other FP languages, can be written in an imperative-ish style if needed, and has clear, simple patterns for code organization. For every place you would consider mutating, you tend to find primitives that make working with immutable data structures quite convenient.
Pros:
- Less magic. It's a lot easier to figure out what's going on under the hood. - Phoenix is an improved Rails. Ecto is more flexible, the generators make more sense and everything is better organized. - FP leads to cleaner code. The difference to a neatly organized Rails (with POROs & service objects) is not big though. - Tooling/Mix is excellent. - Elixirforum is a great place full of helpful people.
Cons:
- Small ecosystem and lower productivity. I often had to spend 1-2 days to write a feature where with Rails I'd download a gem and it's done. - Elixir gets hyped up due to BEAM, OTP, stability, fault tolerance... - however, apart from some very niche cases most of its features can be replicated with background queues, Kubernetes, etc. - Speed & hosting costs. Elixir is a bit faster than Ruby and the footprint is smaller. But a powerful VPS + CDN is so cheap nowadays that it doesn't matter much at my scale. - It's an absolute niche language. There aren't many tutorials, SO answers or solutions for small problems - you often have to figure it out on your own.
Overall I'd say that Elixir is fun to work with and ist well thought-through. At the end of the day I only care about shipping products though. Writing my admin backend in clean FP code is nice, but I rather download a gem like Administrate and be done with it - so I have more time to focus on my core features.
From a business perspective I don't see many cases for Elixir: A small shop is more productive with Rails/JS/Python due to the vast ecosystems - and a bigger company will have trouble finding enough devs.
Absent from these comparisons are the elephants in the web world: the JVM and .net. The JVM in particular is superior in my experience to Elixir in all respects: statically typed languages, battle tested servers and libraries, abundant documentation and discussions, top of the line performance, excellent tooling allowing rapid refactoring and evolutivity, etc...
What if you did not have to choose ? It gives you all of that. There is no "steep learning curve". I had a sysadmin that never did anything functional pushing code to prod in less than a week. This is not a single case. This is the widely reported result across companies switching to elixir.
Regarding rigidity: quite the contrary. In my experience elixir and its take on FP are faaaaar less rigid than an oop one.
I am not going to bad talk any of the languages you offered. I will simply say that i disagree with basically every single one of the characteristics you offer for them.
Regarding how much productive... Well the most extreme example is whatsapp doing it all with 8 backend engineers. All of whatsapp. Recently RocketMortgage had equivalent results. In the case of rocketmortgage, it was wihtout any prior experience in the ecosystem. This was for Erlang, but all the companies using elixir report equivalent results. PagerDuty and Bleacher Report are probably the most visible one.
So in the end... do what work for you ? I do think you are missing the point a bit with your argument, which is what i will fight. But if other languages work for you, great for you :)
Wait, what? Whatsapp had 25 backend engineers in 2016, and they use almost exclusively Erlang, not Elixir. They’ve said many times that the Erlang platform has allowed them to do a lot with a small team, but let’s not turn their story into an urban legend...
Source: https://www.youtube.com/watch?v=87lW4Llsj7E (2:20)
I am confused by this response. You disagree with remarks like go being faster than python?
I'd love to contribute, but I don't know how to phrase anything other than a useless rant.
And I would love for the contribution to boil down to anything else than:
> life without a static type checker is hard when you're writing a server. That needs to stay, like, on.
Which is, arguably, not necessarily a jab at Elixir itself.
Sorry.
But if you're angry at a programming language, you probably need a holiday :-)
It is a decent language, but it's development sucks. Maybe I'm missing something. I use it for Jenkins pipelines and it does not even has an editor with code completion. I must run it through an interpreter to find simple syntax errors, like a missing parenthesis. Looks like I'm developing in the 80's.
It happens all too often that I have to manually cast stuff because the compiler cannot deduct the type of an expression. Seriously, it feels like writing Java pre-1.5 (before Generics).
At the same time, your code might just compile, and you'd get a runtime error because you forgot to rename an attribute that you referenced, and due to some dynamic wizardry Groovy tries to retrieve it anyway.
It is the very opposite of the Erlang universe, where the more time I spent the more impressed I got. So really no comparison between the two, forget Groovy if you have more than a toy project. Java on the other hand... will soon have it's fibers thanks to Project Loom...
The eclipse plugin has a pretty good approach in that it underlines things that cannot be deterministically type checked (that is: it can't prove they are wrong, but it can't prove they are right). It does a fair bit of type inference, so once you get used to that it's reasonably low amount of pain that comes from this type of problem.
It's sad that so many people form their perception of Groovy from what they encounter inside Jenkins.
I do full application development with it inside Eclipse and it is fantastic. None of the above applies. It's basically the same as developing in Java just 30% of the code size.
I don't know too much about Elixir, but for implementing web services just use the tech you know the best - these days you should be able to scale almost indefinitely regardless of the stack you choose.
But if you have a problem that resembles a telephone exchange (eg. no UI, lots of concurrent IO intensive - but not CPU intensive - tasks that have soft-realtime requirements) give Erlang a chance. Even if you end up using some other technology it will really influence your professional development in a good way.
Don't get me wrong, I love learning new languages/tools, but the cost of learning them deeply is a price that's hard to pay for when you have to get things done at an ever-increasing pace.
It have a somewhat steep learning curve with the ORM Ecto. Debugging Ecto, changeset, etc.. is not fun. Dumping whatever Ecto returns can be a puzzle because by default other than the main tables are not preloaded and it loaded with meta data. Also how you deal with Ecto and forms in phoenix is not clear, lots of gotchas. The common thing is that you have a form template that update/edit and new/create share. The problem here is if you don't know what you're doing one of your template will expect a changeset and the other will expect a list. I forgot which one gotta look into my code but it was an annoying gotcha.
The lack of things baked into Phoenix makes it a hunt to find packages/libraries to add features to it.
Examples are Laravel having rate limiting router built in and signed links built-in. I don't believe the html form is as good as other frameworks; can be at time confusing. I think while Phoenix may not be aiming to be full features as Laravel, I believe security measure such as rate limiter and signed links should be built in.
Deploying is also a learning curve. You need to compile Elixir in production server and then the folder layouts is different than development. So hunting for the root web folder of your application is a thing I did and learning about the layout of production.
Having said all that, I enjoy coding in Elixir and using Phoenix. It is fun getting better at it. While there aren't many thing baked in like Laravel, it made me more educated in the things I've taken for granted. I re-did the authentication system 3 times. I tried jwt, did more research and realize when to use session and when to use them.
I enjoy coding in Elixir more than PHP. I see myself building my side web projects in Elixir in the foreseeable future. I do recognize that it's a smaller community with less contributors so I hope this come off as a constructive criticism of something I love and know well enough.
I'm struggling to start any in-depth project. I can do stuff - make a small app - here and there. But the thought of starting something is so daunting and intimidating. The irony is that I built a small but working language as part of the compilers course in college. I feel like I know so much more know but can't bring myself to develop something that reflects that.
But it is also worth saying my first attempt (at Elixir) sucked and it demotivated me to work on the project for 6 to 8 months. It was only later I learned/figured out some of the answers or possible solutions to the problems I was having and that motivated me to work on it again. Once I asked my partners to let me work part-time on the language, I prepared myself it would have to be a long term effort (at least 2 years). Then people started using it and that in itself kept me going (and it has been like that for almost 9 years now).
In all fairness, I also do struggle with motivation when starting hobby projects, even more larger ones, and especially if most of the challenges have been addressed. Also what keeps me motivated changed throughout the years, so I try to be mindful of that.
After tinkering around in IEX and doing the Getting Started Guide, I'd do Dave Thomas's course (https://codestool.coding-gnome.com/courses/elixir-for-progra...) and read Elixir in Action by Sasa Juric. Dave Thomas's course will get you through the basics of the language and the important concepts step by step. Elixir in Action will go further into the concurrency model that makes Elixir unique.
Finally if you want to build a web app I'd go through the Phoenix Guides: https://hexdocs.pm/phoenix/overview.html#content . Those guides will give you a good example of what a real Elixir/Phoenix Web Application looks like using a database with pooling and request concurrency out of the box. The Programming Phoenix book will take that further (https://pragprog.com/book/phoenix14/programming-phoenix-1-4).
If you want more practice writing functions and algorithms I'd recommend Exercism's Elixir track: https://exercism.io/tracks/elixir or Project Euler (https://projecteuler.net).
I stay with Elixir. Thanks!
The tooling gets out of the way, so a newbie is less likely to run into roadblocks. IEX is the best REPL I've worked with. Phoenix is much simpler to reason about than similar frameworks like Rails. And the docs are clean and consistent (+ dark mode). It was really easy to navigate through the docs, try things out in IEX, and get things working. It's just modules and functions. There's no classes, base-classes, abstract-classes, inheritance, instantiations and what-not. Just modules and functions. I doubt there's a better way to learn back-end development (DBs, Queues, Concurrency, PubSub, Distributed Systems, etc.) than Elixir.
A buddy of mine has been getting into Elixir recently while going to school for CS. The school's curriculum is mostly C#, Java, PHP, and what-not. He says Elixir demotivates him from some of the homework because everything in Elixir would be way easier.
See https://github.com/rusterlium/rustler
Discord especially has several real world use cases where they've implemented native code in Rust.
1. Phoenix's channels make communication between a frontend and backend pretty effortless. Create a channel, publish a message, and anyone listening to the channel picks it up. Communicating updates from the server to the client is simple. Communicating between clients is equally simple.
2. Elixir has great support for spawning and managing background processes. My go-to is Rails, and if I want to manage background work I have to use something like Sidekiq and Redis. It works, but Elixir is much nicer. I've written systems that need to manage heavy amounts of background work and I dream of rewriting them in Elixir.
Just a few data points that might be helpful.
It's like, okay, so there's the functional programming, the similarities to Ruby, the BEAM VM, the concurrency.... but what does it do for me? They're not exactly selling points on their own because other languages can compete with those things.
As long as our hypothetical Blub programmer is looking down the power continuum, he knows he's looking down. Languages less powerful than Blub are obviously less powerful, because they're missing some feature he's used to. But when our hypothetical Blub programmer looks in the other direction, up the power continuum, he doesn't realize he's looking up. What he sees are merely weird languages. He probably considers them about equivalent in power to Blub, but with all this other hairy stuff thrown in as well. Blub is good enough for him, because he thinks in Blub.
You make an app using Ruby on Rails, keep developing it, and it keeps growing. You monitor your traffic and it gets bigger, now you add more servers to handle the traffic (it costs you $20/server, now you need 4). A couple more developments, memory usage starts to grow also.. Now, you need to increase memory of your server.. but now you also need Websockets, so you add both and need to add more resources to handle the scale, and the cycle continues.
When you use Elixir/Erlang and it’s BEAM VM, it’s highly efficient and scalable out of the box, so you won’t need to do “much” of the above. A simplistic explanation but shows the point.
OK, so in real life maybe the costs can actually be an order of magnitude higher than this.
But for $60/$80 a month? Is like no money.
That is less than one hour of time for even a cheap developer including taxes and other overhead, or okay call it two hours a month of time if you want to be generous. So if Elixir instead of Rails (or, of course worse, _switching_ to Elixir from current Rails) takes more than, say, 24 hours of developer time in a year... you didn't save money.
You're getting down voted mostly because of your tone (IMO) but the appeal if Elixir is just a reality of experience.
When I found it, I was 15 years in my career and when I dove in, learned it and saw how it addressed so many short term and long term issues that appear in application development...the balance was the closest thing I'd seen to perfect.
But if I hadn't experienced the pain, I would never have appreciated it all the little details.
You also don't have to worry about performance and concurrency. I would actually argue that you have to worry less about performance and concurrency because you can go further without having to resort to cache layers, tuning, etc.
But ultimately, I don't disagree with you. If you are building CRUD apps, then any technology is likely fine. Perhaps there is a chance Phoenix will start to take a bigger pie of the "CRUD apps space" with LiveView (https://github.com/phoenixframework/phoenix_live_view). If you could produce CRUD apps at the pace you do today, but making them interactive and realtime is orders of magnitude simpler, would that interest you?