zenchild

zenchild

Libcluster-dynamic-srv - Clustering with SRV and Dynamic Ports with Custom EPMd

Announcing libcluster_dynamic_srv: Dynamic Port Clustering for Elixir

I’ve been working on a way to cluster Elixir nodes in dynamic environments without needing to set static ports. This work was heavily inspired by the Caravan package, but differs in one key way: you don’t need to specify a port in the node name. The port can be completely dynamic and is discovered using DNS SRV records. It also has a libcluster DNS strategy for clustering with the SRV records. It is very similar to the K8s strategy in the core libcluster library, but is a bit more flexible around service naming.

I’m currently using this with Nomad and Consul, and I’ve also created a demo lab that uses Docker + Consul if you want to play around with it.

How It Works

Unlike traditional Elixir clustering approaches that require fixed ports, this library leverages DNS SRV records to discover both the host and port information for each node. This makes it perfect for containerized environments where ports are often dynamically assigned.

Future Possibilities

This approach should also work with Kubernetes, though I’m not as experienced with K8s. If someone is interested in exploring this integration, I’d love any feedback on the approach or contributions to the examples folder!

Cheers,
Dan Wanek

Links

https://github.com/ElixirOSS/libcluster-dynamic-srv

Most Liked

zenchild

zenchild

Moving to 1.0.0

We’ve been using this library for awhile now and things have been stable so I’ve decided to move it to 1.0.0. This version does have some clean-up and fixes a DNS polling issue we discovered, but it is backward compatible with pre-1.x configurations.

Changelog

Fixed

  • Replace double poll scheduling with handle_continue/2 to ensure a single, clean poll chain
  • Use handle_continue(:poll, state) for initial poll instead of calling do_poll/1 directly in init/1
  • Add catch-all clause in get_nodes/1 to handle unexpected resolver responses without crashing
  • Fix regex character class [a-z0-9-_] to [a-z0-9_-] to avoid ambiguous range matching

Added

  • Test coverage for unexpected resolver responses
  • Test coverage for SRV records with non-matching hostname formats
  • Test coverage for missing :service config
  • Test coverage for meta: nil initialization path
  • Test coverage for self-exclusion from the node list
  • Test coverage for recurring polls after the initial poll

Links

Github | Docs | Hex

zenchild

zenchild

Version 1.1.0 Released

We’ve recently added a few things to make libcluster-dynamic-srv work a little more consistently in production environments. Some notable things from the changelog are listed below.

Changelog

Added

  • disconnect_on_deregister config option (default true). When set to false, nodes that disappear from DNS but still have a live distribution connection are left connected and only removed once the connection drops naturally. This prevents spurious :global partition-prevention cascades during graceful shutdowns that use a deregistration delay.

Fixed

  • DynamicSrv.Epmd.address_please/3 now returns {:error, reason} instead of crashing when DNS resolution fails (e.g. :nxdomain). The distribution layer handles this as a failed connection attempt rather than a process crash.
  • Enable EDNS(0) (edns: 0) on all :inet_res.lookup/4 calls in both the clustering strategy and the EPMD module. Many modern DNS resolvers (e.g. Consul, CoreDNS) require EDNS(0) to return full SRV responses over UDP; without it, lookups could silently return empty or truncated results and cause cluster discovery failures.

Where Next?

Popular in Announcing Top

alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
mischov
import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story <- Meeseeks.all(html, css("tr.athing")) do...
New
Crowdhailer
Raxx is an alternative to Plug and is inspired by projects such as Rack(Ruby) and Ring(Clojure). 1.0-rc.1 is now available. To use it re...
New
mspanc
I am pleased to announce an initial release of the Membrane Framework - an Elixir-based framework with special focus on processing multim...
New
tmbb
I’ve decided to create this topic to discuss optimization possibilities for something like Phoenix LiveView. I’ve created this topic unde...
144 10789 141
New
kevinlang
Hey all, We have made an Ecto3 Adapter for SQLite3, ecto_sqlite3! We have successfully on-boarded the full suite of integration tests (...
New
brainlid
LangChain is short for Language Chain. An LLM, or Large Language Model, is the “Language” part. This library makes it easier for Elixir a...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
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
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New

We're in Beta

About us Mission Statement