Database / ScyllaDB Interview questions
When should you use lightweight transactions in ScyllaDB?
Lightweight transactions (LWT), expressed with IF clauses like INSERT ... IF NOT EXISTS or UPDATE ... IF column = value, provide linearizable compare-and-swap semantics using a Paxos-based consensus protocol among replicas, rather than the normal fire-and-acknowledge write path.
UPDATE inventory SET quantity = quantity - 1 WHERE item_id = 'sku-42' IF quantity > 0;
Use LWT specifically when correctness genuinely depends on a conditional check being atomic across replicas, such as claiming a unique username, decrementing limited inventory without overselling, or implementing a distributed lock. Because Paxos-based consensus requires multiple round trips between replicas, LWT is meaningfully slower and more resource-intensive than a normal write, so it should be reserved for the specific operations that need this guarantee rather than used as a default for all writes.
More Related questions...