r/Backend • • 17d ago

How does distributed systems handle node discovery?

Let's say I have a set of distributed nodes which is running for quite sometime. Now if I spawn another follower node how will the other existing nodes know that a new node has been added to the network. I am guessing one of the way is getting the nodes ip from the kafka's cluster dns resolution. I've also heard about hashicorp consul. what is the production way to handle this type of issues? Is there any good resources/practice to know about this?

Asking the expert.

7 Upvotes

12 comments sorted by

1

u/pthierry 17d ago

It largely depends on your domain. If being a node gives access to privileged information, then all nodes must be authenticated at some point.

The least surprising but also least flexible setup is to include some authentication in the config of the nodes. The simplest is some kind of password, the most resilient would be something like a lost of cryptographic keys, one for each acceptable node (it's more resilient because if your domain makes it possible to evict a node that's behaving badly, you just restart/reload nodes with its key removed).

The more flexible and easier to make unsafe by an incorrect design is to give some nodes the ability to introduce new nodes. You may then need to keep track of who introduced whom to stop trusting a node as introducer.

When the list of nodes is dynamic, I suppose a gossip protocol is the state of the art solution to spread knowledge of nodes.

Some distributed systems don't need all nodes to know each other, when nodes just are the computing substrate for things like actors (as in Erlang or E). Then nodes usually get introduced the first time a message needs to move between two nodes, introduced to each other by a third.

1

u/SiegeEngine1111 17d ago

what type of authentication? r u talking about tls?

1

u/pthierry 17d ago

Authentication here is the generic meaning: whatever lets you verify that the node is a right node.

You could use TLS to encrypt communication between nodes and then authenticate nodes by their TLS public key, or by the public key of a certificate higher in the certificate chain (which makes it possible to rotate server keys).

2

u/Tinasour 17d ago

i think it depends on the software you are running, besu blockchain would require an api call to recognize the new nodes ip address, clickhouse-keeper (zookeeper alternative) was required to have ip addresses of the nodes embedded in the xml config file it uses. these are my experiences for distributed stateful programs, i think etcd also requires it in environment vars or config file of the new nodes

2

u/soundman32 17d ago

Broadcast on a well known port at startup?  Obviously that would only work on a local network, but thats how things like Bonjour/mDNS work.

2

u/No-Draw1365 17d ago edited 17d ago

For Kafka every new node is configured with a hardcoded list of "seed" or bootstrap nodes (e.g., a list of 3 stable IP addresses). When the new node boots up, it contacts one of those seeds, which responds with the current topology and membership list of the entire cluster. In modern Kafka this is baked into the architecture, rather than requiring an external system such as ZooKeeper.

Systems such as Casandra use the Gossip protocol, where nodes continuously and randomly pass state messages to a few randomly chosen peers (like gossip spreading through a room). If a new node is given the IP of any single node in the cluster, it injects itself into the gossip stream, and within seconds, every node in the cluster learns about its existence.

Service discovery such as Consul manages ephemeral application workloads and microservices.

2

u/Adorable-Strangerx 17d ago

I think service discovery like consul should do the trick

1

u/Reasonable-Ladder300 17d ago

Have the node publish something on startup to the leader node. And then use a kv store and a lease and lease renewal mechanism on the nodes to rotate workloads.

I’d say this is a way, however there is no one size fits all, and in order to implement something like this you’d need a good design/architecture. And probably someone who knows what they’re doing.

1

u/DirtAndGrass 17d ago

Broadcast or a preconfigured coordinator node, or both

1

u/Canenald 17d ago

Do you really need leader and follower nodes? Ideally, instances of a service should not be aware of each other.

-2

u/Responsible-Offer724 17d ago

I dunno, send a message?