ENGINEERING

Real-Time & Batch Trading Analytics Architecture: 1M+ TPS with Kafka and ClickHouse

A zero-backpressure Kappa architecture unifying live gRPC market ticks and 1-minute CSV replay for sub-second trading analytics and historical quant research.

By Abundance AI Engineering (Data Engineering & Streaming Systems) · Dec 2026 · 11 min read

Collecting 1M+ market ticks per second during exchange hours without adding backpressure to latency-critical trading engines demands strict decoupling. This system design details a Kappa streaming architecture using Kafka Connect, Kafka Streams, ClickHouse materialized views, automated CSV gap recovery, and S3 cold tiering.

Open full system design document (PDF)

Online trading engines emit market ticks (timestamp, source system ID, stock ID, bid price, ask price) continuously while exchanges are open (09:00 to 18:00). Downstream desks need sub-second latest prices, real-time 1-minute OHLC bars, and multi-year historical joins for quant research, all while guaranteeing zero backpressure on the producing trading systems.

When source systems expose both a push-based gRPC subscription API (~1M ticks/sec, TCP/HTTP2) and 1-minute CSV event logs on shared disk (retained 24 hours as the 100% complete source of truth), the architectural choice comes down to unifying live ingestion and backfill without operating two divergent data pipelines.

1. Constraints, SLOs, and Capacity Planning (NALSD)

Designing for peak NYSE-scale throughput with 2x volatility spikes during market hours requires concrete sizing upfront rather than abstract boxes:

  • Availability & Latency Targets: >99.99% producer isolation during the 09:00 to 18:00 trading window, <10ms intra-cluster network latency, <100ms p99 ingestion-to-query latency, and a 99.9% end-to-end data delivery SLO.
  • Throughput & Compression: 1M ticks/sec (~100 MB/s compressed using Snappy 5:1 compression in Kafka), with headroom to absorb 2x intraday volatility surges.
  • Kafka Cluster Sizing: 6 brokers (m5.4xlarge class), 200 partitions keyed by stock_id, 3x replication (min.insync=2), 1TB buffer per partition to survive a 1-hour downstream outage, and 10 Kafka Connect tasks (c5.2xlarge class, 1GB buffer per task).
  • ClickHouse Tiered Storage: 3-node ReplicatedMergeTree hot cluster with 2TB NVMe SSDs per node for bronze and silver layers (30-day hot retention, horizontally scalable to 5M TPS), paired with infinite S3 cold tiering via TTL policies executed strictly outside trading hours.

2. Why Kappa Beats Lambda for Trading Analytics

A classic Lambda architecture splits the world into a Spark batch layer for CSV files, a Flink speed layer for gRPC streams, and a Trino union query layer to merge both views. In practice, maintaining two processing engines and identical aggregation logic across dev, test, and prod creates continuous schema drift and heavy operational toil.

A streaming-first, zero-ETL Kappa architecture routes both live gRPC ticks and historical CSV replay through one immutable Kafka log, one Kafka Streams processing topology, and one ClickHouse analytical store. Backfills become simple event replays with identical deduplication and windowing semantics.

3. High-Level Flow & Low-Level Pipeline Design

Every stage is asynchronous, non-blocking, and deployed on multi-AZ Kubernetes (EKS/GKE) via GitOps:

  • Dual Ingestion (Kafka Connect): A custom gRPC source connector with a Single Message Transform (SMT) decodes protobuf ticks across 10 stock-grouped tasks, while a FilePulse connector polls shared-disk CSVs every 30 seconds using idempotent offsets. Tasks enforce consumer.request.timeout.ms=5000, shedding failures to a Dead Letter Queue (DLQ) and auto-scaling on CPU > 70%.
  • Stream Processing (Kafka Streams): Co-located Java KStreams apps run a KStream -> KTable deduplication -> 1-minute tumbling window topology with exactly-once idempotent producers, Kafka-backed state stores, and DLQ routing for malformed payloads.
  • Zero-ETL ClickHouse Medallion Schema: ClickHouse tails the market_ticks topic directly via ENGINE = Kafka into bronze_ticks (storing event_time DateTime64(6), stock_id UInt32, Decimal(10,2) bid/ask, source_id, and kafka_offset for lineage). Materialized views build silver_ticks (deduplicated via argMax), gold_ohlc (1-minute open/high/low/close via argMin/argMax), and a latest_price view.
  • Off-Hours Compaction & Tiering: TTL event_time + INTERVAL 7 DAY MOVE TO DISK "s3" migrates aging partitions to cold object storage, while cron jobs run SYSTEM STOP MERGES during active market hours so background compactions never degrade live query latency.

4. Automated Gap Recovery, Security, and Production Pitfalls

Market data pipelines are judged by how cleanly they recover from dropped streams and pass compliance audits:

  • Self-Healing CSV Backfill: An automated Gap Detector compares Kafka consumer lag against 1-minute CSV file checksums. Whenever completeness dips below threshold, it triggers Kafka Connect replay automatically without manual operator intervention.
  • Observability, Lineage & Quality: Prometheus and Grafana monitor throughput and lag alongside OpenTelemetry distributed traces, OpenLineage data flow graphs, Great Expectations data quality checks, and PagerDuty alerts on lag > 1 minute or completeness < 99.5%.
  • Security, Governance & Chaos Testing: Enforce mTLS in transit, encryption at rest, RBAC with column-level ClickHouse security, Avro with Schema Registry for backward-compatible evolution, cross-AZ topic mirroring, and Gremlin chaos drills injecting synthetic Kafka lag.
  • Known Production Gotchas: Watch closely for Kafka partition skews on high-volume tickers (such as index ETFs), silent Connect task stalls, and unthrottled ClickHouse background merge spikes.

Key Takeaways

  • Decouple latency-sensitive trading engines completely via asynchronous Kafka Connect ingestion so downstream stalls never apply backpressure.
  • Choose a Kappa architecture over Lambda by replaying source-of-truth CSV files through the same Kafka topic and ClickHouse materialized views as live gRPC ticks.
  • Use ClickHouse ENGINE = Kafka plus bronze/silver/gold materialized views for sub-100ms p99 analytics, pausing heavy merges and S3 TTL moves during market hours.
  • Automate gap detection with Kafka lag and CSV checksums, and validate operational resilience continuously with OpenLineage, Great Expectations, and chaos testing.