# Tikv Architecture And Role
__*TiKV architecture*__
__*The role of TiKV*__
+ Persistent data
+ Distributed consistency
+ MVCC
+ Distributed transaction
+ Coprocessor

![right](./student-guide/diagram/TiKVArchitectureAndRole_aa_001_20220511.png)

------------------------------------------------------------
In the previous course, we learned that TiDB Server, as a SQL layer, exposes the connection endpoint of the MySQL protocol to the outside world. It is responsible for accepting client connections, executing SQL parse and optimization, and finally generating distributed execution plans. TiDB Server itself is stateless.

Below we will introduce TiKV. The main core function of TiKV is responsible for data persistence of the TiDB database. This function is implement by RocksDB integrated into TiKV, so we will focus on data writing (that is, persistence) and read of RocksDB in TiKV, and also introduce RocksDB in Column Families feature. This feature has a big impact on later transaction and MVCC support.

Another feature of TiKV is that it supports distributed transaction and MVCC, so we will introduce their implement from the TiKV level.

In the TiDB database, TiKV is a distributed storage engine. The data is stored distributed in regions, so we used the raft consensus algorithm to implement strong consistency of data in a distributed environment. Each region and its replica form a raft group, and the combination of multiple raft groups is called multi raft. We will introduce replication and leader elect in raft, as well as data writing, read, splitting, and merging based on the raft consensus algorithm. Writing and reading based on the raft consensus algorithm here is different from the RocksDB write and read mentioned earlier. RocksDB writes and reads mainly refer to the guarantee of data persistence and consistency reading on a single TiKV node, which is vertical, and writing and reading based on the raft consensus algorithm are mainly for multiple TiKV The operation of a cluster of nodes can be considered horizontal.

Later, we introduced the Coprocessor function component, which provides TiKV with the ability to push down operators. We can use this function component to hand over some SQL calculations such as filtering, aggregation, and projection to TiKV to complete it. There is no need to send all the data in TiKV to the TiDB Server via the network, nor It is necessary to send all computational pressure to the TiDB Server. This saves network bandwidth and CPU load on the TiDB Server.