Explore key concepts of lightweight transactions and the Paxos protocol in Cassandra, including consistency guarantees, use cases, and transaction mechanisms. Enhance your understanding of distributed databases and consensus algorithms with these focused, beginner-friendly questions.
What is the main purpose of using lightweight transactions (LWT) in Cassandra when updating data, such as setting a unique username for a user account?
Explanation: Lightweight transactions are used to ensure linearizable consistency, meaning they prevent conflicting writes and guarantee unique values where required, such as ensuring no two users register with the same username. Increasing write throughput is not the purpose, as LWTs can make writes slower due to additional coordination. Reducing storage space and performing analytics are unrelated to LWT. Those options do not address the primary function of lightweight transactions.
Which problem does the Paxos protocol solve in distributed systems, particularly for lightweight transactions?
Explanation: Paxos is a consensus algorithm that helps distributed systems agree on a single value or change, even if some nodes fail or messages are delayed. Compressing data and balancing disk usage are not functions of Paxos. While encryption is important, Paxos is concerned with agreement, not security.
Which level of consistency can lightweight transactions provide for a single conditional write in a distributed database?
Explanation: Lightweight transactions provide linearizable consistency for conditional operations, ensuring all clients see the latest value immediately after the transaction succeeds. Eventual, causal, and weak consistency do not guarantee this immediate visibility and correctness. Only linearizable consistency provides the strict ordering offered by LWT.
How many main phases does the basic Paxos algorithm use to reach consensus on a value?
Explanation: Basic Paxos uses two main phases: the prepare phase and the accept phase, to help participants agree on a proposal. Four and five are incorrect, as those apply to expanded protocols, not the simplest form. One phase is not enough to guarantee consensus with potential failures.
When is it most appropriate to use a lightweight transaction in a distributed database?
Explanation: Lightweight transactions should be used when you need to ensure a unique constraint, such as preventing duplicate entries in a field meant to be unique. Using LWT for every insert is inefficient and unnecessary. Network latency is not addressed directly by LWT, and backup or restore tasks do not use LWT mechanisms.
What is a primary disadvantage of using lightweight transactions frequently for writes?
Explanation: LWTs involve multiple network round trips and consensus steps, which slow down write performance compared to normal writes. They do not increase disk space or disable reads, and they cannot prevent node failures, only improve consistency during failures.
If a lightweight transaction fails because the conditional clause is not met, such as 'IF NOT EXISTS', what happens to the data?
Explanation: When the IF condition in an LWT fails, no changes are applied and the data stays the same. Existing rows are not deleted, random values are never inserted, and table-wide locks are not used by LWT, which targets row-level isolation.
In the context of Paxos and consensus, what does a 'quorum' most closely refer to?
Explanation: A quorum is typically a simple majority of nodes, which is enough to make a decision even if some nodes are unavailable. Consensus does not require all nodes to agree, so 'every node' is incorrect. The fastest node or just the backup nodes do not define quorum.
Which statement describes an example of a lightweight transaction in action?
Explanation: LWTs are conditional updates, such as 'UPDATE ... IF column=value', guaranteeing atomicity and consistency when the condition is met. Compression, exporting tables, and splitting reads are unrelated to lightweight transaction concepts.
Why are lightweight transactions typically limited to a single partition key in distributed databases?
Explanation: Limiting LWTs to a single partition key reduces the number of nodes that must coordinate, thereby improving performance and lowering complexity. Large batch writes and automatic sharding are unrelated to the main reason for this limitation. Reducing memory size is not the primary driver behind this design.