# Routing Capabilities


![left](./student-guide/diagram/04-route-01-01.png)
------------------------------------------------------------
Since PD stores all TiKV cluster information, routing is naturally provided to the TiDB Server. Assume that the TiDB Server wants to write a value to the key.

- The TiKV Client first obtains which region the key belongs to from the PD, and the PD return the metadata related to this region.

- The TiKV Client has a region cache that caches metadata so that it does not need to be fetched from the PD every time. Then send the command directly to the leader peer in the region.

- It is possible that the leader of the region has drifted to another peer. TiKV will return a NotLeader error with the address of the new leader. The TiKV Client updates in the region cache and sends a request to the new leader again.

- It is also possible that the version of the region has changed, for example, split. At this time, the key may have fallen into the new region, and the TiKV Client will receive a staleCommand error, so get it from PD again and enter status 1.