Akka Cluster in use (Part 5): Let’s stay in touch via Gossip

Reading Time: 3 minutes

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

Let’s stay in touch via 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

Nodes Gossiping

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:

  1. Let’s assume that the Node 1 initiated the Gossip. As a result, it will mark the seen status as True.
  2. Now, when the Node 2 hears the Gossip from the Node 1, it will mark the seen status as True.
  3. And finally, when the Node 3 hears the Gossip from the Node 2, it will mark the seen status as True.
  4. 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.
  5. 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:

  1. First reason is Leader selection. Until and unless a cluster attains Convergence, Leader node is not selected.
  2. 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

Cluster Membership Cycle

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:

  1. When a Node Joins the cluster, the leader node helps it to set it’s state to Joining.
  2. 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.
  3. However, when an existing Node of the cluster wants to leave the cluster, it will mark it’s state as Leaving.
  4. Once the Convergence has reached again, the Leader marks the leaving node as Exiting.
  5. 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.


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 🙂


Written by 

Himanshu Gupta is a software architect having more than 9 years of experience. He is always keen to learn new technologies. He not only likes programming languages but Data Analytics too. He has sound knowledge of "Machine Learning" and "Pattern Recognition". He believes that best result comes when everyone works as a team. He likes listening to Coding ,music, watch movies, and read science fiction books in his free time.