Consistency

ACID

Atomicity

All operations in a transaction must either succeed or all are rolled back

For Example: a transaction to transfer funds from one account to another involves making a withdrawal operation from the first account and a deposit operation on the second. If the deposit operation failed, you don’t want the withdrawal operation to happen either.

Consistency

The database integrity constraints are valid on completion of the transaction. Which demands that the data must meet all the validation rules. All validation rules must be checked to ensure consistency

For example: If a field-type in database is Integer, it should accept only Integer value's and not some kind of other.If you want to store other types in this field, consistency are violated. At this condition transaction will rollback.

Isolated

Simultaneously occurring transactions do not interfere with each other. Contentious concurrent access is moderated by the database so that transactions appear to run sequentially

For example: a teller looking up a balance must be isolated from a concurrent transaction involving a withdrawal from the same account. Only when the withdrawal transaction commits successfully and the teller looks at the balance again will the new balance be reported.

Durable

Irrespective of hardware or software failures, the updates made by the transaction are permanent.

Consistency for distributed database system

Strong consistency

  • After any update, any subsequent access by any process will return the updated value

Building such guarantees is considered mostly impossible.

Weak consistency

There are no guarantees that subsequent accesses will return the written value

Eventual consistency

Eventual consistency is a consistency model used in distributed computing to achieve high availability that informally guarantees that, if no new updates are made to a given data item, eventually all accesses to that item will return the last updated value.

Is also a form of weak consistency where the storage system guarantees that eventually all accesses will return the last updated value when write quiesce.

One example is DNS. Updates to a name are distributed according to a set pattern, thus not all nodes will have the latest information during the initial update phase

Cap Theorem

It is impossible for a distributed computer system to simultaneously provide all three of the following guarantees:

Consistency

All nodes see the same data at the same time. A read is guaranteed to return the most recent write, from any client.

Availability

Every request gets a response on success/failure. Achieving availability in a distributed system requires that the system remains operational 100% of the time. Every client gets a response, regardless of the state of any individual node in the system

Partition Tolerance

  • A partition is an inability for two or more nodes in a network to communicate with each other. If node A can not receive messages from Node B and vice versa, this means there is a partition between the two.
  • The system remains operational, despite the loss of network connectivity or message loss between nodes.
  • You can consider partitions to be equivalent of unbounded network latency, meaning that messages will not get to their recipient.

https://www.youtube.com/watch?v=K12oQCzjPxE

An example of a network partition is when two nodes can't talk to each other, but there are clients able to talk to either one or both of those nodes.

Consensus

The two general problems

Multiphase commit

Two phase commit

Three phase commit

Paxos

Raft

Raft is a consensus algorithm, similar to Paxos, but designed to have fewer states and a much simpler algorithm

At any state, each Raft instances in in one of these states:

  • Leader
  • Follower
  • Candidate

Every instances start out as a follower: In this state, the instance is passive and is only supposed to respond to messages, replicate state from Leader

If no messages are received some time, the instances promote themselves to a candidate state. To kickstart an election with the objective to becoming the Leader themselves

In the candidate state, the instances request votes from other instances - their peers. If it receives a majority of votes, it is promoted to a leader.

A leader is responsible for:

  • Handle writes, that is, state-change requests from clients
  • Replicate the state change to all the followers
  • Handle reads in case stale reads are not allowed

References

Last updated on