204 points · by thibaut_barrere · 3y ago · 171 comments
I feel for anyone using a Node.js backend. Y'all really don't know what you're missing.
Also dealing with bugs is infinitely harder. Try catch is infinitely more wordy and messy. And you lose out on so so many valuable CI steps the Elixir community has from sobelow to credo.
And then there's writing tests. In the Node.js community it is an actual joke. It is so hard to write tests and I have yet to see any framework create a nice sandboxed test environment that just works.
All of this stuff in Elixir is free.
And like someone else said, the best ORM is Ecto and it's hard to disagree with that.
Making a reliable and organized Node.js application is actually so difficult.
If my pet project was in Node.js I would not even be able to accomplish it. And that's a fact. Elixir makes me so much more productive and the code I write is so much less buggy and less complex.
I love that HN loves Elixir. If only it was more common in the workplace.
Refactoring code without static type checking is a nightmare. If you're using a strict statically typed ORM like Prisma [1], you can change your data model then run tsc --noEmit --watch in your terminal and the compiler notifies you of every error with their associated file names and line numbers. In VSCode you can even click the line number and it'll open the specific file where the error occurred. Before adopting Typescript, I basically never attempted large refactors, and when I did it consisted of a long process of grepping for specific symbols in the project, and manually writing lots of tedious and verbose tests to do a fraction of what the compiler does automatically.
I remember developers from the Elm community years ago constantly advocating for static typing, and thinking "this has to be hyperbolic". Richard Feldman gave a talk about how he wrote code on an airplane for hours without an internet connection, and without actually running the code, and how the compiler ensured that the code just worked [2]. Typescript is not as sound as a Hindler-Milney type system, but the benefits are similar (especially if you're running Typescript in strict mode).
Ecto is good but I think the Django ORM does it better. The ORM in Django[0] is dead simple and easy to understand. The only caveat being that Django doesn't have changesets, which I do like.
It also integrates nicely with the Django Admin. You setup your models, and you can very easily generate an admin interface to CRUD on those models.
One annoyance I have with Ecto is that migration files are handwritten. There's a generator tool, but it only gives you a skeleton migration that you then have to manually fill in. This gives you 2 sources of truth, which is error prone. Automating this process like in Django solves this issue.
Ash[1] (which uses Ecto under the hood) does solve most of these issues, although at the moment the documentation can be hard to navigate.
[0] https://docs.djangoproject.com/en/4.2/topics/db/queries/
Oh no, I strongly disagree. I know both very well, and Ecto is much better and flexible. SQLAlchemy was great, when I last used it two aeons ago, but still subpar compared to Ecto.
But also apples and oranges. Django has an ORM (i.e. stateful), Ecto is a stateless data mapper.
And there's no repl if you're using transpiled code. I have tried using `ts-node` but that didn't work. In Elixir this stuff just works.
Maybe there's some tooling I am missing out on with Node.js. I am not familiar with Deno.
This is why there was so much push in Rust to get async anything up and running.
There are a LOT of people fed up with the current web backend ecosystems.
This is a huge disadvantage, and extremely dangerous, and in my opinion should render the entire language useless as a backend language for any serious project.
Elixir may not be a silver bullet. But Node.js is definitely a vampire...that isn't on your side.
I also think that livebook has a couple of really killer features now that make anyone who spends a significant amount of their time in Jupyter notebooks to stop and take a second look (eg it’s so easy to share a livebook compared with sharing a jupyter notebook, or even easier to extract code from a livebook prototype to turn into a resilient production elixir module).
Yes there is still a ways to go to catch up to the maturity and breadth of the community that Python has in this domain, but that gap is closing way faster than I could have thought.
I think the biggest challenge for adoption is its functional nature. If you take the time to learn about elixir and the BEAM you are rewarded with a pretty complete runtime which ships with its own DB, in-memory Store and message queue (with a very easy path to adopting more battle tested versions of these when you outgrow what is included in OTP). This means spin up time prototyping new systems is spent less on vendor choices (which type of DB should I use) and more on solving your problem domain.
I wish I had know about all this stuff 5 years ago…
The topology is exactly the same
In fact, porting your vetted numeric code to Elixir is probably going to make the risk go sky high, but running the same code with supervision structure in Elixir would in fact reduce risk so is a no-brainer
Just my thoughts of course
I think pattern matching and the pipe operator combined with the let it crash approach work very well in practice. There are amazing libraries for Erlang/Elixir including database client, dataframes, JWT, http, AMQP client and many more. I haven't had a single library that was not working out of the box the way we wanted.
The code is pretty easy to follow and we can onboard a new engineer with ease. The usual ration for our codebase comparing to Python is 1:10 in favour of Elixir. The engineers on the team have 10+ years Python experience and only used Elixir for toy project before.
And yeah, resilient design de-risks itself and that alone is a huge gain because it also reduces other forms of complexity.
Still, I think we have to keep pushing to debunk other myths from "it's impossible to find talent" and the fear of "no one uses" that are common myths about any technology that is not the #1 most used.
Of course, those with more experience tend to have heard of Elixir and be keen to work in it.
People with less experience are more concerned about whether investing in this language is a good career move, so we emphasise how learning something like Elixir will ultimately make you a more valuable developer.
If you’re considering adopting Elixir for your new project/startup and worried about finding talented developers, I don’t think Elixir will make it harder and might even make it easier.
It's been 4 months and counting that I've been trying to land an Elixir freelance contract.
My theory is that dev. happiness and productivity is so great in Elixir land, there is not much churn, so talent is available, jobs, not so much.
21 years of experience in total, including in C/C++ and Java.
[1] https://survey.stackoverflow.co/2022/#technology-most-popula... [2] https://madnight.github.io/githut/#/pull_requests/2023/1
https://survey.stackoverflow.co/2022/#most-loved-dreaded-and...
It depends on how you measure sustainable. What would happen to Elixir without its BDFL? Has Elixir achieved escape velocity and will continue? Rust was pushed out of the Mozilla nest and managed to live on. I don't see a similar capacity for Elixir handling such existential risk. Are there succession plans? Is there mentoring among members of the core?
I also think that it's necessary to point out that just because OTP facilitates resilience doesn't mean that the system you'll build with it will exhibit that behavior. You have to design your system to use OTP effectively. Easier said than done. I've seen Elixir systems reach a critical failure state following maximum restarts of its internal processes. However, at least Elixir has the potential of being hardened. It's just not going to act as expected without a lot of up front wisdom applied.
We do test systems to the point of breakage. It is not something we skip just because the language is good.
As to existential risk:
I will try to be succinct. If there has been no exposure then there is no need to hedge.
Further, there are commercial firms which will maintain your critical systems. In other words, a long term maintenance contract for Elixir systems can be procured from more than one source.
If you already work with Elixir, I have couple of posts that might be helpful[0].
What I love most about elixir is the ridiculously dead-simple vertical scaling. A close second is The World’s Best Take On ORMs (aka Ecto).
Horizontal scaling is what's hard for a lot of systems, but simple with Erlang and Elixir since they are, by design, meant to support concurrent and distributed workloads. That's why I was asking if they meant horizontal and not vertical.
Erlang and Elixir are not uniquely easy to scale horizontally, but they are (if you don't fight their nature and produce programs that consist of one giant execution thread) ridiculously easy to scale horizontally by tacking on additional CPU cores or physical CPUs.
The challenge is the prevalence of hypes, which as pointed out insightfully, can lead to irrational choices.
I think Elixir/Phoenix could use a little bit of Javascript (and modern PHP) enthusiasm to help with adoption - this all seems a bit…dry.
My stack these days is just Phoenix, Liveview and a sprinkle of client-side interactivity with Stimulus.js, which is super-simple, composable, progressive (i.e. just add it where you need it) and plays excellently with Liveview.
I am designing a super interactive, fully synchronized in real time dashboard with no more than 100 lines of Javascript code to handle: dropdown menus, show/hide burger menu, scroll to top after pagination. Just as it was originally designed, JS should only be the icing on the cake, not the entire buffet.
Yeah, I'm so hipster I'm already living in a post-Javascript world. Feels good, man.
I hate code generators with a passion. They obfuscate the inner workings of the library. Have you tried to find a tutorial which do not use the Mix task "phx.new"? (an up-to-date one).
For example, if I need an API, I will pass `--no-assets --no-html --no-live --no-mailer --no-dashboard` and the generator still creates a static files folder and static files related code.
If I want the strict minimum, I have to take some time to remove the un-necessary code.
Don't misinterpret me, I think Phoenix is a great framework, just like Python/Django, and Ruby on Rails are.
But sometimes, I just want Flask/FastAPI. You can say "just use plug_cowboy", but IMHO, "plug_cowboy" is more like "express.js", not really a FastAPI-like framework.
Also, absinthe is the only GraphQL implementation that natively supports subscriptions (via phoenix+phoenix_pubsub). In Django (graphene), you need so much more boilerplate with django-channels and yet another library. In JS land, Apollo Server also do not support it natively, you need graphql-ws and a pubsub implementation as well. And most of those pubsub implementations will need a Redis (or whatever) to distribute the queue between multiple web workers, while Erlang/Elixir have been designed for this (which actually simplify your infrastructure).
In the end, I often go with Django Async (via ASGI) with Server-Sent-Event (via an async StreamingHTTPResponse) to avoid the complexity of GraphQL subscriptions. But even that, I need a pubsub via Redis to make my multiple workers aware of each other. While with Elixir, a simple libcluster dependency, and a `receive` in the endpoint handler would be enough :)
But speaking of generators, I love this site: https://www.phoenixdiff.org/ — diff your local Phoenix version with the latest one to bring your codebase up to date. I use it every major release to adopt the latest best practices, even if Phoenix has decent backwards compatibility.
What do you mean? You can use other libraries, for instance Guardian or POW.
I can argue the exact opposite: you can just look at the generated code to understand what is going on. No magic involved.
> For example, if I need an API, I will pass `--no-assets --no-html --no-live --no-mailer --no-dashboard` and the generator still creates a static files folder and static files related code.
To me it sounds more like an issue with phoenix rather than with codegen in general. I would expect the static folder to not be generated if we pass the "--no-assets" flag.
Take a look at how django does it. `django-admin startproject` creates:
- settings.py
- wsgi.py
- asgi.py
- urls.py
Then you just need to add your models and views. There is the `startapp` command, but you don't really need it.Even with the codegen tools, you still need to learn what a plug router is, what a phoenix controller/view is, what an ecto repository is, etc...
The codegen tools just overwhelm you with irrelevant code (i'm making an API, why the hell do you generate static files? and why do i need to edit so many files to take it out?)
Another point I don't like about Ecto is that you can't easily switch the database backend depending on the environment.
With django, I can have an sqlite3 db for the dev environment, and a pgsql one for the production. I don't want to run a docker image for pgsql on my machine. I just need to read the DATABASE_URL environment variable, and the ORM takes care of the compatibility. If later on I need some specific pgsql feature, I will have to run the docker image on my computer anyway, but until them please keep the complexity out of my way.
The documentation explains every part of a Phoenix app pretty well.
The code generator is not there to learn you anything. That is your own job.
Adding a controller or schema to results in a small number o f new files. Git commit before you do and you can easily understand what was added.
[1]
[...]
./deps/phoenix_live_view/assets/js/phoenix_live_view/view_hook.js
./deps/phoenix_live_reload/priv/static/phoenix_live_reload.js
./assets/package-lock.json
./assets/vendor/topbar.js
./assets/js
./assets/js/app.js
[...]Previously have seen: https://github.com/patrick-steele-idem/morphdom
I do not know how true it is today.
Definitely, although as someone who finds that level of "enthusiasm" or fanboism a turn off, I like that it's not there. But it has to be there to ensure the success and growth of the language/ecosystem.
I found maintaining the Typescript codebase in the same company much easier.
It's a little bit better than what it might look like on the surface level as you do a lot of pattern matching and dialyzer. It's far from what you get from Rust of course, but it's better than with Python for instance.
So, I leafed through this document, and did not see how it would help people sell Elixir. Engineers will not be offered reasons to prefer it to other languages (popular or otherwise), and managers / bean-counters will not be convinced by the claims of it being less risky and a robust choice for a glue language - when very few people know it, so maintaining the elixir code will depend on some local guru and/or training people to use elixir.
... and this all is not to disparage Elixir! I just don't feel I've been told almost anything about it.
For an experienced dev wanting to pick up Elixir I would suggest picking up Elixir in Action [1]. The third edition is currently in MEAP. Much more concise and great discussion of some Erlang/OTP internals too.
[0] https://github.com/DockYard-Academy/curriculum
[1] https://www.manning.com/books/elixir-in-action-third-edition
Haven't actually gone through it yet, but hoping to over the next month.
Use the code THANKYOU10 to get a $10 discount ;)
But I'll bite: What's wrong exactly with using Github's markdown renderer?
This is a plain markdown file, the author could host it on S3 and it'd look like:
https://gist.githubusercontent.com/evadne/c9aeca424d30f024ba...
There are a ton of markdown renderers, author could write one in a few hours for the feature used (#, ##, ###, >, and unordered lists), or even better, paste the thing in one of the many markdown-to-html tools (https://markdowntohtml.com/).
This is not like the author used some proprietary syntax, that only displays on Github.
GitHub has forked Markdown in a way that is incompatible with CommonMark, GitLab, etc. So the author might accidentally buy into that fork which there is no quality control for (just look at the lack of care put into their attempt at admonitions).
You can share it elsewhere if like
Resilience, within the context of this presentation, and the philosophy of Erlang, would be the capability to recover from errors while unattended.
I prefer systems that don't fail quite so smoothly. Take this example: The application runs out of memory due to too many transactions being processed at once. The problem happens once every day. However the system gracefully recovers, and the team is able to resolve the issue peacefully without the problem escalating to an active incident.
If I was funding development of such a system, I would find this situation unacceptable. I'm paying for an application that doesn't crap out in production every single day, not one that "gracefully recovers" after each such event so the dev team can "peacefully" manage it. The users whose data is lost during these incidents probably wouldn't feel quite so peaceful about it, either.But in practice, if you're on the BEAM and use OTP as intended, your code is fully parallel, split into fault-tolerant pieces, and one crash does not affect the entire system.
I have been responsible of two Elixir monoliths in the last 6 years, and I have not seen them crash even once. Not even during prototyping, not even during load testing, never once. Without having to adopt defensive coding strategies. I write 1/4 the error checking code than if it were Rust, and 1/10 than if it were Python or Go.
How many platforms can realistically promise this?
Note, I haven't said my code is bug free. It's buggy because I'm only human and make plenty of mistakes. But the BEAM saves me from myself, saves me from third-party JSON endpoints that for a split second return corrupted data, saves me because the DB connection dropped for a second, and saves me from the myriad of transient heisenbugs that happen in production.
The bugs are still there. But the system is fault-tolerant because it has been designed to be.
--
If Saša Jurić can't prove it to you, then no one can: https://youtu.be/JvBT4XBdoUE
(I'm pretty sure every time someone posts this link, the number of Elixir converts increases a notch)
I love the OTP framework. So much that I suffer from "erlang envy" in every other language I'm using.
Which is why I made this a couple years ago: https://linkdd.github.io/triotp/ (not benchmarked, not tested in production, only an experiment)
I think it would have been better if he had more time. The first part was nothing special as such, it could have been easily replicated in even crusty old things like Delphi, never mind modern C# or similar.
It only became interesting when he showed the introspection and when he scaled out to another instance. These things you cannot do so easily in other systems. So would have been more interesting to spend more time on that stuff.
I'm sure there are other videos doing just that, just my thoughts on this one as a "PR video".
Seems like most of their issues would not apply to a greenfield project and now that things are stable, they're quite happy with the choice.
Traffic estimate: https://www.similarweb.com/website/cars.com/#overview
If people build multi-billion dollar companies on top of PHP and Node.js, I would not even be concerned about scaling Phoenix.
With OTP, you have what we call a "supervision tree". Your software is divided into components (erlang processes) and organized in a tree where the leafs are your components, and the nodes are the "supervisors" which will catch the error, and restart/retry the operation.
What's the result? Imagine you have a component that is polling data from the database and then sending a message to another component based on that data. For a split second:
- there is a network error
- you lose the connection to the database
- the component crashes
- its supervisor notice the crash, restart the process
If the network error was temporary, everything goes back to normal, and your system did not stop for a temporary network error. And your component does not need to have "retry code" (it is delegated to the parent supervisor).If the network error was not temporary, the parent supervisor will notice that the component crashes far too often, and will decide to crash as a result. Letting the parent supervisor of the supervisor deal with the problem.
In Erlang/Elixir, processes can "monitor" other processes. They will receive a message when the target processes dies (normally, or abnormally). This allows you to delegate the error handling so yes, you write less defensive code, because that code is located in a dedicated component that will be notified automatically.
There is a limit to how defensive you can make your code. As soon as you call out to another service for data, the universe of errorinf situations they can create goes to infinity. For example they could happily send you a 200 but return mistyped JSON. What do you do in that case? Are you genuinely going to write that as a test condition to make sure the transactional chain in your system handles this and rolls back the db inserts that preceded it? I can tell you that in 99% of cases idiomatically written elixir will "do the right thing" if this happens, and that is a consequence of "let it fail" philosophy. Moreover, if you try to write error handling code in the traditional sense, you will probably get it wrong, it will be hard to understand, and it will be hard to debug if your implementation is not quite right.
Trying to continue this conversation is a waste of our time. Feel free not to use Elixir.
To me these phrases are more about the guarantees—if it does crash it recovers—and less about dogmatic advice that everyone follows.
But there's time and place for different levels of defensive programs. I get to pick and choose based on where I see risk, but I know the whole app isn't going to blow up if I missed something.
Hard crashes are not an acceptable substitute for observability, or continuous improvement.
This example doesn't even rise to the level of an "active incident" in the Erlang philosophy. In other words, it's not a bug, so there's no urgency to improve it.
It's still a bug that should be fixed, it's just that the effects are better contained thanks to the ability to self-heal.
Who says data has been lost? Only if your protocol is fire-and-forget with no checking. But then you'd have data loss no matter the language(s) you implemented it in if your system became inundated with requests and crashed.
Databases have WAL -> Systems have task queues
The executor itself can fail, if the job is not lost :)