Database / Apache Cassandra Intermediate and Advanced interview questions
What are lightweight transactions (LWT) in Cassandra?
Lightweight transactions give Cassandra a way to do compare-and-set style operations — "only apply this write if a condition holds" — which normal writes cannot express, since ordinary writes are unconditional and last-write-wins.
INSERT INTO users (user_id, email) VALUES ('u1', 'a@b.com') IF NOT EXISTS; UPDATE accounts SET balance = 150 WHERE account_id = 'acc1' IF balance = 100;
IF NOT EXISTSguarantees a row is only created if it doesn't already exist — useful for uniqueness constraints like usernames or reservations.IF <condition>applies an update only when the current stored value matches, enabling optimistic-concurrency patterns.
Under the hood, LWTs use the Paxos consensus protocol among replicas to agree on whether the condition holds and the write should proceed, rather than the normal quorum-write path. This makes them linearizable but noticeably slower and more resource-intensive than regular writes, so they should be reserved for the specific operations that truly need conditional semantics, not used as a default write pattern.
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...
