Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Database Selection: TDengine vs Others

🇺🇸 English    |    🇨🇳 中文

🇺🇸 English

Scenario: Settlement Persistence - Storing orders, trades, and balances.


📊 Comparison

Candidates

DatabaseTypeUse Case
TDengineTime-SeriesIoT, Financial Data, High-Frequency Write
PostgreSQLRelationalGeneral OLTP
TimescaleDBPG ExtensionTime-Series (PG based)
ClickHouseColumnarOLAP, Analytics

🎯 Why TDengine?

1. Performance (Based on TSBS)

MetricTDengine vs TimescaleDBTDengine vs PostgreSQL
Write Speed1.5-6.7x Faster10x+ Faster
Query Speed1.2-24.6x Faster10x+ Faster
Storage1/12 - 1/27 SpaceHuge Saving

2. Matching Exchange Requirements

RequirementTDengine Solution
High Frequency WriteMillion/sec write capacity
Timestamp IndexNative time-series design
High CardinalityHigh data points, Super Tables
Real-time StreamBuilt-in Stream Computing
Data SubscriptionKafka-like real-time push
Auto PartitioningAuto-sharding by time

3. Simplified Architecture

TDengine Solution:
┌─────────────────────────────────────────────┐
│                  TDengine                    │
│      Persistence + Stream + Subscription     │
55 └─────────────────────────────────────────────┘

Fewer Components = Lower Ops Complexity + Lower Latency

4. Rust Ecosystem

  • ✅ Official Rust Client taos
  • ✅ Async (tokio)
  • ✅ Connection Pool (r2d2)
  • ✅ WebSocket (Cloud friendly)

❌ Why Not Others?

PostgreSQL

  • ❌ Poor time-series performance.
  • ❌ High-frequency write bottleneck.
  • ❌ Large storage consumption.

TimescaleDB

  • ⚠️ Slower than TDengine.
  • ⚠️ Much larger storage footprint.

ClickHouse

  • ✅ Fast analytics.
  • ❌ Real-time row-by-row write is weak (prefers batch).
  • ❌ High Ops complexity.

📋 Data Model

TDengine Super Table

-- Orders Super Table
CREATE STABLE orders (
    ts TIMESTAMP,           -- PK
    order_id BIGINT,
    user_id BIGINT,
    side TINYINT,
    order_type TINYINT,
    price BIGINT,
    qty BIGINT,
    filled_qty BIGINT,
    status TINYINT
) TAGS (
    symbol_id INT           -- Partition Tag
);

-- Trades
CREATE STABLE trades (...) TAGS (symbol_id INT);

-- Balances
CREATE STABLE balances (...) TAGS (user_id BIGINT, asset_id INT);

Advantages

  • ✅ Auto-partition by TAG.
  • ✅ Auto-aggregation query.
  • ✅ Unified Schema.

🏗️ Architecture Integration

Gateway -> Order Queue -> Trading Core -> Events -> TDengine

✅ Final Recommendation

Primary Storage: TDengine

  • Orders, Trades, Balances History.
  • High performance write/read.

📊 Expected Performance

  • Write Latency: < 1ms
  • Query Latency: < 5ms
  • Storage Compression: 10:1
  • Supported TPS: 100,000+



🇨🇳 中文

场景: 交易所 Settlement Persistence - 存储订单、成交、余额


📊 方案对比

候选数据库

数据库类型适用场景
TDengine时序数据库IoT, 金融数据, 高频写入
PostgreSQL关系型数据库通用 OLTP
TimescaleDBPostgreSQL扩展时序数据 (基于PG)
ClickHouse列式分析数据库OLAP, 大规模聚合

🎯 为什么选择 TDengine

1. 性能优势 (基于 TSBS 基准测试)

指标TDengine vs TimescaleDBTDengine vs PostgreSQL
写入速度1.5-6.7x 更快10x+ 更快
查询速度1.2-24.6x 更快10x+ 更快
存储空间1/12 - 1/27极大节省

2. 交易所场景完美匹配

需求TDengine 解决方案
高频写入百万/秒级写入能力
时间戳索引原生时序设计,毫秒级查询
高基数支持亿级数据点,Super Table
实时分析内置流计算引擎
数据订阅类 Kafka 的实时推送
自动分区按时间自动分片
高压缩率1/10 存储空间

3. 简化架构

TDengine 方案:
┌─────────────────────────────────────────────┐
│                  TDengine                    │
│      持久化 + 流计算 + 数据订阅              │
└─────────────────────────────────────────────┘

减少组件 = 减少运维复杂度 + 减少延迟

4. Rust 生态支持

  • ✅ 官方 Rust 客户端 taos
  • ✅ 异步支持 (tokio 兼容)
  • ✅ 连接池 (r2d2)
  • ✅ WebSocket 连接 (适合云部署)

❌ 为什么不选其他方案

PostgreSQL

  • ❌ 通用数据库,时序性能差
  • ❌ 高频写入会成为瓶颈
  • ❌ 存储空间消耗大

TimescaleDB

  • ⚠️ 基于 PostgreSQL,继承其限制
  • ⚠️ 比 TDengine 慢 1.5-6.7x
  • ⚠️ 存储空间是 TDengine 的 12-27x

ClickHouse

  • ✅ 分析查询极快
  • ❌ 实时写入不如 TDengine
  • ❌ 更适合批量导入 + OLAP
  • ❌ 运维复杂度高

📋 交易所数据模型设计

TDengine Super Table 设计

-- 订单表 (Super Table)
CREATE STABLE orders (...) TAGS (symbol_id INT);

-- 成交表 (Super Table)
CREATE STABLE trades (...) TAGS (symbol_id INT);

-- 余额快照表 (Super Table)  
CREATE STABLE balances (...) TAGS (user_id BIGINT, asset_id INT);

Super Table 优势

  • ✅ 自动按 TAG 分表
  • ✅ 查询时自动聚合
  • ✅ Schema 统一管理

🏗️ 架构集成方案

Gateway -> Order Queue -> Trading Core -> Events -> TDengine

✅ 最终推荐

主存储: TDengine

  • 订单、成交、余额历史
  • 高性能写入和查询
  • 自动数据分区和压缩

📊 预期性能

  • 写入延迟: < 1ms
  • 查询延迟: < 5ms
  • 存储压缩率: 10:1
  • 支持 TPS: 100,000+