187 points · by mike1o1 · 3y ago · 106 comments
Elixir and the BEAM make it so easy and pleasant to run extremely complicated infrastructure in the same codebase and in the same application context. Hard problems made easy.
I miss it.
It is common to have:
frontend <-JSON-> backend <-db/queue-> background jobs
Each boundary introduces complexity (marshalling / impedance mismatch / but also different HR/recruiting needs).
In Elixir you can more or less do:
front/back/background
with no boundaries or reduced boundaries (e.g. using LiveView & OBAN in the same process, even if going through Postgres as a queue).
Someone coined the term "deepstack engineer" as well recently I think, which I could draw as:
frontend <-> backend <-> background <-> machine learning
Now with Elixir you can do everything in the same process (but with isolation as required):
front/back/background/ml
And this is something I find really interesting about this stack.
So I can relate :-)
See:
- https://www.youtube.com/watch?v=g3oyh3g1AtQ - https://www.youtube.com/watch?v=HK38-HIK6NA
:sigh:
I am surprised, both in terms of the difficulty you faced and that you would want to; I have beef with the fact that using Celery with Django runs "worker" process on the application server by default.
It's much better than having to worry about extra infrastructure, just deploy your app and because it's code you control you can customise what the queue is going in really bespoke and application specific ways.
Wow, that's pretty cool
I'm sure you're right that the nature of Elixir makes wrangling all the different services easier but is there something special it does to make embedding easier as well?
If I didn't have context clues, it'd be difficult to know which one you mean.
Edit: not native but I've always understood it as the first def here https://idioms.thefreedictionary.com/all+but
This stems from "all but" = "almost"[0]
Compare to a disaster described as "the destruction is all-but-total".
That phrase does not mean "you could describe the destruction by any label except total." For example, whatever just happened it definitely not "tiny" or "moderate".
Like “all but dead”. Everything except dead, as in as close to death as possible without actually being dead (and certainly not the opposite of dead, as in perfect health).
This is usually things around either ETS/mnesia for state storage or doing hot-releases, both of which I find most people in the community recommend _against_.
A few examples:
- Server-wide state - Persistable data - Background Jobs
Having worked in a heavy Erlang codebase and enjoyed some of the features of it, but realized some of the shortcomings where when reliability is a primary concern (medical/healthcare), a lot of the advice changes.
Though I haven't written any F# in a while, I was always curious to see how F# + https://learn.microsoft.com/en-us/dotnet/orleans/overview (virtual actors) would feel comparatively.
Specifically, hot loading allows for tremendous agility in rolling out code: for better and worse. There's sharp edges, but it's worth it IMHO (of course, it should be noted that AFAIK, hot loading is either unused or very rarely used at WhatsApp now. I believe they now use fairly conventional rollouts where new instances are started with the new code, load balancers shift the load and old instances are shut down eventually... back in my day, we didn't have load balancers or easy access to spare machines to rotate through, etc)
Mnesia has lots of sharp edges too, but if you are willing to learn them as you grow, and maybe do a bit of work here and there, disc_copies and ram_copies tables scale pretty good (afaik, we only used disc_only_copies for the schema table, and that's a small table, so it works; I don't think that table type works well with large tables). And having data and application colocated makes a lot of things pretty nice. IMHO, if you are doing the volume of data and accesses we were doing with any other database, you'd need in house engineering on the database as well, so I don't see it as a strong negative that it's needed for mnesia. If you have a smaller need, maybe it works out of the box. IMHO, mnesia works best with stable nodes and stable network though: the original use case was for two nodes in the same chassis, and the farther you stray from that, the more work you may have to do. But we had replication setup between Reston, VA and Dallas, TX and it worked fine as long as the backbone between the two wasn't being extra flakey.
Again, I think post-acquisition, mnesia was phased out, but FB doesn't value stability of nodes or networks.
From the first slide in the linked article, I would almost never use Erlang to store data. I'm always going to reach for Postgres there unless I've got some very specific use case.
I do think having most everything else "under the same roof" is nice for a smaller company that doesn't want to run a whole bunch of different services, though. Having an internal cron thing, and an internal job thing are probably fine for a lot of people getting something off the ground and easier to deal with than having something external to deal with. I think in particular this is often nice when trying to replicate the production environment on both a staging and local development system. If the infrastructure is complicated, that's harder to do. It's nice to be running substantially similar systems everywhere.
I'm not 100% sold that it's that big a win compared to having more libraries and such available with, say, Rails or PHP or Python or something. But it's definitely nice to have.
https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.JS.htm...
It might be hard if you never used JS before but it not as hard as you think once you build a component.
Also Phoenix comes with common components like modals.
What I ended up doing was loading react components using LiveView hooks and syncing state using pushed events. Saved me a ton of time because libraries were all there, and worked seamlessly alongside my LiveView app.
https://github.com/petalframework/petal_components
https://github.com/coingaming/moon
I personally wouldn't use React for components in LiveView, you are just adding more complexity to your application for no reason. It really not that hard to build components using JS and LiveView. In the end you get less complex components than what you would get with react.
That leads to the market responding much more slowly to newer options, even when they have clear advantages. Smaller startups and indie hackers don’t have the same switching costs though, so you’ll see more of them making a bet on a less popular technology they believe has a productivity edge for their use case.
Plus since these solutions already exist, there is less incentive to switch things over to the newcomer when you already have something that is working.
Glad to see that some people are doing a more serious job than me :)
(also, it's a small world – I know Giuseppe Castagna, wasn't aware that he was working on typing Elixir)
I will say that editor support for static languages is categorically better due to the language server being able to more completely reason about the state of your code. That’s the one drawback.
You omitted the caveat: the program will behave in unexpected ways sometimes. What else do you do to ensure correctness?
ie The minimum bar for modern software is not "it compiles, ship it".
For example doing "1" + 2 would give you an error.
https://thinkingelixir.com/elixir-in-the-type-system-quadran....
I think the fact that most functions are "pure" / "static" is really helping with refactorings.
This topic has come up quite a few times on HN, but it seems like it’s generally people who haven’t ever used Clojure or another similar immutable functional language that worry about this.
IMO, Elixir and Clojure hit the sweet spot between a language like Ruby and one with an ML-inspired type system.
Elixir has great support for pattern matching, guards, documentation, testing and being a functional language all help negate the problems of a dynamic language.
Really they are a perfectly regular form of type hinting--as is pattern matching in function heads--when being used for no other purpose than to ensure the correct type is passed at runtime.
I know from Elm that it does change how things feel. I could see an upside. But coming from a dynamic life I can't quite grok considering it a requirement.
It really depends on your definition of your massive. Discord seems to have a few hundreds to a thousand employees in total. I am from a typical tech company. So I could estimate that their total engineers count is probably just a couple of hundreds, which is about our director/senior director's team size.
In our definition of massive, we could have even hundreds of ppl to touch the same portion of the code base frequently. We regularly have to deal with code which are about 10 years old and it's a moving target. You have to deliver quickly with migration requirement in mind. Also we frequently collaborate with the other teams and you have to be able to understand others' code quickly.
Typing is critical as you don't have time to deal with the constant stream of the new projects to dig deeper in to the objects. And you really want to have some understanding of the code in the first glance. We also want to offload lots of the things to compiler and ide as much as possible.
It doesn't have to be full on static typing like Java, type annotation in python/ruby already helped a lot
YMMV very large project have been written in Erlang/Elixir without static typing and they've been wildly successfull
i.e WhatsApp (based on Ejabberd), Ericsson network switches, RabbitMQ, CouchDB and a lot more, you can read about some of them here https://www.erlang-solutions.com/blog/which-companies-are-us...
as a less knows example, an entire insurance company in my country with > 1 million customers
The "niche" label cast at Elixir and its ecosystem hasn't been relevant for years; it can do what you need it to and with massive reduction in complexity.
If or when you do need to write your own library: you'll find that straightforward as well.
Have a proposal here: https://docs.google.com/document/d/1adXQGiDoqyJ37r8XWYthFFZf...
[1] https://github.com/hbcondo/last10k_liveview
I've been brainstorming writing my own book that covers elixir pheonix crud, auth, background jobs, live view, (+ more?) using a twitter-clone example, which feels sufficiently complex. Basically writing a book that I wish existed.
I also did Rob Conery's Elixir tutorial which was fun - https://robconery.com/course/take-off-with-elixir/#/ Absolutely loved the way he did this one as a story but it also didn't feel like I was sitting there forever waiting for him to get to the lesson either. Looks like it's out dated though.
I can cite some easily available public stats: Scholar, which is compared to numpy, has like 0.001% of its popularity. (While there are rumors people buy likes on github I doubt this is something affecting the numpy project).
Maybe the reason believers in elixir/erlang are more passionate is precisely because there is no obvious reason there isn't major adoption?
My best guess is that the missing ingredient are major corporate interests that directly or indirectly are promoting the technology. E.g the usual big tech suspects seem to be absent. For better or worse, they are the ones dangling lucrative jobs prospects etc.
But if its a technology delivering the goods people would gravitate to it sooner or later. Would be interested if more informed people can add their insights
The ruby community it aimed at initially already moved to go and JavaScript by the time phoenix became production ready.
Erlang is an arcane, hard to understand language which many of the base packages of the elixir ecosystem uses.
I think that’s why it’s not as popular as it should be.
It’s great though. My go to stack is phoenix nowadays.
ML isn’t even close to the primary use case of Elixir either. This is just a bizarre comparison.
Also, Scholar would be equivalent to Sklearn, not Numpy. Nx would be the Numpy equivalent. Scholar has literally only existed for 2 years.
You shouldn't have any issues integrating it into Absinthe, because it doesn't have any ecto bindings out of the box. (There's a helper library, but even that is fairly small.)
I have heard of people using mnesia, but it's not really that common. I'd personally avoid it unless I had a good reason not to.
[1] https://elixirforum.com/t/elixir-ls-error-undefinedfunctione...
[2] https://hexdocs.pm/credo/Credo.Check.Readability.AliasOrder....
Plus, these days there are many alternate LSP implementations besides Elixir LS: