advancedTop 30 Scenario-Based Questions

Design a Cassandra schema for storing user activity events with the ability to query: 1) All events for a user in the last 7 days, 2) All events of a specific type today.

Two tables for two query patterns: Table 1 for query 1: CREATE TABLE user_events (user_id UUID, bucket DATE, event_time TIMESTAMP, event_type TEXT, payload TEXT, PRIMARY KEY ((user_id, bucket), event_time)) WITH CLUSTERING ORDER BY (event_time DESC) AND default_time_to_live = 604800; Query: WHERE user_id=? AND bucket IN [today, yesterday, ...7days...]. Table 2 for query 2: CREATE TABLE events_by_t

This is a Pro chapter

Sign in, then upgrade to Pro or Power to unlock this and the full Databases Mastery library.

Design a Cassandra schema for storing user activity events with the ability to query: 1) All events for a user in the last 7 days, 2) All events of a specific type today.

Next Step

Continue to How do you implement optimistic concurrency control in MongoDB?← Back to all NoSQL questions