# TiKV Server's Architecture

+ Persistent data
+ Consistency
+ `MVCC`
+ Distributed transaction
+ Coprocessor

![`smart`](TiKVArchitectureAndRole_aa_001_20220511.png)

------------------------------------------------------------------------------
In the previous unit, we learned that the TiDB server, as the SQL layer, exposes the MySQL protocol connection endpoint to client programs. It is responsible for accepting client connections, executing SQL parsing and optimization, and finally generating distributed execution plans. The TiDB server itself is stateless.

The main feature of TiKV is to provide data persistence for TiDB. This is achieved through the integration of RocksDB into TiKV, so we will focus on the data writing (i.e., persistence) and reading of RocksDB in TiKV, as well as introducing the RocksDB Column Families feature.

Another TiKV's feature is its support for distributed transactions and MVCC.

In TiDB, TiKV is a distributed storage engine. The data is stored in a distributed manner in regions, so we use 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 election in Raft, as well as data writing, reading, splitting, and merging based on the Raft consensus algorithm. Writing and reading based on the Raft consensus algorithm here is different from the previously mentioned RocksDB write and read. 

RocksDB writes and reads primarily refer to the guarantee of data persistence and consistency on a single TiKV node, while writing and reading based on the Raft consensus algorithm primarily concern multiple TiKV nodes.

The Coprocessor feature gives TiKV the ability to push down operators. We can use this feature to hand over some SQL computational workloads, such as filtering, aggregation, and projection, to TiKV instances to execute them. This eliminates the need to send all the data from TiKV to the TiDB server (the `root` node in execution plan) via the network, saving network bandwidth and CPU load on the TiDB server. Coprocessor operates in parallel.