---
title: "Building a .NET API Gateway with ClickHouse and Aspire"
description: "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."
---

# Building a .NET API Gateway with ClickHouse and Aspire

[Clickhouse](https://yomu.fyi/company/clickhouse) · Jun 2, 2026

**Type:** Tutorial

## 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.

**Tags:** [Architecture](https://yomu.fyi/topic/architecture), [Microservices](https://yomu.fyi/topic/microservices), [Observability](https://yomu.fyi/topic/observability), [Performance](https://yomu.fyi/topic/performance)

- Source: [Clickhouse](https://clickhouse.com/blog/dotnet-api-gateway-aspire)
- Source URL: https://clickhouse.com/blog/dotnet-api-gateway-aspire
- Ingested by Yomu: 2026-08-29T01:34:02.400Z

[Read original post](https://clickhouse.com/blog/dotnet-api-gateway-aspire)
