
TiDB: A Raft-based HTAP Database
Dongxu Huang, Qi Liu, Qiu Cui, Zhuhe Fang
∗
, Xiaoyu Ma, Fei Xu, Li Shen, Liu Tang,
Yuxing Zhou, Menglong Huang, Wan Wei, Cong Liu, Jian Zhang, Jianjun Li, Xuelian Wu,
Lingyu Song, Ruoxi Sun, Shuaipeng Yu, Lei Zhao, Nicholas Cameron, Liquan Pei, Xin Tang
PingCAP
{huang, liuqi, cuiqiu, fangzhuhe, maxiaoyu, xufei, shenli, tl, z, menglong,
weiwan, liucong, zhangjian, jay, wuxuelian, songlingyu, sunruoxi, yusp,
zhaolei, nick, liquanpei, tangxin}@pingcap.com
ABSTRACT
Hybrid Transactional and Analytical Processing (HTAP) databases
require processing transactional and analytical queries in isolation
to remove the interference between them. To achieve this, it is nec-
essary to maintain different replicas of data specified for the two
types of queries. However, it is challenging to provide a consistent
view for distributed replicas within a storage system, where ana-
lytical requests can efficiently read consistent and fresh data from
transactional workloads at scale and with high availability.
To meet this challenge, we propose extending replicated state
machine-based consensus algorithms to provide consistent replicas
for HTAP workloads. Based on this novel idea, we present a Raft-
based HTAP database: TiDB. In the database, we design a multi-
Raft storage system which consists of a row store and a column
store. The row store is built based on the Raft algorithm. It is scal-
able to materialize updates from transactional requests with high
availability. In particular, it asynchronously replicates Raft logs to
learners which transform row format to column format for tuples,
forming a real-time updatable column store. This column store al-
lows analytical queries to efficiently read fresh and consistent data
with strong isolation from transactions on the row store. Based on
this storage system, we build an SQL engine to process large-scale
distributed transactions and expensive analytical queries. The SQL
engine optimally accesses row-format and column-format replicas
of data. We also include a powerful analysis engine, TiSpark, to
help TiDB connect to the Hadoop ecosystem. Comprehensive ex-
periments show that TiDB achieves isolated high performance un-
der CH-benCHmark, a benchmark focusing on HTAP workloads.
PVLDB Reference Format:
Dongxu Huang, Qi Liu, Qiu Cui, Zhuhe Fang, Xiaoyu Ma, Fei Xu, Li
Shen, Liu Tang, Yuxing Zhou, Menglong Huang, Wan Wei, Cong Liu, Jian
Zhang, Jianjun Li, Xuelian Wu, Lingyu Song, Ruoxi Sun, Shuaipeng Yu,
Lei Zhao, Nicholas Cameron, Liquan Pei, Xin Tang. TiDB: A Raft-based
HTAP Database. PVLDB, 13(12): 3072-3084, 2020.
DOI: https://doi.org/10.14778/3415478.3415535
1. INTRODUCTION
Relational database management systems (RDBMS) are popu-
lar with their relational model, strong transactional guarantees, and
∗
Zhuhe Fang is the corresponding author.
This work is licensed under the Creative Commons Attribution-
NonCommercial-NoDerivatives 4.0 International License. To view a copy
of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/. For
any use beyond those covered by this license, obtain permission by emailing
info@vldb.org. Copyright is held by the owner/author(s). Publication rights
licensed to the VLDB Endowment.
Proceedings of the VLDB Endowment, Vol. 13, No. 12
ISSN 2150-8097.
DOI: https://doi.org/10.14778/3415478.3415535
SQL interface. They are widely adopted in traditional applica-
tions, like business systems. However, old RDBMSs do not pro-
vide scalability and high availability. Therefore, at the beginning
of the 2000s [11], internet applications preferred NoSQL systems
like Google Bigtable [12] and DynamoDB [36]. NoSQL systems
loosen the consistency requirements and provide high scalability
and alternative data models, like key-value pairs, graphs, and doc-
uments. However, many applications also need strong transac-
tions, data consistency, and an SQL interface, so NewSQL systems
appeared. NewSQL systems like CockroachDB [38] and Google
Spanner [14] provide the high scalability of NoSQL for Online
Transactional Processing (OLTP) read/write workloads and still ma-
intain ACID guarantees for transactions [32]. In addition, SQL-
based Online Analytical Processing (OLAP) systems are being de-
veloped quickly, like many SQL-on-Hadoop systems [16].
These systems follow the “one size does not fit all” paradigm
[37], using different data models and technologies for the different
purposes of OLAP and OLTP. However, multiple systems are very
expensive to develop, deploy, and maintain. In addition, analyzing
the latest version of data in real time is compelling. This has given
rise to hybrid OLTP and OLAP (HTAP) systems in industry and
academia [30]. HTAP systems should implement scalability, high
availability, and transnational consistency like NewSQL systems.
Besides, HTAP systems need to efficiently read the latest data to
guarantee the throughput and latency for OLTP and OLAP requests
under two additional requirements: freshness and isolation.
Freshness means how recent data is processed by the analytical
queries [34]. Analyzing the latest data in real time has great busi-
ness value. But it is not guaranteed in some HTAP solutions, such
as those based on an Extraction-Transformation-Loading (ETL) pro-
cessing. Through the ETL process, OLTP systems periodically re-
fresh a batch of the latest data to OLAP systems. The ETL costs
several hours or days, so it cannot offer real-time analysis. The ETL
phase can be replaced by streaming the latest updates to OLAP sys-
tems to reduce synchronization time. However, because these two
approaches lack a global data governance model, it is more com-
plex to consider consistency semantics. Interfacing with multiple
systems introduces additional overhead.
Isolation refers to guaranteeing isolated performance for seper-
ate OLTP and OLAP queries. Some in-memory databases (such as
HyPer [18]) enable analytical queries to read the latest version of
data from transactional processing on the same server. Although
this approach provides fresh data, it cannot achieve high perfor-
mance for both OLTP and OLAP. This is due to data synchroniza-
tion penalties and workload interference. This effect is studied in
[34] by running CH-benCHmark [13], an HTAP benchmark on Hy-
Per and SAP HANA. The study found that when a system co-runs
analytical queries, its maximum attainable OLTP throughput is sig-
3072
评论