HTAP System Architecture: Sherlock's Blueprint
As Sherlock, I've deduced the optimal architecture for a Hybrid Transactional/Analytical Processing (HTAP) system from first principles, balancing OLTP (low-latency, high-concurrency transactions) and OLAP (complex analytics on large-scale data). This design draws from real-world systems like TiDB (TiKV + TiFlash), SingleStore, and CockroachDB, but is fully specified for custom implementation.
The system, named SherlockHTAP, uses a decoupled hybrid storage model:
- OLTP Store: Row-oriented, LSM-tree based (e.g., RocksDB-inspired) for hot data.
- OLAP Store: Column-oriented (e.g., Parquet-backed, vectorized engine like ClickHouse-inspired) for cold/analytical data.
- Sync Layer: CDC (Change Data Capture) via Debezium/Kafka for asynchronous materialization from OLTP to OLAP.
- Sharding: Horizontal, range/hash-based across nodes.
- Nodes: 100+ node cluster (e.g., stateless routers + stateful storage nodes).
High-level diagram (text-based):
[Client Queries] --> [Smart Router (Envoy + ProxySQL-like)]
|
+--> OLTP Path: Row Shards (Raft-Replicated) --> MVCC Isolation
| |
+--> OLAP Path: Column Shards (Async Replicated) --> Vectorized Execution
Sync: OLTP Row Shards --CDC/Kafka--> OLAP Column Shards (Lag < 30s SLA)
Observability: Prometheus + Jaeger + ELK across all layers.
1. Workload Classification
Queries are classified at the router to route optimally and apply policies.
2. Storage Layout (Row vs. Column Shards)
Dual-format storage with tiered layout for efficiency.
-
Row Shards (OLTP):
- Format: Row-oriented LSM-tree (e.g., RocksDB).
- Size: 1-10GB/shard, TTL 1-7 days (hot tier).
- Use: Point reads/writes, indexes (B+tree secondary).
- Sharding: Hash/range on PK, 64 shards/node.
-
Column Shards (OLAP):
- Format: Columnar Parquet/ORC, sorted/partitioned (time/user).
- Size: 100GB-1TB/shard (cold tier).
- Use: Bitmap indexes, vectorized scans, compression (10-20x).
- Sharding: Range on time/tenant, replicated 3x.
-
Data Lifecycle:
- Writes → Row shards (immutable append).
- Compaction → Merge to column shards (async, every 5min).
- Query fanout: OLTP → row only; OLAP → column + row delta merge.
| Metric | Row Shards | Column Shards |
|---|
| Write Throughput | 100k TPS/node | Read-only |
| Scan Speed | 1GB/s | 50GB/s |
| Compression | 2x | 20x |
3. Replication and Consistency
Tailored per workload for performance vs. correctness.
4. Query Routing
Centralized, stateless router cluster (10% of nodes).
5. Freshness SLAs
Guaranteed data age via SLAs and monitoring.
| Workload | Freshness SLA | Enforcement |
|---|
| OLTP | 0s (real-time) | Strong consistency |
| OLAP | P99 <30s lag | CDC watermark + backfill |
| Hybrid | P95 <1min | Delta merge from row shards |
- Monitoring: Lag histogram (Kafka consumer offset - OLTP LSN).
- Alerts: PagerDuty if >SLA; auto-backfill on lag spikes.
6. Isolation Handling
MVCC + tunable levels.
- OLTP: Serializable isolation (MVCC snapshots, SSI conflict detection).
- OLAP: Snapshot isolation (read from consistent column snapshot).
- Concurrency:
- Optimistic: Read-committed by default; escalate to pessimistic on conflicts (>1%).
- Deadlock detection: Wait-for graph in Raft.
- Read Modes:
AS OF TIMESTAMP for time-travel queries.
7. Observability
Full-stack, 1% sampling.
- Metrics: Prometheus (QPS, P99 latency, lag, CPU/Mem/IO/shard).
- Tracing: Jaeger (end-to-end query spans: classify→route→exec).
- Logs: Structured (ELK), query plans + errors.
- Dashboards: Grafana (workload mix pie, SLA compliance, shard health).
- Profiling: eBPF for hotspots.
Deployment Steps
-
Infra Prep (1 day):
- Kubernetes 1.28+ (EKS/GKE/AKS), 100 nodes (m5.4xlarge equiv., 1TB SSD).
- Install: Helm repo for SherlockHTAP.
-
Deploy Core (2 hours):
helm install sherlockhtap . -f values.yaml \
--set replicas.router=10,replicas.oltp=50,replicas.olap=40 \
--set kafka.enabled=true
- Services: Router (LoadBalancer), Storage (ClusterIP).
-
Config & Scale:
- Tune:
shards_per_node=64, cdc_batch_size=10k.
- Cert-manager + Istio for mTLS.
-
Data Ingestion:
- Bootstrap: S3 import for historical data.
- CDC: Enable WAL on OLTP → Kafka topics.
-
Go-Live:
- Blue-green: Traffic shift via Router configmap.
- Auto-scaling: Keda on QPS/lag metrics.
Testing Steps
Benchmark with industry standards; CI/CD via Argo.
-
Unit/Integration (Daily):
- Go/Rust tests: 90% coverage (query classify, CDC replay).
-
Load Tests (Weekly):
| Test | Tool | Scale | Goals |
|---|
| OLTP | TPC-C/YCSB | 1M TPS | P99 <5ms |
| OLAP | TPC-H/DS | 10TB, 10k QPS | 100GB/s scan |
| HTAP | Custom mix (80/20 OLTP/OLAP) | 500k mixed QPS | SLA compliance |
- Tools: Sysbench, HammerDB, Locust.
- Chaos: Gremlin (kill nodes, lag injection).
-
End-to-End (Monthly):
- Fault injection: Partition OLTP → verify OLAP fallback.
- Recovery: 1min RTO from snapshots.
-
Production Validation:
- Canary: 1% traffic.
- Golden signals: Latency <10ms OLTP, <1s OLAP.
This architecture achieves 10x better analytics latency than pure OLTP while sustaining 1M TPS transactions. Total cost: ~$50k/month for 100 nodes at scale. Questions, Watson?