CockroachDB

CockroachDB is NewSQL which offer the scalability of NoSQL in SQL.

CockroachDB has all ACID feature of the SQL data plus horizontal scaling.

Architecture

Contains number of nodes. Internally has layer to distribute the the node quicly

Fault Tolerance and High availability

Using Raft for concensus that need to agree to a Quorum. Say if there is a change, the majority of a Quorum needs to agree and log the change

Self-healing: Each range of data has a leader, if a leader fail, replica takes over.

Horizontal Scale

Data keep splitting to small ranges of 64 MB. If it's larger, it splits into smaller range.

Every range has 3 replicas (by default) split to different nodes. Each node has a copy.

If you add another node, cluster realises it's unbalanced. It moves the replicas to new node.

  • It doesn't move only the copy, create new replica on new node and delete the extra one in new node
flowchart TB
 subgraph Node1["Node1"]
        R1a["Range 1"]
        R2a["Range 2"]
        R3a["Range 3"]
  end
 subgraph Node2["Node2"]
        R1b["Range 1"]
        R2b["Range 2"]
        R4a["Range 4"]
  end
 subgraph Node3["Node3"]
        R1c["Range 1"]
        R3b["Range 3"]
        R4b["Range 4"]
  end
 subgraph Node4["Node4"]
        R2c["Range 2"]
        R3c["Range 3"]
        R4c["Range 4"]
  end
    data["data is split into ranges"] --> Node1 & Node2 & Node3 & Node4