What is Cassandra's secondary index and materialized view?
Answer
Cassandra has limited support for querying non-partition-key columns. Secondary indexes: CREATE INDEX ON users (email);. Allows querying by email without the partition key. Warning: secondary indexes in Cassandra are not like SQL indexes. They are distributed — each node maintains an index for its local data, so a query hits all nodes. Avoid secondary indexes in production for high-cardinality columns (many unique values) or low-cardinality columns (few distinct values, huge results). They cause cluster-wide queries. Materialized views (MVs): pre-computed tables derived from a base table with a different primary key. Example: if the base table has PRIMARY KEY (user_id), a MV can have PRIMARY KEY (email, user_id) — enabling queries by email. Cassandra maintains the MV automatically on writes. Warning: MVs have performance implications — each write to the base table triggers a write to the MV. They have known issues with eventual consistency and are considered experimental by some. Prefer manually maintaining duplicate tables (query tables) over MVs for production use.
More RabbitMQ & Cassandra Questions
View all →- Intermediate How does Cassandra's read path work?
- Intermediate What is Cassandra's compaction and its types?
- Intermediate What are RabbitMQ's quorum queues?
- Intermediate How do you model time-series data in Cassandra?
- Intermediate What is Cassandra's consistency vs availability trade-off with tunable consistency?