Database / Apache Cassandra Intermediate and Advanced interview questions
What is consistent hashing and how does Cassandra use it?
Consistent hashing is the technique that lets Cassandra distribute data across nodes so that adding or removing a node only reshuffles a small fraction of the data, instead of the entire dataset.
- Cassandra arranges a hash space (from 0 to a maximum value) into a logical ring.
- Each node is assigned one or more positions (tokens) on that ring.
- A partition key is hashed by the partitioner into a token, and the row is stored on the node whose token range contains that value, walking clockwise around the ring.
- Replicas for that partition are simply the next N‑1 distinct nodes further around the ring, where N is the replication factor.
Without consistent hashing, a naive hash(key) % number_of_nodes scheme would remap almost every key whenever a node was added or removed, forcing a massive, disruptive data shuffle. Consistent hashing bounds that disruption to only the token ranges actually adjacent to the change, which is what makes elastic scaling practical in Cassandra.
Invest now in Acorns!!! š
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
