Convert Figma logo to code with AI

pingcap logotidb

TiDB - the open-source, cloud-native, distributed SQL database designed for modern applications.

37,777
5,884
37,777
4,833

Top Related Projects

30,408

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.

18,977

Vitess is a database clustering system for horizontal scaling of MySQL.

5,271

Apache HBase

Apache Cassandra®

Quick Overview

TiDB is an open-source, distributed SQL database that supports Hybrid Transactional and Analytical Processing (HTAP) workloads. It is MySQL compatible and designed to provide scalability, strong consistency, and high availability for large-scale applications.

Pros

  • Horizontal scalability: TiDB can easily scale out to handle large amounts of data and traffic
  • MySQL compatibility: Supports most MySQL syntax and protocols, making migration easier
  • HTAP capabilities: Can handle both transactional and analytical workloads efficiently
  • Strong consistency: Ensures data consistency across distributed nodes

Cons

  • Learning curve: Complex architecture may require time to understand and optimize
  • Resource intensive: Can be demanding on hardware resources, especially for smaller deployments
  • Limited ecosystem: Fewer third-party tools and integrations compared to more established databases
  • Performance tuning: May require careful configuration and tuning for optimal performance

Code Examples

  1. Connecting to TiDB using Go:
import (
    "database/sql"
    _ "github.com/go-sql-driver/mysql"
)

db, err := sql.Open("mysql", "root:@tcp(127.0.0.1:4000)/test")
if err != nil {
    log.Fatal(err)
}
defer db.Close()
  1. Creating a table and inserting data:
CREATE TABLE users (
    id INT PRIMARY KEY,
    name VARCHAR(50),
    age INT
);

INSERT INTO users (id, name, age) VALUES (1, 'Alice', 30), (2, 'Bob', 25);
  1. Performing a simple query:
rows, err := db.Query("SELECT * FROM users WHERE age > ?", 20)
if err != nil {
    log.Fatal(err)
}
defer rows.Close()

for rows.Next() {
    var id int
    var name string
    var age int
    err := rows.Scan(&id, &name, &age)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("ID: %d, Name: %s, Age: %d\n", id, name, age)
}

Getting Started

  1. Install TiDB using TiUP (TiDB package manager):

    curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
    
  2. Start a local TiDB cluster:

    tiup playground
    
  3. Connect to TiDB using MySQL client:

    mysql -h 127.0.0.1 -P 4000 -u root
    
  4. Start using TiDB with SQL commands or your preferred programming language's database driver.

Competitor Comparisons

30,408

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.

Pros of CockroachDB

  • Better support for geo-distributed deployments and multi-region setups
  • Stronger consistency guarantees with serializable isolation by default
  • More mature cloud-native architecture and Kubernetes integration

Cons of CockroachDB

  • Higher resource consumption, especially for smaller workloads
  • Less flexible storage engine options compared to TiDB's pluggable architecture
  • Steeper learning curve for SQL dialect and configuration options

Code Comparison

TiDB SQL syntax:

CREATE TABLE users (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(255),
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

CockroachDB SQL syntax:

CREATE TABLE users (
  id INT PRIMARY KEY DEFAULT unique_rowid(),
  name STRING,
  created_at TIMESTAMP DEFAULT current_timestamp()
);

Both databases support standard SQL syntax, but CockroachDB uses STRING instead of VARCHAR and unique_rowid() instead of AUTO_INCREMENT. TiDB's syntax is more similar to MySQL, while CockroachDB's is closer to PostgreSQL.

TiDB and CockroachDB are both distributed SQL databases designed for horizontal scalability and high availability. TiDB offers better compatibility with MySQL ecosystems, while CockroachDB excels in geo-distributed deployments. The choice between them depends on specific use cases, existing infrastructure, and scalability requirements.

YugabyteDB - the cloud native distributed SQL database for mission-critical applications.

Pros of YugabyteDB

  • Better support for geo-distributed deployments and multi-region setups
  • Native support for both SQL (PostgreSQL-compatible) and NoSQL APIs
  • Stronger consistency guarantees with linearizable ACID transactions

Cons of YugabyteDB

  • Smaller community and ecosystem compared to TiDB
  • Less mature and battle-tested in large-scale production environments
  • Limited support for advanced features like distributed transactions across shards

Code Comparison

YugabyteDB (C++):

Status YBClient::CreateTable(const string& table_name,
                             const Schema& schema,
                             const CreateTableOptions& options) {
  // Implementation details
}

TiDB (Go):

func (s *session) CreateTable(ctx context.Context, stmt *ast.CreateTableStmt) error {
    // Implementation details
}

Both projects use different programming languages for their core implementations. YugabyteDB primarily uses C++ for its storage engine and query processing, while TiDB is written in Go. This difference affects performance characteristics and development workflows.

YugabyteDB focuses on providing a unified platform for both SQL and NoSQL workloads, making it suitable for applications requiring flexible data models. TiDB, on the other hand, emphasizes compatibility with MySQL and excels in handling large-scale OLTP workloads.

18,977

Vitess is a database clustering system for horizontal scaling of MySQL.

Pros of Vitess

  • More mature project with longer history and wider adoption
  • Better suited for horizontal scaling of MySQL databases
  • Stronger support for sharding and multi-tenancy

Cons of Vitess

  • Less flexible query processing capabilities
  • More complex setup and configuration
  • Limited support for advanced SQL features compared to TiDB

Code Comparison

Vitess query execution:

func (vtg *VTGate) Execute(ctx context.Context, session *vtgatepb.Session, sql string, bindVariables map[string]*querypb.BindVariable) (*vtgatepb.Session, *sqltypes.Result, error) {
    // Query execution logic
}

TiDB query execution:

func (e *Execute) Next(ctx context.Context, req *chunk.Chunk) error {
    // Query execution logic
}

Both projects use Go for their core implementations, but TiDB's query execution is more tightly integrated with its storage engine, while Vitess acts as a proxy layer on top of MySQL.

Vitess is better suited for scaling existing MySQL deployments, while TiDB offers a more comprehensive distributed database solution with advanced SQL features. The choice between them depends on specific use cases and requirements.

5,271

Apache HBase

Pros of HBase

  • Mature and battle-tested system with a large user base
  • Strong support for very large datasets and high write throughput
  • Tight integration with the Hadoop ecosystem

Cons of HBase

  • Steeper learning curve and more complex setup compared to TiDB
  • Less SQL-like query language, which may require more specialized knowledge
  • Generally slower for complex analytical queries

Code Comparison

HBase (Java):

Put put = new Put(Bytes.toBytes("row1"));
put.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("qual1"), Bytes.toBytes("value1"));
table.put(put);

TiDB (SQL):

INSERT INTO table_name (column1, column2)
VALUES ('value1', 'value2');

Key Differences

  • TiDB offers a more familiar SQL interface, while HBase uses a NoSQL model
  • TiDB provides built-in distributed transactions, which HBase lacks natively
  • HBase is better suited for write-heavy workloads, while TiDB offers better support for complex queries and OLTP scenarios

Use Cases

  • HBase: Large-scale data storage, real-time data processing, and time-series data
  • TiDB: Hybrid transactional and analytical processing (HTAP), scaling out MySQL applications, and distributed OLTP systems

Both systems have their strengths, and the choice between them depends on specific requirements, existing infrastructure, and team expertise.

Apache Cassandra®

Pros of Cassandra

  • Highly scalable and distributed architecture, designed for large-scale deployments
  • Strong support for multi-datacenter replication and high availability
  • Mature project with a large community and extensive ecosystem

Cons of Cassandra

  • Limited support for complex queries and joins compared to TiDB's SQL capabilities
  • Less flexible schema changes, as altering existing tables can be challenging
  • Steeper learning curve for developers unfamiliar with the CQL query language

Code Comparison

Cassandra (CQL):

CREATE TABLE users (
  id UUID PRIMARY KEY,
  name TEXT,
  email TEXT
);

TiDB (SQL):

CREATE TABLE users (
  id UUID PRIMARY KEY,
  name VARCHAR(255),
  email VARCHAR(255)
);

Both databases support creating tables, but TiDB uses standard SQL syntax, while Cassandra uses its own CQL language. TiDB offers more traditional relational database features, including support for complex queries and transactions, making it easier for developers familiar with SQL to work with. Cassandra, on the other hand, is optimized for high-throughput, low-latency operations on large-scale distributed systems, sacrificing some flexibility in query capabilities for improved scalability and performance in specific use cases.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

TiDB

TiDB (/’taɪdiːbi:/, "Ti" stands for Titanium) is an open-source, cloud-native, distributed SQL database designed for high availability, horizontal and vertical scalability, strong consistency, and high performance.

Key Features

  • Distributed Transactions: TiDB uses a two-phase commit protocol to ensure ACID compliance, providing strong consistency. Transactions span multiple nodes, and TiDB's distributed nature ensures data correctness even in the presence of network partitions or node failures.

  • Horizontal and Vertical Scalability: TiDB can be scaled horizontally by adding more nodes or vertically by increasing resources of existing nodes, all without downtime. TiDB's architecture separates computing from storage, enabling you to adjust both independently as needed for flexibility and growth.

  • High Availability: Built-in Raft consensus protocol ensures reliability and automated failover. Data is stored in multiple replicas, and transactions are committed only after writing to the majority of replicas, guaranteeing strong consistency and availability, even if some replicas fail. Geographic placement of replicas can be configured for different disaster tolerance levels.

  • Hybrid Transactional/Analytical Processing (HTAP): TiDB provides two storage engines: TiKV, a row-based storage engine, and TiFlash, a columnar storage engine. TiFlash uses the Multi-Raft Learner protocol to replicate data from TiKV in real time, ensuring consistent data between the TiKV row-based storage engine and the TiFlash columnar storage engine. The TiDB Server coordinates query execution across both TiKV and TiFlash to optimize performance.

  • Cloud-Native: TiDB can be deployed in public clouds, on-premises, or natively in Kubernetes. TiDB Operator helps manage TiDB on Kubernetes, automating cluster operations, while TiDB Cloud provides a fully-managed service for easy and economical deployment, allowing users to set up clusters with just a few clicks.

  • MySQL Compatibility: TiDB is compatible with MySQL 8.0, allowing you to use familiar protocols, frameworks and tools. You can migrate applications to TiDB without changing any code, or with minimal modifications. Additionally, TiDB provides a suite of data migration tools to help easily migrate application data into TiDB.

  • Open Source Commitment: Open source is at the core of TiDB's identity. All source code is available on GitHub under the Apache 2.0 license, including enterprise-grade features. TiDB is built with the belief that open source enables transparency, innovation, and collaboration. We actively encourage contributions from the community to help build a vibrant and inclusive ecosystem, reaffirming our commitment to open development and accessibility for everyone.

Quick start

[!Tip]
As part of our commitment to open source, we want to reward all GitHub users. In addition to the free tier, you can get up to $2000 in TiDB Cloud Serverless credits for your open-source contributions - Claim here.

  1. Start a TiDB Cluser

    • On Local Playground. To start a local test cluster, please refer to the TiDB quick start guide.

    • On Kubernetes. TiDB can be easily deployed in a self-managed Kubernetes environment or Kubernetes services on public clouds using TiDB Operator. For more details, please refer to the TiDB on Kubernetes quick start guide.

    • Using TiDB Cloud (Recommended). TiDB Cloud offers a fully managed version of TiDB with a free tier, no credit card required, so you can get a free cluster in seconds and start easily: Sign up for TiDB Cloud.

  2. Learn About TiDB SQL: To explore the SQL capabilities of TiDB, refer to the TiDB SQL documentation.

  3. Use MySQL Driver or ORM to Build an App with TiDB with TiDB.

  4. Explore key features, such as data migration, changefeed, vector search, HTAP, disaster recovery, etc.

Need Help?

Architecture

TiDB architecture

Learn more details about TiDB architecture in our Docs.

Contributing

TiDB is built on a commitment to open source, and we welcome contributions from everyone. Whether you are interested in improving documentation, fixing bugs, or developing new features, we invite you to shape the future of TiDB.

Active Contributors of pingcap/tidb - Last 28 days

License

TiDB is under the Apache 2.0 license. See the LICENSE file for details.

See Also

Acknowledgments