hubertlepicki

hubertlepicki

So I have been investigating the feasibility of employing Erlang’s native distributed application architecture (Distributed Applications — Erlang System Documentation v29.0.2) for a project. I have done some research but I do lack hands on experience.

I am mostly interested in built in failover and takeover mechanisms, I think it will work just fine in my case. The problem are network splits.

I will be running the cluster in the cloud (EC2) and, I am afraid, the connectivity between those two nodes is not as guaranteed as it would be if the nodes were connected by a physical cable in the same date center. The connectivity will and does go down on occasion. The default dist_ac’s behavior is less then ideal:

  • nodes disconnect from each other
  • they keep running as if they were single nodes in the cluster.

To make things even worse, re-joining the cluster afterwards does not resolve the situation and failover / takeover no longer take effect.

I can detect that a node was disconnected from the cluster, but that’s about it I can do. I can’t find a way to recover from this situation - other than shutting down and starting the whole cluster from scratch.

Any recommendations you may have?

Showing Posts 1 to 10

CptnKirk

CptnKirk

Split brain scenarios like these are a problem for stateful distributed systems. The dirt simple solution is to detect a split by detecting that your current cluster only has < (total / 2) + 1 nodes in it. If so, you’re on the wrong side of the split. Shut yourself down, let something like heart start you back up. Then wait to rejoin the cluster using the normal cluster joining rules you’ve defined for your app.

A more complicated solution might involve only shutting down the request processing tree of processes responsible for handling reqs that could cause damage. Leaving a stateless tree open for better administration and triage.

cs-victor-nascimento

cs-victor-nascimento

The biggest problem about distribution is state. If your cluster needs a distributed state (which is not always the case) then you will probably need some distribution strategy.

For example, if you want the state of the cluster to be always available, then every time something gets written to that state, you would replicate it. Then you would probably meed a consensus algorithm (raft, paxos), a distributed hash ring and other tricks to have everything stable. This is the case for something like Lasp or Riak Core.

But, if you can save your state in a DB (even your cache, authentication and whatnot) then that state is not your application worries. So, that is why there is no ready available solution for all use cases.

CptnKirk

CptnKirk

All true, but none of that works if you can’t detect changes in topology. Especially for split-brain situations where you might double-owner yourself and start to corrupt that shared DB. It sounds like he’s having problems at that level. Getting the join/leave master election stuff working.

cs-victor-nascimento

cs-victor-nascimento

Yep you are right! My first read led me to believe this was the first step that would eventually end up on the distributed state problem. But, that may not be the case \o/

slashdotdash

slashdotdash

You can use the Swarm library which provides a distributed process registry. I contributed changes to make it CP, rather than AP, so that it remains consistent during a network partition. This is achieved by using a static quorum distribution strategy as described by @CptnKirk. These changes have not yet been published to Hex and are available from the master branch in GitHub only. I plan to ask Paul to release v3.1.

During a network partition, processes are redistributed so that only one instance of each named registered process is running on the cluster. Those on the wrong side of the split are stopped. When the cluster reforms the processes are redistributed and you can handle migrating process state per GenServer (discard, hand-off, etc.).

hubertlepicki

hubertlepicki OP

Yes, I’m not looking at it from distributed state point of view at all just yet. As I originally pointed out, the objective is being able to fail over to backup nodes and recover from failure.

My current thinking is that the built-in dist_ac is not suitable for any cloud-based deployment, as it was designed for co-located servers. It does not handle well network splits, resulting in brief freezes of nodes when it happens, and then can’t re-join on it’s own the cluster and restore the topology of apps running on top of the cluster.

I am experimenting now with @bitwalker 's libcluster, as a low-level cluster manager. libcluster — libcluster v3.5.0 with possibly swarm running on top, or a custom solution. I’d need to implement EC2 clustering strategy, I think too.

slashdotdash

slashdotdash

Someone’s written an EC2 cluster strategy for libcluster: GitHub - kyleaa/libcluster_ec2 · GitHub

hubertlepicki

hubertlepicki OP

perfect, thank you :).

If I go with Swarm, I’d have to make some architectural changes, however. Unit that’s being distributed across nodes is in this case process, versus OTP application.

I also can’t seem to find a way to make nodes specialized. For example, I want to run my web app on on some nodes and my heavy worker processes that crunch numbers on others. If I understand Swarm correctly, I’d run everything on all nodes, or create separate clusters for web interface and worker backend.

slashdotdash

slashdotdash

Swarm doesn’t support node specialisation, but that seems like a good feature to build. You could have configuration mapping a named cluster type (web, worker) to individual cluster config and then specify the type when starting up a registered a process.

Currently you would need separate clusters to restrict where processes can run.

cs-victor-nascimento

cs-victor-nascimento

One point to take into consideration here is: BEAM is really, really good at keeping everything responsive under stress. I mean, let’s say you start a heavy worker process that distributes the load in your cluster and starts competing for resources with your web app. The impact on response times for, say, REST calls wouldn’t be big. That’s because the BEAM is one of the single preemptive scheduling systems I’ve ever seen. Depending on the feature, you could just use this fact and just distribute the load in your cluster for all your process just the same.

I have no links to point you to but I’ve personally done some synthetic benchmarks comparing the BEAM and Node.js under stress. Suffice to say that BEAM under load (response times under heavy loads of requests) beats node pretty badly once the machines are on 90% percentile (even a little lower than that). BEAM had practically the same response times up until 99% of stress.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
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
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
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
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
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
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews