Database / Apache Cassandra Intermediate and Advanced interview questions
How do you model time-series data in Cassandra?
Good time-series modeling in Cassandra centers on two goals: keep partitions bounded in size, and keep the most commonly queried time range fast to retrieve.
CREATE TABLE sensor_readings ( sensor_id text, day text, -- bucket, e.g. '2026-07-21' reading_time timestamp, value double, PRIMARY KEY ((sensor_id, day), reading_time) ) WITH CLUSTERING ORDER BY (reading_time DESC);
- Bucket the partition key by a time unit (day, hour, or week depending on write volume) combined with the natural entity id, so no single partition grows without bound.
- Cluster by timestamp, typically descending, so the most recent readings — the ones usually queried — are at the front of the partition and returned fastest.
- Use TTLs to expire old data automatically if it doesn't need to be kept forever, pairing well with Time Window Compaction Strategy so whole SSTables age out together.
- Choose bucket size based on write rate: a high-frequency sensor might bucket hourly, while a low-frequency one might bucket monthly, so each bucket stays a reasonable, similar size.
This pattern — bucketed partition key, descending clustering key, TTL, TWCS — is the standard playbook for metrics, logs, events, and IoT data in Cassandra.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
