Distributed algorithms are algorithms designed to run on multiple interconnected computers or nodes, rather than a single centralized system. These algorithms must coordinate the actions of the distributed nodes to achieve a common goal, while addressing challenges like communication delays, node failures, and the need for consistency across the system.
Characteristics of Distributed Algorithms
Distributed nodes must be able to communicate and coordinate their actions, often using message passing or shared memory. Algorithms must handle issues like message delays, lost messages, and asynchronous communication.
Many distributed algorithms require the nodes to reach consensus on certain decisions or agree on a common state.
Distributed systems can experience node failures, so algorithms must be designed to be fault-tolerant and continue operating correctly even when some nodes fail.
Distributed algorithms must be able to handle increasing numbers of nodes and scale to large-scale systems without performance degradation.
Distributed algorithms often need to balance the trade-offs between data consistency and availability, as described by the CAP theorem.
Types of Distributed Algorithms:
1. Consensus Algorithms:
These ensure that all nodes in a distributed system agree on a particular value or decision, even in the presence of failures.
Examples:
- Paxos: A classic consensus algorithm that is widely used in distributed databases and fault-tolerant systems.
- Raft: A consensus algorithm designed to be easier to understand than Paxos, often used for leader election and replicated state machines.
- Byzantine Fault Tolerance (BFT): Ensures consensus even when some nodes behave maliciously or unpredictably, often applied in blockchain and finance.
2. Leader Election Algorithms
These are used to select a unique leader among nodes to perform specific tasks, such as coordinating actions or managing resources.
Examples:
- Bully Algorithm: Nodes elect the leader based on their IDs. If a node with a higher ID joins, it can replace the current leader.
- Ring Algorithm: Nodes are arranged in a logical ring, and messages are passed around to elect a leader based on predefined rules.
3. Mutual Exclusion Algorithms
These ensure that only one process or node can access a shared resource at a time, preventing conflicts and inconsistencies.
Examples:
- Lamport’s Algorithm: Uses timestamps to establish an order of access requests to ensure mutual exclusion.
- Ricart-Agrawala Algorithm: An efficient algorithm where nodes send requests for resource access and wait for permission from other nodes.
4. Fault-Tolerant Algorithms
These enable the system to continue functioning correctly even when some nodes fail or experience issues.
Examples:
- Replication: Data is duplicated across multiple nodes to ensure availability in case of failures.
- Checkpointing: Periodically saving the state of a computation so that the system can recover from a failure.
5. Broadcast and Multicast Algorithms
These make sure that messages are sent reliably from one node to multiple nodes (broadcast) or from one node to a subset of nodes (multicast).
Examples:
- Flooding: A simple approach where each node receiving a message forwards it to all neighbors until it reaches all nodes.
- Reliable Broadcast: Ensures that all correct nodes receive the same message even if some nodes fail during communication.
6. Clock Synchronization Algorithms
These maintain a consistent sense of time across nodes in a distributed system, which is crucial for ordering events and preventing conflicts.
Examples:
- Network Time Protocol (NTP): Synchronizes clocks across nodes using dedicated time servers.
- Lamport Timestamps: Logical clocks to order events in distributed systems, without requiring precise time synchronization.
- Vector Clocks: A more complex form of logical clocks that track causal relationships between events.
7. Routing Algorithms
Used to determine efficient paths for messages to travel between nodes in a network, especially in large-scale or dynamically changing networks.
Examples:
- Distance Vector Routing: Nodes share routing information with neighbors to determine the shortest path.
- Link State Routing: Nodes maintain a complete map of the network and calculate optimal paths.
- Dynamic Routing Algorithms: Adapt paths based on real-time network conditions, such as in ad hoc and mobile networks.
8. Distributed Hash Tables (DHTs)
Allow nodes to efficiently store and retrieve key-value pairs in a distributed manner, enabling scalable lookup and storage.
Examples:
- Chord: Organizes nodes in a ring and distributes keys among them for efficient lookups.
- Kademlia: Uses XOR-based distance metrics to locate nodes responsible for storing a particular key.
9. Load Balancing Algorithms
Used to distribute tasks or data evenly across nodes to prevent overload on any single node and optimize resource usage.
Examples:
- Round Robin: Assigns tasks to nodes in a circular order, balancing load equally.
- Randomized Load Balancing: Distributes tasks randomly, often used in large-scale systems where fairness is less of a concern.
- Least Connections: Assigns tasks to nodes with the fewest active connections.
10. MapReduce Algorithms
Process large datasets by dividing tasks across multiple nodes, especially in data-intensive distributed applications.
Example:
- MapReduce: The core framework, popularized by Google, for parallel processing and aggregating large datasets.
In the next parts, we will be exploring each one of them in detail with hands-on of implementing a small system using them.




