Senior
Tell me about Cassandra: consistency, guarantees, features
sobes.tech AI
Answer from AI
Apache Cassandra is a distributed NoSQL database focused on high availability and scalability.
Consistency: Cassandra uses a tunable consistency model. You can choose the consistency level for read and write operations: from one node (ONE) to all nodes (ALL). This allows balancing between speed and strict consistency.
Guarantees:
- Eventual consistency by default, but strong consistency can be achieved by configuring read and write levels.
- Writes are idempotent, with a timestamp-based conflict resolution mechanism.
- Supports data replication with strategies like SimpleStrategy and NetworkTopologyStrategy.
Features:
- Column-oriented data model with dynamic columns.
- No rigid schema, providing flexibility.
- High fault tolerance through replication and automatic recovery.
- Uses Gossip protocol for state sharing between nodes.
- Supports CQL (Cassandra Query Language), similar to SQL.
Example of setting the consistency level in Java driver during a write:
session.execute(
new SimpleStatement("INSERT INTO users (id, name) VALUES (?, ?)", id, name)
.setConsistencyLevel(ConsistencyLevel.QUORUM));
Here, QUORUM means the write must be acknowledged by the majority of replicas.