Implement a wide column store like Cassandra (bonus : support secondary indexes).
MediumLet's dive into building a simplified version of a Wide Column Store, similar in concept to Cassandra. A Wide Column Store differs significantly from relational databases. Instead of rows with predefined columns, it uses column families that group related columns together. Think of it as a map of maps - a keyspace containing column families, which contain rows, which contain columns. Each row can have a different set of columns, adding flexibility.
This implementation will include support for secondary indexes, a crucial feature for querying data efficiently based on values other than the primary key. Without secondary indexes, you'd need to scan the entire table, which is a performance killer in large datasets.
Imagine storing user profile data. A column family might be users. Each row would represent a user, keyed by user_id. Columns could include name, email, age, city, etc. With a secondary index on city, you can quickly find all users in a specific city.
This problem focuses on the in-memory data structure representation, how to handle concurrent operations, and the design of secondary indexes. The core challenge lies in maintaining the consistency and integrity of the indexes when data is updated or deleted. We will simulate the database behavior in memory for the purpose of this problem.
Requirements
Think like an Architect
Before revealing the requirements, imagine you're in the interview right now."How would you clarify the scope with your interviewer?"