TiKV — Distributed Transactional Key-Value Store on Raft
A CNCF-graduated distributed key-value store written in Rust that powers TiDB. Provides horizontal scaling, strong consistency via Raft, geo-replication, and ACID transactions with Percolator-style MVCC.
Installation avec revue préalable
Cet actif nécessite une revue. Le prompt copié demande un dry-run, affiche les écritures, puis continue seulement après confirmation.
npx -y tokrepo@latest install 4772853c-3920-11f1-9bc6-00163e2b0d79 --target codexDry-run d'abord, confirmez les écritures, puis lancez cette commande.
What it is
TiKV is a distributed transactional key-value store written in Rust. It is a CNCF-graduated project that powers TiDB (a distributed SQL database). TiKV provides horizontal scaling, strong consistency via the Raft consensus protocol, geo-replication, and ACID transactions with Percolator-style MVCC.
It targets infrastructure teams building distributed systems that need a reliable storage layer with transactional guarantees. TiKV runs as a standalone key-value store or as the storage engine behind TiDB.
How it saves time or tokens
Building a distributed, strongly consistent storage layer from scratch is a multi-year effort. TiKV provides this as a ready-to-deploy component. The Raft consensus protocol handles leader election and data replication automatically, and the Percolator transaction model provides distributed ACID without manual coordination.
TiKV's RawKV API is simple enough for key-value workloads, while the TxnKV API supports multi-key transactions across shards.
How to use
- Install TiUP (PingCAP's cluster manager):
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
- Start a local TiKV cluster for testing:
tiup playground --mode tikv-slim
- Interact with TiKV using the Rust, Go, Java, or Python client:
from tikv_client import RawClient
client = RawClient.connect(['127.0.0.1:2379'])
client.put(b'key1', b'value1')
value = client.get(b'key1')
print(value) # b'value1'
Example
// Go client example with transactions
package main
import (
"context"
"github.com/tikv/client-go/v2/txnkv"
)
func main() {
client, _ := txnkv.NewClient([]string{"127.0.0.1:2379"})
txn, _ := client.Begin()
txn.Set([]byte("account:alice"), []byte("1000"))
txn.Set([]byte("account:bob"), []byte("500"))
err := txn.Commit(context.Background())
// Both writes are atomic -- either both succeed or neither does
}
Related on TokRepo
- AI Tools for Database -- Distributed database tools and storage engines
- AI Tools for DevOps -- Infrastructure tools for distributed systems
Common pitfalls
- TiKV requires PD (Placement Driver) for cluster coordination. Running TiKV without PD is not supported in production.
- Raft consensus requires an odd number of replicas (3, 5, 7) for proper leader election. A 2-node cluster cannot tolerate any node failure.
- The Percolator transaction model adds latency compared to single-node databases. Expect 2-5ms per transaction in a well-configured cluster.
Questions fréquentes
TiDB is a distributed SQL database that uses TiKV as its storage engine. TiKV can also run standalone as a pure key-value store without TiDB. They are separate projects maintained by PingCAP.
TiKV provides strong consistency via the Raft consensus protocol. Every write is replicated to a majority of nodes before being acknowledged. Reads can be served from the leader for linearizable consistency or from followers for slightly stale reads.
Official clients are available for Rust, Go, Java, and Python. The Go and Rust clients are the most mature. Community clients exist for other languages.
TiKV automatically splits data into regions (default 96MB each). When a region grows too large, it splits. PD balances regions across TiKV nodes to distribute load evenly.
TiKV can store time-series data but is not optimized for it. Dedicated time-series databases like InfluxDB or TimescaleDB provide better compression and query performance for time-series workloads.
Sources citées (3)
- TiKV GitHub Repository— TiKV is a CNCF-graduated distributed key-value store
- TiKV Documentation— Uses Raft consensus protocol for strong consistency
- Percolator Paper (Google)— Percolator-style MVCC for distributed ACID transactions
En lien sur TokRepo
Fil de discussion
Actifs similaires
RocksDB — Facebook's Embeddable Persistent Key-Value Store
A C++ LSM-tree storage engine from Meta powering MyRocks, CockroachDB, TiKV, Kafka Streams and more. Optimized for fast SSDs and workloads with high write throughput and low read latency.
TiDB — Distributed SQL Database with MySQL Compatibility
TiDB is an open-source, cloud-native, distributed SQL database that supports hybrid transactional and analytical processing (HTAP). MySQL-compatible wire protocol, horizontal scalability, strong consistency, and elastic scaling.
Apache Ignite — Distributed In-Memory Computing Platform
A distributed database and computing platform that combines in-memory speed with disk persistence, providing distributed SQL, key-value storage, and compute grid capabilities.
NSQ — Real-Time Distributed Messaging Platform in Go
A guide to NSQ, the real-time distributed messaging platform designed for fault tolerance and horizontal scalability with no single point of failure.