Achieving Real-time in Elixir
Explore how Elixir's functional programming and lightweight processes provide a strong foundation for scalable real-time applications. Understand the role of Phoenix and its channels in building web-based real-time features, emphasizing clean OTP design for reliable data and error isolation.
We'll cover the following...
What is Elixir?
Elixir is a functional programming language that enables scalable application development. Elixir is a low-ceremony language—it emphasizes expressive syntax that quickly conveys the meaning of code. These properties help reduce the complexity of code and, by proxy, improve maintenance scalability over time.
Elixir builds on top of Erlang/OTP to provide an excellent foundation for soft real-time applications. Elixir leverages lightweight virtual machine processes, often implemented as GenServers, that allow for encapsulation and modeling of the various components of a real-time system. It’s possible to scale Elixir applications to multiple cores without any particular constructs, just as it is simple to connect servers to form a cluster. This means that Elixir applications can scale up vertically on a single large machine, or horizontally to many devices, to meet different user profiles’ needs.
A phone example
For any real-time system, time matters the most, and such systems should have reliable isolation of data and isolated error handling.
A classic example to consider— andvery relevant to the Erlang ecosystem due to its history in telecom—is a phone system. When two people talk on the phone, we expect their conversation to be private (data isolation) and that their call will not end before they hang up. Two people talking on the phone should not be able to cause a crash of any other users, even if their call encounters a bug (error isolation). Data isolation and error isolation are handled for us, almost freely, by using separate OTP processes for different elements of our real-time system.
Elixir is a fantastic choice for developing real-time systems due to its Erlang/OTP and functional design usage. Still, it is possible to experience issues in an Elixir application when using a software design that doesn’t take advantage of Elixir’s strengths. Throughout this course, we’ll focus on clean OTP design to promote best practices and, ultimately, success with our application.
What is Phoenix?
Elixir is a great choice for developing real-time systems, but it is just a language. We’ll leverage several different Elixir libraries for building our real-time systems—the most important one is Phoenix.
Phoenix is a web framework written in Elixir that drives productive web application development.
One component of Phoenix that we will use for building real-time systems is Phoenix Channels.