ClickhouseTutorial
Building a .NET API Gateway with ClickHouse and Aspire
Summary
The tutorial builds a .NET distributed application around a YARP API gateway, two backend APIs, an analytics API, a Blazor dashboard, a load generator, and ClickHouse. Aspire’s AppHost coordinates these resources, injects connection strings and service endpoints, orders startup with dependency health checks, and exposes selected services through stable or external endpoints. The gateway records proxied requests in ClickHouse while emitting OpenTelemetry metrics for request counts, duration, and backend failures. A bounded queue and background ingestion keep request logging off the hot path, while a narrow schema and materialized view precompute minute-level aggregates for volume, p95 latency, error rates, and route comparisons. Aspire supplies live telemetry, whereas ClickHouse retains request history for analytical queries and drill-down into slow requests.
Context
The demo addresses the need to understand distributed systems both while they are running and after enough traffic has accumulated to reveal patterns. It distinguishes live operational telemetry from historical, aggregate analysis such as p95 latency, error rates, request volume, and route-level comparisons.
Approach / What changed
The application uses Aspire to orchestrate a ClickHouse resource, YARP gateway, backend APIs, analytics service, dashboard, and traffic generator. Service discovery, injected configuration, dependency ordering, and external endpoints are defined in the AppHost. The gateway writes request records through a bounded background-ingestion pipeline and emits OpenTelemetry metrics; ClickHouse stores the raw history and a materialized view maintains minute-level aggregate states for dashboard queries.
Takeaways
Aspire can manage ClickHouse as a first-class application resource, inject its connection string, provide health checks and tracing, and coordinate service startup without hard-coded peer URLs.
A bounded queue with background ingestion keeps gateway request logging off the hot path while retaining request history in ClickHouse.
A materialized view precomputes minute-level aggregate states, allowing dashboard queries to merge summaries instead of scanning the full request_logs table on every refresh.
Source and freshness
- Source
- clickhouse.com
- Published
- Added to Yomu
- Last updated
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.