docs: HTTP sessions on a multi-replica ClickHouse Cloud service need replica-aware routing

Open
#765 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@laeg is already working on this.

Since Nov 24, 2026.

  • #766 by @laeg — open

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
30/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
documentation

Research direction

Read docs/http.mdx, especially the Session management section and Best practices > Sessions, then look at TestUtilities.GetTestCustomHeaders() and ClickHouse.Driver/AGENTS.md for the exact header pattern the repo already uses. The note should say state lives on the serving replica, show a snippet sending X-ClickHouse-Replica-Tag per session, and list the best-effort/scaling caveats, with a cross-link from Best practices. An open PR (#766) already covers this, so check it before duplicating work.

Written by the indexing model from the issue text.

Description

documentation

TLDR: On a ClickHouse Cloud service with more than one replica, UseSession alone doesn't keep a session's queries on one replica, so a temporary table or a SET can vanish between two queries. docs/http.mdx doesn't say so, though this repo's own Cloud tests already work around it with X-ClickHouse-Replica-Tag.

What happens

A session's temporary tables and settings live on the replica that ran the query. Cloud load-balances HTTP requests across replicas, and session_id doesn't influence which replica a request reaches.

Measured on a ClickHouse Cloud service (26.6, 3–4 replicas) with driver 1.5.0:

HTTP replica-aware routing Client Result
off 12 requests, same session_id, new connections answered by all 3 replicas (4 / 3 / 5)
on 12 requests, same session_id, one kept-alive connection answered by 4 replicas
on 12 requests with X-ClickHouse-Replica-Tag answered by 1 replica
on 10 sessions: UseSession = true, then CREATE TEMPORARY TABLE, INSERT, 3 × SELECT 10 of 10 failed (Unknown table expression identifier)
on the same 10 sessions with CustomHeaders = { ["X-ClickHouse-Replica-Tag"] = sessionId } 0 of 10 failed

Replica-aware routing fixes this. Turn on the service's HTTP toggle, and send the same X-ClickHouse-Replica-Tag on every request of the session. The repo already does this for its Cloud test runs, in TestUtilities.GetTestCustomHeaders(), and notes it in ClickHouse.Driver/AGENTS.md: "without them, a session, a Memory table or a read of a row that the test just inserted can reach another replica and fail". Only the user-facing docs are missing it.

Proposed change

In docs/http.mdx, add a note to Session management and a pointer to it from Best practices > Sessions:

  • sessions keep state only on the replica that served the query;
  • on a multi-replica Cloud service, turn on HTTP replica-aware routing and send X-ClickHouse-Replica-Tag with every query of the session, with a snippet;
  • the caveats: best-effort, and a tag can move to another replica when the service scales.

Docs only; no code change. A PR follows.

Dominant language
C#
Stars
102
Forks
31
Avg merge
2d 13h
Merged PRs (30d)
40

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ClickHouse/clickhouse-cs

All issues in ClickHouse/clickhouse-cs

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.