hiramegl
Does Phoenix works fine in a containerized environment (since is stateful)?
Hi everyone,
First of all, sorry if I’m making a very silly question that maybe is answered in the documentation.
I’m planning to evaluate Phoenix in a micro-frontends architecture.
I’ve started to check the free Phoenix-LiveView tutorial at LiveView Course | The Pragmatic Studio
From what I understood Phoenix creates a stateful LiveView process in the backend that updates small chunks of the state through web-socket calls.
That sounds like a great idea but my concern is if I want to use Phoenix with containers that are deployed in a Continuous Delivery fashion. Would that play fine with the stateful LiveView processes?
I’m thinking of a deployment chain where a new image is created and deployed in a new container, and afterwards the current container is swapped with the new container. I’m afraid that would effectively make the states from the current container get lost. Or is it possible to copy them to the new container?
Perhaps I’m getting it all wrong and Phoenix is not supposed to be used with containers or maybe one just should be fine with losing the state when swapping.
Or is there any other way to use Phoenix in a containerized & CI environment?
Thank you for your help beforehand,
Best regards,
/Hiram
Most Liked
rhcarvalho
The toast is customizable, it is stored in your project code in core_components.ex – look for def flash and def flash_group in that file to see how it is implemented.
You can change how it looks, and how it behaves.
There’s a thread here on this forum where we’re discussing how to delay this “trying to reconnect” message to possibly avoid it quickly flashing in and out during a redeploy or when a tab wakes up from sleep.
I recall now the main point of this thread, and so wanted to add that while Phoenix and LiveView can fit such an environment, you may get into a position in which some useful things become harder to use.
I understand by “micro-frontends architecture” you mean different parts of a single user-facing webpage is composed of multiple frontend projects, possibly using different stacks, and not relying on iframes but rather sharing a single DOM. Is that what you mean?
In that case, unless Phoenix is driving the outer shell of the app, a few things off the top of my head become harder to integrate:
- Consistent notifications such as those flash messages
- Presence and PubSub
- Backend controlled SPA-like navigation
- Possibly more
That, plus the complexity of managing the multiple frontend projects, but then you probably have some other driving factors for opting into that architecture?
In any case, happy to help!
PS: another piece of knowledge that might be super useful is understanding your options regarding state management (client side and server side). Here’s an excellent post by José Valim, Elixir’s creator: Web apps have client and server state (plus realtime and LiveView) - Dashbit Blog
rhcarvalho
Hmm I think the previous posts didn’t mention that LiveView has a built in mechanism to recover form state, which I think is exactly what you are looking for:
Tl;dr give an id and phx-change to your forms, and the framework will automatically get things back on track once the “old container” is gone, as the client resends state to the “new container”.
al2o3cr
This is a generic problem with restarting/replacing containers that are serving websockets - replacing a container means reconnecting things.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









