Distributed Shortest-Path Bellman Ford Algorithm in Distributed Systems



454 views Distributed Systems



Determining the shortest path in a distributed system is an important problem to address and it finds its application across multiple use cases like

  • delivering messages to a node efficiently
  • efficient routing of messages

A key point to consider here is the fact that “shortest” is not only about the distance, but it can also be about the congestion, time, cost of communication lines, cable infra, and much more.

Problem statement

In a distributed network, where nodes are connected via paths/edges having some weight assigned, find the shortest path from a specific source to all the nodes

Bellman-Ford Algorithm in Distributed System

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.

Because it is a distributed network no node knows the entire topology and weights. They just know

  • total number of nodes
  • their immediate neighbors, and
  • the weights of the edges incident on it.

Every node keeps track of dist which holds the shortest distance to it from the source i0. Initially, dist at i0 will be 0 and dist at all other nodes will be inf.

At every round, all the nodes will send their dist across all of their outgoing edges to their neighboring nodes. Every node i upon receiving an incoming dist from its immediate neighbor j compares

  • its own dist
  • incoming dist + weight(i, j)

after comparing, if the incoming distance plus the weight of the connecting edge is smaller than its own dist it means that the distance from i0 to the current node could be shorter and hence, the node updates the parent suggesting that the shortest path from i0 to i goes through j.

After n - 1 rounds, the dist at every node will contain the shortest distance to it from source i0, and the parent will contain one of its immediate neighbors that lies in the shortest path.

Complexity Analysis

We require n - 1 rounds to complete the algorithm, the time complexity of Bellman-Ford Shortest Path in Distributed System is O(n). At every round, every node sends dist message across all of its edges to its immediate neighbors, the communication complexity becomes O(n x |E|).


Arpit Bhayani

Arpit's Newsletter

CS newsletter for the curious engineers

❤️ by 17000+ readers

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.




Other essays that you might like


Two Phase Commit to power Distributed Transactions in a Distributed System

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 ...

Exponential Information Gathering (EIG) Algorithm for Byzantine Agreement

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...

Exponential Information Gathering (EIG) Algorithm - Distributed Consensus even when processes crash

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? ...

FloodSet Algorithm - Distributed Consensus even when processes crash

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 ...


Be a better engineer

A set of courses designed to make you a better engineer and excel at your career; no-fluff, pure engineering.


System Design Masterclass

A masterclass that helps you become great at designing scalable, fault-tolerant, and highly available systems.

800+ learners

Details →

Designing Microservices

A free playlist to help you understand Microservices and their high-level patterns in depth.

17+ learners

Details →

GitHub Outage Dissections

A free playlist to help you learn core engineering from outages that happened at GitHub.

67+ learners

Details →

Hash Table Internals

A free playlist to help you understand the internal workings and construction of Hash Tables.

25+ learners

Details →

BitTorrent Internals

A free playlist to help you understand the algorithms and strategies that power P2P networks and BitTorrent.

42+ learners

Details →

Topics I talk about

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.



  • v12.7.8
  • © Arpit Bhayani, 2022

Powered by this tech stack.