Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

ClickHouse 13 min read How-to mediumAdept

Building a .NET API Gateway with ClickHouse and Aspire

A sample .NET API gateway uses Aspire to orchestrate a ClickHouse container, a YARP gateway, backend APIs, a load generator, an analytics API and a Blazor dashboard. Aspire provides live OpenTelemetry metrics and ClickHouse stores the full request history for aggregate analytics. The gateway middleware never blocks on the database: it enqueues rows into a bounded System.Threading.Channels queue with DropWrite, counts drops as a metric, and a background service batch-inserts via RowBinary with async_insert and wait_for_async_insert. The ClickHouse schema uses LowCardinality columns, daily partitions, a sorting key, a 30-day TTL, and an AggregatingMergeTree materialized view with -State/-Merge combinators so percentile dashboards stay fast regardless of log volume.

Related posts

  • Structured Logging in .NET with Serilog and ClickHouse

    ClickHouse mediumAdept

    Serilog's ClickHouse sink lets an ASP.NET service write structured logs directly into a ClickHouse table with one WriteTo.ClickHouse() call. A fluent C# schema builder controls the table: typed JSON property hints, promoted columns such as CorrelationId, a text inverted index on messages, a MergeTree ORDER BY key and a TTL. The demo also covers correlation ID middleware via LogContext, single per-request summary events with UseSerilogRequestLogging and IDiagnosticContext, and flushing batched events with Log.CloseAndFlushAsync on shutdown. For production, manage the schema externally rather than letting the sink create it, and tune compression codecs and Kubernetes-aware sort keys.

  • Building an Observability Solution with ClickHouse at Dash0

    ClickHouse hardMaster

    Dash0 stores all OpenTelemetry metrics, logs and spans in ClickHouse, using PostgreSQL only for customer settings, so signals can be joined and correlated in one system. The setup tiers storage with 1-2 days on local disk, then AWS S3 plus a local cache, driven by TTL moves, and keeps metrics for 13 months. Tables are ordered by a ResourceHash before Timestamp for better filtering and compression, with daily partitions bounding time ranges, and the cluster runs as a single shard with multiple replicas. Metric metadata is deduplicated into an AggregatingMergeTree table keyed by MetricHash with FirstSeen/LastSeen tracking, and queries against it must use GROUP BY or FINAL because merges are not guaranteed to have happened.

  • Why Astronomer chose ClickHouse to power its new data observability platform, Astro Observe

    ClickHouse easyNovice

    Astronomer built Astro Observe, an observability platform for Apache Airflow, on ClickHouse Cloud after a per-customer Amazon RDS Postgres setup degraded on large time-range aggregations and forced limits on retained data. Airflow DAG and task events flow through an ingestion API and Go enrichment services into Kafka for buffering and replay, then into ClickHouse, while low-volume deployment and GitHub change events are written directly. Tables share common keys such as org_id, run_id and asset_id; per-table TTLs handle retention, MergeTree engines deduplicate, and materialized views precompute aggregations at insert time. The motivating numbers: 100 million tasks a month with a 1.5% failure rate, each failure taking about 1.24 hours to resolve.

  • How Respan is scaling LLM observability with ClickHouse Cloud

    ClickHouse mediumAdept

    Respan, an AI gateway with built-in LLM observability processing about 50 million events per day, moved ingestion and analytics from Postgres to ClickHouse Cloud after per-request transactional inserts began contending at 50-100 writes per second. The ClickHouse design keeps rows small by storing typed metric columns and truncating prompt and output text. Incremental materialized views cascade minute-level rollups into hourly rollups per dimension, while refreshable materialized views update user-metadata joins every 10 minutes. Trace spans arrive asynchronously and are linked to parents at query time, and argMax-style aggregates replace the expensive FINAL modifier so trace analytics stay memory-efficient at billions of rows.

  • How the D. E. Shaw group powers high-cardinality observability at scale with ClickHouse

    ClickHouse mediumAdept

    The D. E. Shaw group moved per-task resource metrics from its HPC grid, millions of high-cardinality time series keyed by unique task IDs, from an InfluxDB-protocol time-series platform to ClickHouse. In same-hardware benchmarks, a single ClickHouse node ingested about 3.5M samples/s against roughly 480k for a competitor, and queries that timed out elsewhere finished in seconds. Production keeps the InfluxDB line-protocol ingestion path through a custom batching service, backfills history by reading the old platform's files directly from disk, and stores 68 TB compressed on four replicated NVMe servers at about 530k inserts/s, with materialized views for capacity-planning dashboards. Tradeoffs included rewriting Prometheus-style queries in SQL and limited compression on unique-ID fields (up to 5x), while OpenTelemetry traces reach about 12.5x compression.

The quest for software engineering knowledge.

Look:
Layout: