One of the places where Elixir and Phoenix leave the competition in the dust is support for soft real time programming. The ability to keep a lightweight Elixir process running for the duration of a user's time in our app, and holding some small amount of state, makes our world far simpler for certain things than it otherwise would be.
Real TimeChannel Basics
Phoenix Channels are a first class citizen in the framework, on equal footing with Controllers. It shows! You'll be amazed at how easy it is to start adding real-time features to your apps, where we push data from server to client.
Development best practices are increasingly moving in a functional and "stateless" direction, but Elixir Processes are a place where small pieces of state can be safely held and used. We'll explore how powerful this idea is, in the context of Phoenix channels.
Real TimeManaging Channel Complexity
While you may have contributed to a REST API project that had 10 endpoints (each handling 1-4 HTTP verbs), it's less likely that you have experience working with a long-lived web socket connection operating on the same scale of complexity. It's important to remember that this is API surface, and because it's often stateful instead of stateless, keeping organized is even more important.
Real TimeEXERCISE: Push Notifications
We have a need to instruct consumers of our API to render a notification on their screen. Broadcast a notification object to all users subscribed to the
notifications:allchannel, consisting of a type and a body.
Break for Lunch