Database / Apache Cassandra Intermediate and Advanced interview questions
What are the different compaction strategies available in Cassandra?
Compaction merges multiple SSTables into fewer, larger ones, discarding overwritten data and expired tombstones along the way. Cassandra offers a few strategies, each tuned for a different workload shape.
| STCS | LCS | TWCS |
| Size-Tiered: merges similarly-sized SSTables together. | Leveled: organizes SSTables into non-overlapping levels. | Time Window: groups SSTables by time bucket. |
| Good for write-heavy workloads. | Good for read-heavy workloads needing predictable latency. | Good for time-series data with TTL expiration. |
| Can cause temporary space amplification (needs free disk equal to data size). | More consistent read performance, but higher compaction I/O. | Whole SSTables expire together, minimizing tombstone scanning. |
ALTER TABLE metrics WITH compaction = {'class': 'TimeWindowCompactionStrategy', 'compaction_window_unit': 'DAYS', 'compaction_window_size': 1};
Choosing the right strategy is a workload decision, not a one-size-fits-all default: STCS suits general write-heavy tables, LCS suits tables with heavy read amplification concerns, and TWCS is purpose-built for append-only, time-ordered data with TTLs.
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...
