568 views • Distributed Systems
Breadth First Search is a critical algorithm in Distributed systems as it powers key features like
In this gist, we discuss a synchronous approach which means every node moves forward in the algorithm in sync. There are ways to achieve this, but the implementation of synchronous behavior is out of the scope of this gist.
The output of this traversal is a Breadth-First Directed Spanning tree that covers all the nodes but a subset of edges. This output is important because we can use this spanning tree as a foundation for other applications and algorithms.
i0 initiates the BFS and it sends the
search message to its neighbors. The nodes can either be marked or unmarked. If marked, they are part of the spanning tree already.
When an unmarked node receives the
In the next round, the nodes that received the message in the previous round participate, and send
search messages to their neighbors, and the nodes receiving the messages do the needful.
Eventually, every node will be receiving the
search message from some or the other node and will be part of the spanning tree.
Time taken to complete the BFS is proportional to the diameter of the network and the number of messages exchanged will be equal to the number of outgoing edges in the network.
With the current algorithm, every node knows its parent in the spanning tree but every node also needs to know which of its neighbors are its children in the spanning tree.
To achieve this, each node has to respond to the
search message with a
parent/non-parent message that tells the node if it was chosen to be the parent or not. This way, every node will know its parent and children in the spanning tree.
The most important part of any distributed algorithm is its termination. How would the node know that BFS is done?
The approach we use is called Convergecast.
The idea is to respond to the search message only when it received responses from all its children. This ensures that the node initiating the BFS would receive the messages from its children only after all the nodes respond to their corresponding parents.
After constructing the BFS Spanning Tree, we can use this constructed path to
If you like what you read subscribe you can always subscribe to my newsletter and get the post delivered straight to your inbox. I write essays on various engineering topics and share it through my weekly newsletter.
618 views • 28 likes • 2022-09-16
Distributed Transactions are the heart and soul of Distributed Systems and getting all the participating nodes to agree ...
379 views • 16 likes • 2022-09-14
Byzantine Agreement is an important problem to address in a Distributed Network. It is all about being tolerant of the n...
245 views • 6 likes • 2022-09-12
Exponential Algorithms have to be the worst possible way to solve Distributed Consensus; but are they really that bad? ...
432 views • 14 likes • 2022-09-09
Reaching a consensus is extremely critical in a Distributed System as we would have situations day-in and day-out where ...
A set of courses designed to make you a better engineer and excel at your career; no-fluff, pure engineering.
Being a passionate engineer, I love to talk about a wide range of topics, but these are my personal favourites.
Arpit's Newsletter read by 17000+ engineers
🔥 Thrice a week, in your inbox, an essay about system design, distributed systems, microservices, programming languages internals, or a deep dive on some super-clever algorithm, or just a few tips on building highly scalable distributed systems.
Powered by this tech stack.