r/AskComputerScience • u/goyalaman_ • Apr 05 '26
Rebalancing Traffic In Leaderless Distributed Architecture
I am trying to create in-memory distributed store similar to cassandra. I am doing it in go. I have concept of storage_node with get_by_key and put_key_value. When a new node starts it starts gossip with seed node and then gossip with rest of the nodes in cluster. This allows it to find all other nodes. Any node in the cluster can handle traffic. When a node receives request it identifies the owner node and redirects the request to that node. At present, when node is added to the cluster it immediately take the ownership of the data it is responsible for. It serves read and write traffic. Writes can be handled but reads return null/none because the key is stored in previous owner node.
How can I solve this challenge.? Ideally I am looking for replication strategies. such that when new node is added to the cluster it first replicates the data and then starts to serve the traffic. In the hind-sight it looks easy but I am thinking how to handle mutation/inserts when the data is being replicated?
More Detailed thoughts are here: https://github.com/goyal-aman/distributed_storage_nodes/?tab=readme-ov-file#new-node-with-data-replication
2
u/EternalStudent07 Apr 07 '26
I believe this is just a DHT (Distributed Hash Table), right? There are a number of well thought out algorithms you should probably pick one of and reuse.
Like...
https://en.wikipedia.org/wiki/Kademlia
Can't say it's the best, or the best for you... but I didn't see a big pointer to the obviously better v2 algorithm either. There are a few that were submitted around the same time...
https://en.wikipedia.org/wiki/Content-addressable_network https://en.wikipedia.org/wiki/Chord_(peer-to-peer) https://en.wikipedia.org/wiki/Tapestry_(DHT) https://en.wikipedia.org/wiki/Pastry_(DHT)
In your example... you'd need to add an ownership shifting action. Meaning the new node must get copies of any existing data from the old owners, and then new requests need to go to the new owner.
You didn't explain how nodes decide what data they'll own. Or how the various nodes magically know who "owns" a record.
Or what behavior you expect for transactions (overlapping operations). Where you read the old value, change it, then write the same data entry. If 2 clients were doing that they might both think they incremented something, but it only happened once. Read, read, change x 2, write, write but only see 1 "change" happened.
2
u/teraflop Apr 05 '26
If you care about consistency, meaning you want your system to reliably serve up-to-date results, then there are protocols like Raft that will provide it. Raft is a lightweight protocol, so you can just run a Raft instance per shard.
This is straightforward to handle in a log-based replication scheme such as Raft. Writes are logged in a stable order, so the protocol guarantees that a new replica will not be added until it has seen all prior writes, including ones that happened while it was in the process of joining the cluster.