# Write Data


![left](./student-guide/diagram/03-Writing-of-data-01-01.png)

------------------------------------------------------------
After having the Raft consensus algorithm and RocksDB foundation, we can introduce the data written to TiKV. The process is as follows:

Suppose we want to write key = 100, value = Jack
- Client (usually TiDB Server) asks PD about the region where key = 100
- The PD informs the Leader of the region location (TiKV node)
- The client (usually TiDB Server) sends a write command to the TiKV node where the leader resides
- After the leader node accepts the write command, it starts the TiKV write process.

Here, we use two components, one called raftstore pool and the other called apply pool, which are the mechanisms used to write to the Persistent Storage Engine (RocksDB).

As for the storage engine, or RocksDB instance, we have two RocksDB instances in a TiKV, one of which is responsible for persisting the Raft log, which we call Raft RocksDB, and the other responsible for persisting the real key value data, which we call KV RocksDB.

When a write command is received back to the leader node, the raftstore pool serializes it into a log (raft log) and submits it to Raft RocksDB for persistence (append log). At the same time, the raftstore pool is also responsible for copying (distributing) logs (raft logs) to the TiKV nodes where followers are located. When most followers nodes in the cluster have received this log (raft log), we consider this (raft log) to be committed.

Next, apply pool parse the committed log (raft log) and applies it to the KV RocksDB.
- Leader applies key = 100, value = Jack to KV RocksDB and return write success to the client.

The above is the process of writing data in TiKV.