Building a Reddit-like site after 3-4 months learning Elixir
reddit.com
reddit.com
Our task load was getting out of hand, and during peak load throwing memory and CPU at it was not helping. Task monitoring was also a pain. It needed a complete rewrite, because the original design, while robust for what it targeted at the time, could not keep up with our growth.
The integration developer I hired to take over the project looked into using Go at first, but then discovered Elixir. I started learning it with him (he quickly surpassed me), and after a few trial task implementations, I gave him the go-ahead. We couldn't be happier with the result. Thanks to OTP and the existing tools built around it, we have great monitoring, and the ability to easily and quickly scale up workers at peak times.
I have not switched to Elixir/Phoenix for my other web development. I still use Django for that.
Elixir (due to Erlang base) is great for long-running or distributed services and includes tooling to, for example, easily introspect the state/memory usage of your services down to a single mutable data structure, to heal from failures, and to hot-swap upgrade/code while the server is still running, and to perform node-to-node RPC.
Go would be a replacement for something that was previously written in C/C++, that may need concurrency, and that should compile to native code. You get very fine-grained control of everything from network to file operations and excellent concurrency constructs. A web crawler, a device driver, or writing an Nginx/HAProxy-type daemon, all may be great example use cases.
One could write their next social network/app backend using Go (just as one could do it in C), but it would probably take more work than just using a higher-level language.
PS: Go's memory usage is pretty up there some times, another reason you should probably stick with C/C++ in the context mentioned above.
It took about a week and a half to write, and would have taken a bunch more time to fix to apply backpressure properly, so it suffered from getting OOMed. Even it's base memory usage was around 300MB. I rewrote it in elixir + genstage in about 8 hours, now it takes 60MB of ram for basically as many messages as I can throw at it, because 1) beam uses a lot less base memory 2) backpressure concerns are sorted out.
In scala, I would have to use akka streams or similar, and it would take me weeks and still I don't think I could get it to fit in such a small footprint.
I plan to add websockets to view a live stream, but I have a little trouble finding the right genstage patterns (as it's still new).
If I were doing high frequency numerical calculations, maybe scala would be a better fit, but for most high speed messaging elixir is pretty amazing.
The OTP foundation of Erlang and hence Elixir just screams "platform" or at least "network", as it was designed to handle parallel flows of data. Great to see yet another project utilizing this aspect of the language.
Only a single TCP connection is opened between any two nodes and there's a head-of-line blocking issue with message delivery (intentionally for backward-compatibility reasons).
Certainly you can build your own multi-connection subsystem if you want to, but that's true of almost anything. I've had to do this for Erlang several times.
Grind this thing to a halt!
(...no, actually Elixir is pretty cool.)
It is, however, likely true based on the evidence that each ElixirConf so far has doubled the number of attendees of the previous year.
Search trends for the language seem to be growing, although not seemingly strongly: https://trends.google.com/trends/explore?q=%2Fm%2F0pl075p
Elixir has become my go-to language for whipping up new communication utilities. The syntax is comfortable, although I had to get used to a Functional Programming style at first.
What I like most is the language and runtime's features that make parallelization so easy. Spawning threads that are monitored, have their own protected state, that are managed if they crash, and are trivially spread across different machines on the network made it straightforward to write fairly highly available code right from the beginning without a lot of planning.
(I assumed it was a front-end Javascript framework or something like that)
For me coming from Scala, I feel like the lack of typesystem would be a step back.
Between Dialyzer (a static analyzer that finds type errors) and runtime pattern-matching (extremely powerful destructuring, sort of borrowed from Prolog initially), I don't find myself wanting to go back to strong typing on the JVM.
side-effecting shots fired!
I'm still getting used to dynamic typing in Elixir. Most of the time I feel like just matching against Map data structure or records.
While Dialyzer is great, writing the typespecs is a bit of a maintenance overhead. I suppose it's a tradeoff...
> I came to Elixir from Scala, [..] now I don't have to deal with the half of the Scala community that tries to make Scala into Haskell.
IMO Scala will continue to be a multi-paradigm lang. On pure-FP and libs, it's a choice and really depends on the problem domain. It might not be a good solution to everyone, but I'm glad it exists.
It would be a bit like showing Rails on the uptake, but Ruby going down, isn't it?
It's as seeing a graph with Java usage going down, while Kotlin or Scala up.
Not sure why I got the downvotes for asking a question, but there you go...
weird?
Elixir isn't in the Top 50 programming languages yet, but I reckon it will be there in not more than 3 months... and that is respectful given its age.
This isn't to say that I wouldn't use SO for other purposes, as I actively visit the site for JS/PHP content. Anecdotal evidence to support your insight by all means, of course.
"Go to the Slack channel" is not really an acceptable substitute for that level of independence in research.
The other angle that SO can misrepresent is that inexperienced developers are using the site more than experienced devs. If you know your language/framework/libraries pretty well, then you are mostly going other places for help like API docs or maybe directly to the Github repo for a library and asking committers since you are much deeper into the language.
I'm also in your camp (not liking Elixir or Erlang's syntax, but really liking BEAM). I like Clojure a whole lot, but would prefer it on BEAM for a whole variety of reasons. LFE seemed like a step back from Clojure in many ways when I looked at it.
You might find Joxa interesting, it predates Elixir, but came after LFE and is patterned on Clojure.
Erlang does something very similar.
Erlang Source Code -> Erlang Abstract Format --> Core Erlang --> BEAM bytecode
I'm pretty sure that LFE doesn't skip the Erlang Abstract Format step
Macros in Elixir are "true" compile-time macros... They take the AST as an argument, and are expected to return an AST. Possibly the first, or one of the first, implementations of "true" macros in a non-homoiconic language, which was previously a strong selling point of homoiconic (Lisplike, syntax-less) languages.