---
title: "Building a .NET API Gateway with ClickHouse and Aspire"
description: "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."
url: "https://swe.quest/articles/building-a-net-api-gateway-with-clickhouse-and-aspire-d43f7774c1e69e19"
canonical: "https://clickhouse.com/blog/dotnet-api-gateway-aspire"
source: "ClickHouse"
published: "2026-06-02"
difficulty: "medium"
kind: "How-to"
reading_minutes: 13
tags: ["dotnet","analytics","observability","load-balancing"]
---

# Building a .NET API Gateway with ClickHouse and Aspire

A post on [ClickHouse](https://swe.quest/sources/clickhouse.md), published 2026-06-02, 13 min read, How-to. Original: [https://clickhouse.com/blog/dotnet-api-gateway-aspire](https://clickhouse.com/blog/dotnet-api-gateway-aspire)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [.NET](https://swe.quest/tags/dotnet.md) (Languages)
- [Analytics & OLAP](https://swe.quest/tags/analytics.md) (Data & databases)
- [Observability](https://swe.quest/tags/observability.md) (Reliability & operations)
- [Load balancing](https://swe.quest/tags/load-balancing.md) (Infrastructure)

## Prerequisites

- ASP.NET Core
- dependency injection in .NET ([easy posts on Application security](https://swe.quest/tags/appsec.md?difficulty=easy))
- SQL basics ([easy posts on SQL](https://swe.quest/tags/sql.md?difficulty=easy))

## Keywords

ClickHouse, Aspire, YARP, OpenTelemetry, Blazor, AggregatingMergeTree, System.Threading.Channels

## Related posts

- [Structured Logging in .NET with Serilog and ClickHouse](https://swe.quest/articles/structured-logging-in-net-with-serilog-and-clickhouse-433c37101ab76f06.md): ClickHouse · 2026-03-23 · Medium · 20 min read · .NET, Observability, Analytics & OLAP
  Serilog's ClickHouse sink lets an ASP.NET service write structured logs directly into a ClickHouse table with one WriteTo.ClickHouse() call.
- [Building an Observability Solution with ClickHouse at Dash0](https://swe.quest/articles/building-an-observability-solution-with-clickhouse-at-dash0-f950ba66eb3161c6.md): ClickHouse · 2025-04-07 · Hard · 18 min read · Analytics & OLAP, Observability, Storage engines, Databases, Cost optimization
  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.
- [Why Astronomer chose ClickHouse to power its new data observability platform, Astro Observe](https://swe.quest/articles/why-astronomer-chose-clickhouse-to-power-its-new-data-observability-platform-f5c7916b8461008d.md): ClickHouse · 2025-03-10 · Easy · 7 min read · Analytics & OLAP, Observability, Data pipelines, Queues & messaging
  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.
- [How Respan is scaling LLM observability with ClickHouse Cloud](https://swe.quest/articles/how-respan-is-scaling-llm-observability-with-clickhouse-cloud-a4578d78266aa225.md): ClickHouse · 2026-04-06 · Medium · 6 min read · Analytics & OLAP, Observability, PostgreSQL, LLMs
  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.
- [How the D. E. Shaw group powers high-cardinality observability at scale with ClickHouse](https://swe.quest/articles/how-the-d-e-shaw-group-powers-high-cardinality-observability-at-scale-with-b74a9887c2072ab0.md): ClickHouse · 2026-05-15 · Medium · 7 min read · Observability, Analytics & OLAP, Scaling, Capacity planning
  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.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
