:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Choosing a ClickHouse workload
Every ClickHouse call takes a Workload from posthog/clickhouse/workload.py:
sync_execute(..., workload=), execute_hogql_query(..., workload=), and QueryRunner(..., workload=).
The workload sets two things:
the cluster the query runs on, and the workload query tag that query_log_archive.lc_workload records.
Both feed capacity planning, so pick the workload on purpose.
The rule
- Pass
workload=explicitly at every new call site. Do not rely onWorkload.DEFAULT, unless the code runs both in a request and in the background and must follow its caller. - Say which workload you picked and why in the PR description.
If the reason is not clear from where the code runs, add a one-line comment at the call site, for example
workload=Workload.OFFLINE, # nightly recompute, no user waits for the result. - When you review a diff that adds a ClickHouse call, check that its workload matches the questions below.
Pick the workload
Answer in order and stop at the first yes.
| Question | Workload |
|---|---|
| Does the query read a table that exists only on the logs cluster? | LOGS |
| Does the query execute an Endpoints (the product) request? | ENDPOINTS |
| Does a person wait on screen for this result (an app request, a Max chat turn)? | ONLINE |
| Anything else: scheduled, batch, export, backfill, recompute, eval, digest | OFFLINE |
ONLINE is for latency a person feels.
A background job does not get faster with ONLINE.
It competes with interactive queries for the online replicas, or it runs on the offline replicas anyway and only gets the wrong tag (see below).
OFFLINE turns off hedged requests, so ClickHouse does not send a second copy of a slow query to another replica.
This keeps offline load off the online replicas when the offline replicas are busy.
Latency and failure rates are higher as a result, so offline work must tolerate retries.
How a workload resolves
sync_execute in posthog/clickhouse/client/execute.py can change the workload you pass:
DEFAULTwith API-key auth (personal API key, project secret key) becomesOFFLINE.DEFAULTin a Celery task becomesOFFLINE, except cache warming (Feature.CACHE_WARMUP), which staysONLINE.process_query_taskforcesONLINEfor app users andOFFLINEfor API-key users, even when you pass a workload explicitly. OnlyLOGSis exempt.- A
workload=ENDPOINTSquery tag becomesENDPOINTS. - Any
DEFAULTthat is left becomes the process default. The process default isCLICKHOUSE_DEFAULT_WORKLOAD, which isONLINEunless the deployment sets it. Celery switches its process default toOFFLINEbefore each task.
The tag and the host are separate
The workload is intent.
The host comes from the environment of the pod that runs the code, in get_kwargs_for_client:
ONLINEconnects toCLICKHOUSE_HOST.OFFLINEconnects toCLICKHOUSE_OFFLINE_CLUSTER_HOSTwhen the deployment sets it, and toCLICKHOUSE_HOSTwhen it does not.LOGSandENDPOINTSconnect to their own hosts.
A background worker deployment can point CLICKHOUSE_HOST at the offline replicas and set CLICKHOUSE_DEFAULT_WORKLOAD=OFFLINE.
Then ONLINE and OFFLINE from those pods both run on the offline replicas.
Passing ONLINE there does not move the query to the online replicas.
It only tags an offline query as online, which hides it from per-workload capacity numbers.
Moving a query between clusters is a deployment change, not a code change.
Check where queries land
posthog.query_log_archive records both the intent and the host.
Group recent initial queries by lc_workload and by whether hostname is an offline node.
An ONLINE tag on an offline host, from a service that is not in a request path, is a mislabeled call site.