IMO yes! It’s possible to treat offers as processes & index them to get really fast matching. Use commanded if you need event-sourcing for auditability.
It depends on your definition of real time. Erlang is quite popular in real time ad exchanges. Lack of garbage collection pauses give more predictable latency than some languages. It is considered “soft” real time, though.
When things need to be really fast and predictable, then C++ was popular, sometimes supervised by Erlang. That is a pretty good approach, isolating the pieces that need to be fast. Now speeds are such that things are done in silicon.
We wrote an embedded “logo inserter” box for the broadcast television industry in a mixture of Erlang and C++. The C++ handled the low level processing: pull a frame from a Blackmagic SDI interface, add an image, send it out another interface, 60 frames per second. Erlang handled everything else, and restarted the C++ if it should crash in time for the next frame. Bulletproof.
Does Elixir with Phoenix is good choice for real-time stock trading systems ?
Depends on what you mean by this. I’ve heard success stories with c++ and erlang (c++ handled computations, erlang handled some networking). And some experiments with erlang + rust (now rust handles the computations).
I don’t quite see how phoenix fits in a trading system, though.
That sounds quite doable. Keep in mind that Erlang is optimized for robustness above math performance, so it lacks things like native integers (it uses bignums) and can be slow. If your system is computation-heavy, managing big baskets, etc. that may be a worry. NIFs may help. For stuff like order routing and as a backend for user GUIs though it should be a nice platform to work on.
I would think that from the point of view of a market maker, a real exchange and a crypto exchange are very different beasts in terms of response time / performance requirements … I think even ads (see adroll) come closer to what’s required from a real time system than a crypto exchange due to the inherent limits of crypto trading (which seems to be mostly retail for now).
Although it doesn’t seem like you really need it here, there is an interesting talk about building hard real time systems on top of the Erlang VM: https://www.youtube.com/watch?v=yjmZoAtkkLY
Even if you don’t need hard real time, the talk gives some nice insight into using NIFs and dedicated hardware to build high performance systems.
As a related thought, maybe we as a community should add another category in the Awesome Elixir (curated Elixir libraries list) that has pointers to libraries that allow you to have an Erlang-compliant node written in other languages.
I heard about C++, Rust and Go libraries but that’s about it. There are probably more?
hmm…yes, we think it’s a good choice for trading system. we wrote https://chaince.com as mentioned above by @gonglexin (and thank you so much ) based on pure elixir/phoenix/OTP infrastructure.
we’re using phoenix channel with websocket as order submission and trading reports system, it’s very fast. we think it can be called “real time”.
as to the High Availability, it’s just the pros of OTP. there’re 12 nodes in our cluster, and the whole cluster can be rolling restarted any time we like, without any service interruption.
“elixir is a good thing, maybe the best of things, and no good thing ever DIES”
Java … as much as I dislike that language, that can be a real deal-maker for large enterprise-y shops that are heavily vested in the Java ecosystem.
That said, you don’t really need a full node to just supervise external processes or do simple communication with them (stdout/stdin style). A port is enough, as it lets you launch, sent/recv data and get notified of termination. This really opens the door to executables written in all sorts of languages.
@KishoreKarunakaran I’ve been working on just that and get sub ms latencies with colocated servers. I’ve open sourced the plumbing for the framework here https://github.com/fremantle-capital/tai but it’s still very much in the alpha stages. I’m posting it with a huge disclaimer that this is the project I used to learn Elixir, so there’s bunches of code that needs improvements
Currently it only does cryptocurrencies but I’ve been playing around with adding an adapter for stock trading through https://alpaca.markets/
Friends who work in high frequency trading tell me that in the hot path where latency is critical that languages with non-deterministic garbage collection such as Elixir are not suitable as the latency is not low enough it consistent enough.
Outside of the hot path Java and Python are used, so I suspect latency is less important there.
I suspect Elixir hits an awkward middle ground where it is too slow for the fast bits and too niche for the rest (given the extreme hiring requirements of these companies).