hiramegl

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

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

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

al2o3cr

This is a generic problem with restarting/replacing containers that are serving websockets - replacing a container means reconnecting things.

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New

Other popular topics Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39467 209
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement