Fly.ioProblem & solution
Launching Livebook using LiveView
Summary
Fly.io’s Livebook launcher uses a single LiveView process to deploy a Livebook instance, but temporarily held deployment secrets could be lost when a user refreshed the browser or the server restarted. The secrets, including liveview_password, were sent to deployment and stored in Vault, so the values could not be retrieved; keeping them in a database or Redis also conflicted with avoiding persistent server-side storage. The implementation encrypts the private state with Phoenix.Token.encrypt/4, stores the resulting blob in browser SessionStorage, and uses LiveView hooks and websocket events to restore it through Phoenix.Token.decrypt/4. After recovery, the UI resumes tracking deployment progress, then clears the cached data when deployment succeeds or fails, while closing the tab also clears SessionStorage.
Context
The launcher kept private, temporary deployment data only in a LiveView process. A browser refresh, connection problem, or server deployment or restart could cause the UI to lose secrets needed to display the deployment information at the end. A database or Redis server was considered, but retaining that data on the service was undesirable.
Approach / What changed
The implementation encrypts the private deployment data with Phoenix.Token.encrypt/4 and stores the encrypted blob in the browser’s SessionStorage. LiveView hooks handle store, restore, and clear events between the server and browser. On reload or server restart, the browser sends the data back, the server decrypts it with Phoenix.Token.decrypt/4, and deployment tracking resumes.
Takeaways
Phoenix.Token.encrypt/4 both signs the deployment data to prevent tampering and encrypts its contents to keep them private.
LiveView hooks use websocket events to store encrypted state in SessionStorage and push it back to the server for restoration.
Cached state is removed from SessionStorage after deployment success or failure, and closing the browser tab clears the session storage as well.
Source and freshness
- Source
- fly.io
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.