Database / Apache Cassandra Intermediate and Advanced interview questions
What is token awareness in Cassandra drivers?
Token awareness is a driver-side optimization where the client library computes, on its own, which node actually owns a given partition — before sending the request — instead of connecting to an arbitrary node and letting it coordinate.
- The driver maintains a local copy of the cluster's token ring and replication metadata.
- Given a partition key, it hashes it the same way the server's partitioner would, then sends the request directly to a node that's actually a replica for that token.
- This removes an extra network hop: without token awareness, a request might land on a non-replica node that then has to forward it to the real replica and wait for the response.
Cluster cluster = Cluster.builder() .addContactPoint("10.0.0.1") .withLoadBalancingPolicy( new TokenAwarePolicy(new DCAwareRoundRobinPolicy())) .build();
Token awareness is usually combined with datacenter awareness, so the driver also prefers replicas in the local datacenter to avoid unnecessary cross-region latency. Most modern official drivers (Java, Python, DataStax drivers) enable token-aware routing by default.
More Related questions...