I am considering Phoenix live views and I was wondering if there is a standard deployment pattern for a high availability deployment?
As each live view is connected to a client via a long-lived web client if I was running the server in a load balanced pair how would failover happen? In a stateless app server model requests would simply be routed to an active server in the cluster, but with phoenix individual state is tied to an individual instance. This feels like it would make recovery after a server failure harder. OTOH I may be over thinking it.
Any pointers to approaches people have used elsewhere much appreciated.
The LiveView state is ephemeral. If the LiveView crashes, then any data in the LiveView that was not persisted will disappear. So when it comes to failures, you don’t need any special setup at the proxy level because if you drop the WebSocket connection, LiveView will automatically reconnect, picking up another server.
Of course, the follow up question then is: how can you not lose this state in case of server failures? You and LiveView can do many things:
Forms are automatically recovered and resubmit on reconnection for you by LV
Make sure that navigation (changing tabs, opening modals, etc) are mirrored in the URL by using live navigation (live_patch, live_redirect)
Otherwise persist changes somewhere. To the database, to the browser session using hooks, etc.