In our previous blog post, Managing an Akka Cluster, we learnt how to manage an Akka Cluster via Akka Management. In this blog post, we are going to learn, how the Node(s) within an Akka Cluster communicate with each other via Gossip
Let’s Gossip

A very popular way to transmit a message is via Gossip 😛 . As it doesn’t need much effort and also helps in communicating messages quickly. Hence the Node(s) within an Akka Cluster communicate with each other via Gossip protocol.
What do the Node(s) Gossip about?
The nodes sends the information about their status(state) and whether they have heard(seen) the Gossip or not. Also, Node(s) keeps on Gossiping after a regular interval of time.
A Closer look at Gossip

While Gossiping, the Node(s) of the Akka Cluster maintains a record of the other Node(s) State and whether it has heard the Gossip or not.
Let us understand it with the help of the diagram above:
- Let’s assume that the Node 1 initiated the Gossip. As a result, it will mark the seen status as True.
- Now, when the Node 2 hears the Gossip from the Node 1, it will mark the seen status as True.
- And finally, when the Node 3 hears the Gossip from the Node 2, it will mark the seen status as True.
- However, when all the 3 Nodes have marked their seen status as True, the Convergence it achieved. It means that both – the Convergence and the seen status will remain same until a Node changes it’s state.
- For example, when Node 2 is going down due to some failure or crash, it will mark it’s seen status as False and marks the end of Convergence.
Note: The Gossip continues even after the Convergence is achieved. But Why?? Because any Node of the cluster can leave the cluster or any new Node can join the cluster. In any case, Gossip is important to know the state of the whole cluster.
Importance of Convergence
It is important that an Akka Cluster achieves Convergence, because of the following reasons:
- First reason is Leader selection. Until and unless a cluster attains Convergence, Leader node is not selected.
- In return a Leader node helps an existing node to leave the cluster or helps a new node to join the cluster.
However, Leader selection is a complex process in Akka Cluster, because each an every node decides whether it wants to become the leader or not. This might lead to a fight between the nodes to become the leader. But once a leader is selected, i.e., a Node decides to become the Leader, other Nodes rejects the choice to become the leader.
Different States of a Node

One of the important duties of the leader is to help a Node to change it’s state too which we can understand from the above diagram:
- When a Node Joins the cluster, the leader node helps it to set it’s state to Joining.
- Once all the existing nodes of the cluster has seen the new Node’s state as Joining, i.e., Convergence has reached, the Leader marks the new Node’s state as Up.
- However, when an existing Node of the cluster wants to leave the cluster, it will mark it’s state as Leaving.
- Once the Convergence has reached again, the Leader marks the leaving node as Exiting.
- At last, when the Convergence has been achieved again, the Leader marks the Exiting node as Removed.
Note: The states mentioned in the above diagram are unidirectional, i.e., a Node can move from Up to Leaving state, but not from Leaving to Up state. Hence, once a Node has decided to leave the cluster, it has to rejoin the cluster only after it has been Removed from the cluster.
Conclusion
So, now we know how the Node(s) within an Akka Cluster communicate with each other. In our future posts we will get to know about what happens in case of a Cluster Failure. So stay tuned 🙂
References
