Little over 3 weeks from `mix new` to the live event. Not sure how I could have done it so easily without OTP and LiveView.
Can you share any details of how that works? E.g. do you operate on a single HLS chunk at a time, or can you get ffmpeg to separate a continuous audio stream, etc?
When a stream starts I start a supervisor that then starts a GenServer to manage the port. On init a port is started for FFmpeg (using the above bash wrapper) with args that sends 16-bit PCM audio back to the port through the `handle_info/2` callback.
When a new live HLS segment is downloaded by FFmpeg the entire segment's audio is sent to the GenServer all at once (could be a few handle_info/2 calls, but it happens quickly). Since I want to work in small fixed chunks, I send the segment's audio to an AudioBuffer GenServer (started as a sibling under the same supervisor). This buffer uses binary pattern matching to segment the audio in chunks exactly 2 seconds long while keeping any remainder in the GenServer's state for the next buffer event. I then send the chunks to another ChunkBuffer GenServer that pops chunks at 2-second intervals for processing.
Since everything is supervised, if (when...) FFmpeg crashes the supervisor just restarts it. Meanwhile, the audio in the buffer is still processing and nothing goes down. There might be a duplicate word or two in the transcription if the restarted port processes a segment again, but everything keeps running smoothly.
For even more reliability, I have the application running clustered across four locations in the US, EMEA, and APAC using libcluster[^2]. The stream supervisor is started under a Horde.DynamicSupervisor[^3] with a custom distribution strategy. The strategy prefers the region closest to the company HQ, but if it goes down, the processes will be restarted in another region.
[^1]: https://hexdocs.pm/elixir/1.13.4/Port.html#module-zombie-ope...
Working with it in a real project now, instead of toy examples like in the video, it works really well for when you have highly complex components that rely on quite a lot of local state.
What you'll find is the developer experience is quite nice with LiveSvelte compared to JS hooks.
Personally, I use it for any web app I'm making. It's a very simple language at its core and is just as good for tiny things as it is for large ones.
The last time I used it seriously, we used Erlang as the high level language for these: https://www.icare-world.com/us/product/icare-eidon/ and it was a great fit for that kind of semi-embedded environment.
A slightly cool thing its enabled is that I have a monolith with a single microservice. All the microservice does is process messages from the main app to process images, upload them to S3, then notify back when it's done. The cool thing is that they can be run on two separate connected BEAM instances communicating via the built-in message passing with no need for an HTTP API. I haven't deployed this, yet, though.
Maybe that's still not what you're looking for but I was really happy when I figured out I could do that :D
Elixir felt all around like s perfect fit for it , apart that some faster deep mutations likely would have been had to be ported to rust or c because the way I wrote it having 250 players on a single map walking around and seeing each other close by caused huge latency but no crashes Scaled well across multiple machines and lots of players as long as they did not all bog down the same map process :) Didn't even had to think s lot about how I structured it for the current state of development it was basic rapid iteration with mostly live recompilation on changes without having to restart anything https://gitlab.com/zen_core/zen_core