GuSuku

GuSuku

I am new to Elixir and looking to run my distributed application (a state machine) on an elastic cluster. I want to know:

(a) If it is possible to migrate a process from one node to another, without losing the state of the actor or its messages (those in inbox and the one that is being processed).

(b) Are there good resources to follow or actively maintained libraries that I can look up for this purpose?

Some reasons when I would want to migrate could be when there is a severe imbalance in the load across nodes in the cluster (say, a new node got added to the elastic cluster) or when the application gets a notification that a particular node is about to go down.

Showing Posts 1 to 9

idi527

idi527

:waving_hand:

You might want to check out erleans and/or horde.

tty

tty

In migrating there are 3 things you need to consider:

  1. process state
  2. process registered name aka how do other processes still contact it
  3. messages in queue

Process state
You can place the state into a struct or map and have the new SM start_link with this state this would solve this issue.

Registered name
Either use global or have an internal name/process resolver to ensure current processes can still access the migrated SM.

Message in queue
This is a bit trickier. Before migrating you will have to dequeue the messages into a list and provide it to the new SM.

This is a common trick to always dequeue messages into an ets table and process off the table. This trick is typically uses for high transaction processes or for message reordering.

tristan

tristan

Rebar3 Core Team

I haven’t worked on erleans in a while (the company I developed it at is no more) but would like to again and to create an Elixir example or interface if it makes sense to offer some nicer abstractions when using in Elixir. And I suppose an ecto hookup for persistence would be good to do.

So it isn’t production ready but happy to help if anyone tries it out.

GuSuku

GuSuku OP

Thanks @idi527 (and @tristan !) - I will check out those libs

Thanks @tty. I will keep those in mind when evaluating solutions. On persisting messages: Is this the case only for inter-node migrations or is this pattern to be followed even when the process is restarted on the same node?

tty

tty

This technique can also be used to restart on the same node if it is important to retain those messages.

A comparable technique is to store state in Mnesia for node restart persistence (and distribution). When a process is started it checks Mnesia if there is a last state stored and spins up with that state. By relying on the distributed properties of Mnesia this process is now node agnostic.

tristan

tristan

Rebar3 Core Team

I wouldn’t use mnesia for distribution unless you have a very controlled environment (i.e. not the cloud).

amnu3387

amnu3387

:wave:
could you explain a bit on why

?

tristan

tristan

Rebar3 Core Team

Mnesia just was not built for such an environment where instances and the network are coming and going. I’m sure someone who has had the fun of attempting this would have better details than I can provide. The best I can do is link to Jesper’s post about it https://medium.com/@jlouis666/mnesia-and-cap-d2673a92850 which has some of the history behind Mnesia.

There are libraries to improve the situation, like Ulf’s unsplit which he discusses in this erlang-questions thread unsplit - resolving mnesia inconsistencies

tty

tty

I use mnesia because it comes with Erlang/Elixir. Substituting DynamoDB, or a RDMS is also possible. Might need to do term_to_binary and store a blob, however still very doable.

— All posts loaded —

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
I’m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
I’ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenix’s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews