I was reading about the Protocol for distributed consensus and came across the Paxos. It states that you require Paxos for the leader election. Article claiming the same. So, my question is when Cassandra is a ring architecture not master-slave why does it need a leader election mechanism. Moreover, if the answer is yes what is the role of leader in the Cassandra ring. When Gossip protocol is used for communication in the ring.
Why Paxos is required for leader election in cassandra
2k views Asked by Naresh AtThere are 2 answers
The leader election system is only used for Light weight transactions. Light weight transaction allow the user to get isolation for the price of performance.
Consider the following example: A system manages money for users. Let us say one user wants to insert 100$ into an account.
Current balance (0$) + new money (100$) = 100$.
Another user wishes to update the same account. He inserts 20$ into that account. His calculation happens before the first person insert his money.
Current balance (0$) + new money (20$) = 20$.
One would expect that the balance after the two insertions of money would be 120$. However, without the leader election, one write will overwrite the other and you will either be left with 100$ or 20$ depending on which write finishes last.
Leader election allows nodes to synchronize their updates on a single resource to make sure that each calculation is isolated. "I will update the value if it is 0$" The election is done so that one node can coordinate the transaction for a particular request.
In our example, the 100$ will be updated but the 20$ will fail and the user will need to try again.
Keep in mind that this leader architecture is distinctly different from master/slave architecture. There is no single point of failure in this as the leader could be any node for a particular request.
More on this topic you can find here.
The article demonstrated an example of implementing leader election algorithm using Cassandra's feature called Light weight transaction. Its not about electing a master node for Cassandra.