Skip to content

A go program simulates a gossip algorithm for communication between nodes in a distributed system. The implementation, inspired by system design principles book, introduces features such as dynamic gossip intervals, simulated network delays, and handling unresponsive nodes.

Notifications You must be signed in to change notification settings

Mohamed-khattab/simple-gossip-SIP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gossip Algorithm Simulation in Go

Overview

This Go program simulates a gossip algorithm for communication between nodes in a distributed system. The implementation, inspired by system design principles book, introduces features such as dynamic gossip intervals, simulated network delays, and handling unresponsive nodes.

Node Structure

The Node structure encapsulates essential properties of a gossip node:

type Node struct {
    ID        int
    Data      string
    Peers     map[int]*Node
    mutex     sync.Mutex
    gossipLog []string
}

Gossiping

The Gossip method initiates the gossip process, asynchronously sending data to all peers, simulating network delays, and handling unresponsive peers.

func (n *Node) Gossip() {
    // ... (see code)
} 

Simulating Delays

Methods like simulateNetworkDelay and simulateProcessingDelay introduce random delays to simulate network and processing delays.

 func (n *Node) simulateNetworkDelay() {
     // ... (see code)
 }
 
 func (n *Node) simulateProcessingDelay() {
     // ... (see code)
 }

Handling Unresponsive Nodes

The system can handle unresponsive nodes by notifying other peers and implementing a method to handle notifications.

func (n *Node) notifyPeersAboutUnresponsiveNode(unresponsiveNodeID int) {
    // ... (see code)
}

func (n *Node) HandleUnresponsiveNode(unresponsiveNodeID int) {
    // ... (see code)
}

Main Function

The main function orchestrates the simulation, loading environment variables, creating nodes, establishing peer connections, and simulating gossiping over a specified duration.

func main() {
    // ... (see code)
} ```

## Logging
The writeLogToFile method writes the gossip log for each node to an external file.

```go
func (n *Node) writeLogToFile() {
    // ... (see code)
}

Acknowledgment

This implementation is part of a learning project aimed at applying concepts learned from the system design book. The code is specifically written in Go to gain a deeper familiarity with the language and to practically implement various design principles discussed in the system design book.

About

A go program simulates a gossip algorithm for communication between nodes in a distributed system. The implementation, inspired by system design principles book, introduces features such as dynamic gossip intervals, simulated network delays, and handling unresponsive nodes.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages