Database Reference
In-Depth Information
Consistency in Cassandra
As application developers using Cassandra, we also have a choice between immediate and
eventual consistency. However, we don't implement this decision by selecting a particular
machine to read from: when interacting with Cassandra, the particular node we're commu-
nicating with is irrelevant because requests are always forwarded to the node or nodes that
should handle them.
Instead, Cassandra has a built-in notion of tunable consistency , which allows us to make a
decision, for each query, about what consistency characteristics we want. Specifically, we
tune consistency by telling Cassandra what constitutes a successful request.
The anatomy of a successful request
From the application's standpoint, when we issue a query to Cassandra, we simply send
some CQL over the wire, and at some later point receive a response. Hopefully, the re-
sponse will return successfully; if not, we will receive an error.
One requisite for a successful response is that our query is well-formed: if we misspell the
name of a column, for instance, we will certainly see an error. But this condition for suc-
cess is of little concern to us, since an invalid query will always generate an error, regard-
less of external factors.
More interesting from the perspective of consistency is the other condition of a successful
request: that Cassandra is internally able to fulfill it. For a write request, this means durably
storing the data being written; for a read request, it means retrieving the data from storage
and returning it.
The crux of the question is this: How many nodes must be involved in the fulfillment of a
request for it to be considered successful? For instance, if we are writing data to a row, we
might consider the write successful as soon as the data is written to a single replica of that
row; or we might require that the data be written to all of the replicas it belongs on before
we consider it a success.
When reading data, the same logic applies: we may want Cassandra to just read one copy
of the data and return it to us; or we may want it to read all copies of the data, compare
their timestamps, and return to us the most recent version.
Search WWH ::




Custom Search