ClickHouse
Audited from github.com/ClickHouse/ClickHouse
ClickHouse is an open-source, column-oriented SQL database for real-time analytics, built as a large C++/CMake monorepo with a vendored dependency tree covering coordination, streaming ingestion and cloud storage.
- Language
- C++
- Hosting
- Docker
- License
- Apache-2.0
- Running for
- 9 years
- Team
- 20+ people
Why this architecture
A single CMake super-project that vendors ~150 native dependencies (Arrow, gRPC, AWS/Azure/GCS SDKs, NuRaft, Delta Lake kernel) under contrib/ lets ClickHouse ship a largely self-contained, dependency-free binary and Docker image.
Tech stack by layer
8 technologies · audited Sep 17, 2026- C++Implements the query engine, storage layer and SQL execution, compiled through the root CMake super-project.
- RustBuilds a handful of native components (chcache build-cache client, vendored skim/prql/polyglot/wasmtime crates) wired into the CMake build via Corrosion.
- ANTLRGenerates the SQL parser from a formal grammar (vendored ANTLR4 C++ runtime and grammar files).
- gRPCVendored as an alternative client/server RPC protocol alongside the native TCP interface.
- Protocol BuffersSerialization format vendored for gRPC and other structured interchange.
- ClickHouse KeeperBuilt-in Raft coordination service (vendored NuRaft) that can replace ZooKeeper for replication and distributed DDL; ships its own Docker image.
- KafkaVendored C++ client (cppkafka) backing the Kafka table engine for streaming ingestion.
- Apache ArrowVendored columnar in-memory format used for Arrow-ecosystem interoperability.
- S3Vendored AWS C++ SDK components (including an S3-specific library) back S3-compatible object storage for tables and backups.
- Delta LakeVendored Delta Lake kernel (Rust) lets ClickHouse read Delta Lake tables directly, matching the repo topic "lakehouse".
- DockerPackages server, keeper and a minimal "bare" image from Ubuntu/Alpine bases with a shared entrypoint.
- CMakeRoot build system orchestrating the C++ core plus ~150 vendored dependencies under contrib/ and the Rust workspace.
- GitHub ActionsRuns the workflow suite (pull_request, master, nightly fuzzers/jepsen/keeper, weekly official docker, merge queue).
- PraktikaClickHouse's own Python-based CI orchestration framework that composes the GitHub Actions job graph.
ClickHouse architecture diagram
Open SVGDiagram as text
- Clients (native TCP · HTTP · gRPC) → clickhouse-server (C++ query engine): queries · inserts
- clickhouse-server (C++ query engine) → SQL parser (ANTLR4 grammar): parse
- clickhouse-server (C++ query engine) → Table storage (columnar tables): read / write
- clickhouse-server (C++ query engine) → ClickHouse Keeper (Raft coordination): replication
- Kafka (streaming ingestion) → clickhouse-server (C++ query engine): Kafka engine
- clickhouse-server (C++ query engine) → Object storage (S3 · Delta Lake): S3 · lakehouse
Key architectural decisions
7 decisions- 01
The C++ core is a single CMake super-project with contrib/ as a vendored dependency tree
Instead of relying on system packages or a package manager, the root CMakeLists.txt pulls in roughly 150 subdirectories under contrib/ (abseil-cpp, arrow, aws, azure, boost, google-cloud-cpp, grpc, icu, jemalloc, and more), each paired with its own -cmake wrapper directory, so the server builds as a mostly self-contained binary.
- 02
Rust components integrate into the CMake build via Corrosion, not a separate pipeline
rust/workspace/Cargo.toml defines a workspace with skim, prql, polyglot and wasmtime crates, and rust/chcache/Cargo.toml defines a standalone build-cache client; contrib/corrosion bridges Cargo output into the CMake/Ninja build graph so Rust does not need its own release process.
- 03
SQL parsing is generated from a formal ANTLR4 grammar, not a hand-rolled parser
The languages breakdown shows a dedicated ANTLR byte count, and contrib/antlr4-cpp-runtime plus contrib/antlr4-grammars are vendored so the SQL grammar can be regenerated as part of the build rather than maintained as ad hoc parsing code.
- 04
Cluster coordination is built in-house (ClickHouse Keeper) instead of requiring ZooKeeper
docker/keeper/Dockerfile packages a dedicated Keeper image (multi-stage from ubuntu:22.04 to copy glibc, then FROM alpine), backed by the vendored NuRaft Raft-consensus library in contrib/NuRaft, so operators can run replication and distributed DDL coordination without standing up a separate ZooKeeper ensemble.
- 05
CI runs on a custom Python orchestrator layered on top of plain GitHub Actions workflows
ci/praktika holds the orchestration code and ci/pyproject.toml configures ruff/pylint/black for it; the workflow list includes custom_build_praktika.yml alongside more conventional pull_request.yml, master.yml and a large set of nightly_* jobs (fuzzers, jepsen, keeper faults, sqlancer, statistics).
- 06
Cloud object storage and lakehouse table formats are vendored as first-class C++/Rust deps
contrib/aws-c-s3, contrib/azure and contrib/google-cloud-cpp give the engine native S3/Blob/GCS clients, while contrib/arrow, contrib/avro and contrib/delta-kernel-rs let it read external columnar and lakehouse formats directly, consistent with the "lakehouse" and "cloud-native" repo topics.
- 07
Server images are minimal, multi-stage Docker builds, not one generic image
docker/server/Dockerfile is a thin FROM Dockerfile.ubuntu wrapper (kept only so tests/ci/docker_server.py can push unsuffixed tags), docker/keeper/Dockerfile is a separate Alpine-based image with a glibc-donor build stage, and docker/bare/Dockerfile exists as a third minimal variant.
How ClickHouse is built
How ClickHouse is structured
ClickHouse is organized as one large CMake project rather than a set of independently versioned packages. The root CMakeLists.txt drives the build, cmake/ holds toolchain, sanitizer and platform-detection modules, and base/ provides compatibility shims (darwin-compatibility, glibc-compatibility, glibc-rseq) for building across Linux, macOS and other targets. The bulk of the tree by directory count is contrib/, which vendors on the order of 150 third-party C++ and Rust libraries as git submodules, each usually paired with a <name>-cmake wrapper directory that adapts the upstream build to ClickHouse's CMake conventions. rust/ holds a Cargo workspace (rust/workspace/Cargo.toml, members skim, prql, polyglot, wasmtime) plus the standalone rust/chcache build-cache client, both wired into the same CMake build via the vendored contrib/corrosion bridge. ci/ contains a large, separately-linted Python codebase (its own pyproject.toml, ci/praktika orchestrator) that drives continuous integration independently of the C++ core.
Backend & APIs
The query engine and storage layer are C++, compiled through the root CMake super-project. SQL parsing is generated rather than hand-written: the languages breakdown reports a distinct ANTLR byte count, and contrib/antlr4-cpp-runtime and contrib/antlr4-grammars are vendored so the grammar is checked into the tree and regenerated during the build. For RPC, contrib/grpc and contrib/google-protobuf are vendored, giving ClickHouse a gRPC interface alongside its native TCP protocol. Rust plays a narrower, supporting role — rust/chcache is a native build-cache client (dependencies include clickhouse, tokio, blake3), and the rust/workspace crates (skim, prql, polyglot, wasmtime) are vendored native libraries rather than a second application layer.
Data & persistence
ClickHouse is itself the data store, but several vendored components define how it talks to other systems. Cluster coordination and distributed DDL are handled by ClickHouse Keeper, a Raft-based service built on the vendored contrib/NuRaft library and packaged as its own multi-stage Docker image (docker/keeper/Dockerfile, built from an ubuntu:22.04 glibc-donor stage onto alpine) — this is explicitly positioned to substitute for an external ZooKeeper ensemble. Streaming ingestion goes through a vendored Kafka client (contrib/cppkafka). For interoperability with external formats, contrib/arrow and contrib/avro are vendored, and contrib/delta-kernel-rs (a Rust Delta Lake kernel) lets the engine read Delta Lake tables directly — consistent with the repo's "lakehouse" topic. Cloud object storage is likewise vendored rather than left to an external SDK: contrib/aws-c-s3 (S3), contrib/azure, and contrib/google-cloud-cpp (GCS) are all present in the dependency tree.
Build, test & deploy
The build is CMake-driven and cross-platform, with cmake/toolchain and per-OS directories (cmake/darwin, cmake/linux, cmake/freebsd, cmake/sunos) plus WebAssembly support (cmake/wasm). Python tooling is governed by two separate pyproject.toml files — one at the repo root, one under ci/ — both configuring ruff, pylint and black (pinned to black version 26) for the test and CI scripts. CI itself runs on GitHub Actions but is layered on top of a custom orchestrator: ci/praktika is invoked from custom_build_praktika.yml, alongside a large, explicit workflow list that includes pull_request.yml, master.yml, merge_queue.yml, and a long tail of nightly_* jobs (nightly_fuzzers.yml, nightly_jepsen.yml, nightly_keeper.yml, nightly_keeper_faults.yml, nightly_sqlancer.yml, nightly_statistics.yml) plus weekly_official_docker.yml and weekly_cfi.yml. Distribution is via three Docker images — a full server (docker/server/Dockerfile, itself a thin wrapper delegating to Dockerfile.ubuntu), Keeper (docker/keeper/Dockerfile), and a minimal docker/bare/Dockerfile — built by dedicated builder images under ci/docker/ (binary-builder, fuzzer, performance-comparison, wasm-builder, docs-builder).
Self-hosting notes
The README documents a one-line install (curl https://clickhouse.com/ | sh) for Linux, macOS and FreeBSD, in addition to the Docker images described above. Because coordination is handled by the bundled ClickHouse Keeper rather than an external ZooKeeper, a self-managed cluster does not require standing up a separate coordination service. Cloud storage backends (S3, Azure Blob, GCS) are compiled in, so self-hosted deployments can point MergeTree storage or backups at object storage without extra plugins.
What to copy (and what not to)
The contrib/ vendoring pattern — pinning every native dependency as a submodule with its own CMake wrapper — is worth studying for any project that needs reproducible, dependency-free native builds, but it is a heavyweight approach: ClickHouse maintains on the order of 150 such directories, which is only proportionate at this scale. The Corrosion-based Rust-into-CMake integration (rust/workspace, contrib/corrosion) is a useful reference for teams mixing Rust components into a mature C/C++ build rather than rewriting the whole build system. The layered CI (plain GitHub Actions workflows plus the in-house ci/praktika orchestrator) reflects a test matrix (fuzzers, Jepsen, SQLancer, statistics, coverage) large enough to need its own scheduler — smaller projects are unlikely to need a comparable custom layer on top of Actions.
Sources & repo audit
- Audited
- Sep 17, 2026
- Commit
- ddba901
- License
- Apache-2.0
- Root CMakeLists.txt (single CMake super-project)
- rust/workspace/Cargo.toml (vendored Rust crates, built via Corrosion)
- docker/keeper/Dockerfile (ClickHouse Keeper image)
- ci/pyproject.toml (Python lint/format config for the CI tooling)
- .github/workflows (CI workflow suite, incl. custom_build_praktika.yml)
- contrib/ (vendored C++/Rust dependency tree: arrow, aws-c-s3, grpc, NuRaft, delta-kernel-rs, etc.)
Independent analysis of repository at github.com/ClickHouse/ClickHouse. Spotted an inaccuracy? Use the claim form to request a correction.
Show this stack on your README or website
[](https://stackitfast.com/project/clickhouse)Paste it into your README. It shows your current stack and links to this page.
Scaffold it with your agent
Paste this prompt into Claude Code, Cursor, Windsurf or AGY to start a project with ClickHouse's architecture.
- 1Copy the promptThe full markdown spec, with every layer and decision.
- 2Open your AI toolClaude Code, Cursor, Windsurf or Copilot, in a new repo.
- 3Paste and scaffoldUse it as the first instruction; review before you ship.
# MISSION: Scaffold "ClickHouse" Production Architecture
You are an expert Senior Staff Software Architect and Full-Stack Engineer. Your mission is to scaffold and implement a production-grade, highly reliable, and modular codebase following the proven architecture of **ClickHouse**.
---
## 1. PROJECT SPECIFICATIONS & BENCHMARK
- **Reference Architecture**: ClickHouse
- **What It Does**: ClickHouse is an open-source, column-oriented SQL database for real-time analytics, built as a large C++/CMake monorepo with a vendored dependency tree covering coordination, streaming ingestion and cloud storage.
- **Domain & Category**: Columnar Real-Time Analytical Database (OLAP)
- **Production Scale**: 20+ people
- **Development Mode**: CLASSIC
- **Architectural Rationale**: A single CMake super-project that vendors ~150 native dependencies (Arrow, gRPC, AWS/Azure/GCS SDKs, NuRaft, Delta Lake kernel) under contrib/ lets ClickHouse ship a largely self-contained, dependency-free binary and Docker image.
- **Live Website Reference**: https://clickhouse.com
- **Source Repository**: https://github.com/ClickHouse/ClickHouse
---
## 2. PRODUCTION TECH STACK
- **Full Stack Array**: C++, CMake, Python, Rust, Docker, gRPC, Protocol Buffers, Kafka
- **Primary Language(s)**: C++, Python, Shell
- **License of the reference repo**: Apache-2.0
- **Backend & APIs**: C++ — Implements the query engine, storage layer and SQL execution, compiled through the root CMake super-project.; Rust — Builds a handful of native components (chcache build-cache client, vendored skim/prql/polyglot/wasmtime crates) wired into the CMake build via Corrosion.; ANTLR — Generates the SQL parser from a formal grammar (vendored ANTLR4 C++ runtime and grammar files).; gRPC — Vendored as an alternative client/server RPC protocol alongside the native TCP interface.; Protocol Buffers — Serialization format vendored for gRPC and other structured interchange.
- **Data & persistence**: ClickHouse Keeper — Built-in Raft coordination service (vendored NuRaft) that can replace ZooKeeper for replication and distributed DDL; ships its own Docker image.; Kafka — Vendored C++ client (cppkafka) backing the Kafka table engine for streaming ingestion.; Apache Arrow — Vendored columnar in-memory format used for Arrow-ecosystem interoperability.; S3 — Vendored AWS C++ SDK components (including an S3-specific library) back S3-compatible object storage for tables and backups.; Delta Lake — Vendored Delta Lake kernel (Rust) lets ClickHouse read Delta Lake tables directly, matching the repo topic "lakehouse".
- **Infrastructure & deploy**: Docker — Packages server, keeper and a minimal "bare" image from Ubuntu/Alpine bases with a shared entrypoint.; CMake — Root build system orchestrating the C++ core plus ~150 vendored dependencies under contrib/ and the Rust workspace.; GitHub Actions — Runs the workflow suite (pull_request, master, nightly fuzzers/jepsen/keeper, weekly official docker, merge queue).; Praktika — ClickHouse's own Python-based CI orchestration framework that composes the GitHub Actions job graph.
---
## 3. KEY ARCHITECTURAL DECISIONS (audited from https://github.com/ClickHouse/ClickHouse @ ddba901)
1. **The C++ core is a single CMake super-project with contrib/ as a vendored dependency tree**: Instead of relying on system packages or a package manager, the root CMakeLists.txt pulls in roughly 150 subdirectories under contrib/ (abseil-cpp, arrow, aws, azure, boost, google-cloud-cpp, grpc, icu, jemalloc, and more), each paired with its own -cmake wrapper directory, so the server builds as a mostly self-contained binary.
2. **Rust components integrate into the CMake build via Corrosion, not a separate pipeline**: rust/workspace/Cargo.toml defines a workspace with skim, prql, polyglot and wasmtime crates, and rust/chcache/Cargo.toml defines a standalone build-cache client; contrib/corrosion bridges Cargo output into the CMake/Ninja build graph so Rust does not need its own release process.
3. **SQL parsing is generated from a formal ANTLR4 grammar, not a hand-rolled parser**: The languages breakdown shows a dedicated ANTLR byte count, and contrib/antlr4-cpp-runtime plus contrib/antlr4-grammars are vendored so the SQL grammar can be regenerated as part of the build rather than maintained as ad hoc parsing code.
4. **Cluster coordination is built in-house (ClickHouse Keeper) instead of requiring ZooKeeper**: docker/keeper/Dockerfile packages a dedicated Keeper image (multi-stage from ubuntu:22.04 to copy glibc, then FROM alpine), backed by the vendored NuRaft Raft-consensus library in contrib/NuRaft, so operators can run replication and distributed DDL coordination without standing up a separate ZooKeeper ensemble.
5. **CI runs on a custom Python orchestrator layered on top of plain GitHub Actions workflows**: ci/praktika holds the orchestration code and ci/pyproject.toml configures ruff/pylint/black for it; the workflow list includes custom_build_praktika.yml alongside more conventional pull_request.yml, master.yml and a large set of nightly_* jobs (fuzzers, jepsen, keeper faults, sqlancer, statistics).
6. **Cloud object storage and lakehouse table formats are vendored as first-class C++/Rust deps**: contrib/aws-c-s3, contrib/azure and contrib/google-cloud-cpp give the engine native S3/Blob/GCS clients, while contrib/arrow, contrib/avro and contrib/delta-kernel-rs let it read external columnar and lakehouse formats directly, consistent with the "lakehouse" and "cloud-native" repo topics.
7. **Server images are minimal, multi-stage Docker builds, not one generic image**: docker/server/Dockerfile is a thin FROM Dockerfile.ubuntu wrapper (kept only so tests/ci/docker_server.py can push unsuffixed tags), docker/keeper/Dockerfile is a separate Alpine-based image with a glibc-donor build stage, and docker/bare/Dockerfile exists as a third minimal variant.
---
## 4. NON-NEGOTIABLE ARCHITECTURAL GUARDRAILS
1. **Monorepo & Modular Separation**:
- Structure as a Turborepo monorepo with strict package boundaries:
- `apps/web`: Application UI, routing, layouts, and server endpoints.
- `packages/ui`: Shared design tokens, CSS variables, and Radix UI primitive components.
- `packages/db`: Database schemas, client singleton, declarative migrations, and seed scripts.
- `packages/config`: Shared TypeScript, ESLint, and build configurations.
2. **Strict Type Safety & Zero `any` Policy**:
- Enable `strict: true`, `noImplicitAny: true`, and `strictNullChecks: true`.
- Validate ALL external inputs, API request bodies, and query parameters with **Zod** schemas before execution.
3. **Frontend & Rendering Guidelines**:
- Isolate interactive UI state to leaf components. Keep core pages lightweight and performant.
4. **Design System & Aesthetics**:
- Keep every color, radius, shadow and font in a single token file (CSS variables) and consume tokens everywhere; never hardcode hex values in components.
- Prefer crisp 1px borders and one subtle shadow scale over blurry default shadows. Pair one sans-serif for body/headings with one monospace for tags, badges, metrics, and code.
5. **Data Layer & Reliability**:
- Write declarative schema definitions with foreign keys, composite indexes on queried filters, and automated timestamp triggers.
- Use connection pooling and prepared statements for serverless database execution.
---
## 5. STEP-BY-STEP SCAFFOLDING ROADMAP
- **Phase 1: Workspace & Root Config**: Initialize package manager, monorepo configuration (`turbo.json`, `tsconfig.base.json`, `package.json`).
- **Phase 2: Database Schema & Client**: Set up the data layer (ClickHouse Keeper, Kafka, Apache Arrow, S3, Delta Lake): client, connection pool, models, and migration scripts.
- **Phase 3: Design Tokens & UI Primitives**: Build accessible `Button`, `Input`, `Card`, `Badge`, and layout wrappers inside `packages/ui`.
- **Phase 4: Core Application Routes & Handlers**: Implement primary authentication, user session handling, and application routes.
- **Phase 5: Quality Assurance & Build Verification**: Run `tsc --noEmit`, ESLint, Prettier, and smoke test suites to ensure zero compilation or runtime errors.
---
## 6. EXECUTION INSTRUCTIONS
1. Review all specifications, architectural guardrails, and stack choices above.
2. Present the full monorepo directory tree structure.
3. Systematically generate the complete, production-ready codebase according to the 5-phase roadmap above — starting with the root workspace setup, followed by the database schema, UI design system package, and full-stack application routes until the repository is fully scaffolded and ready to run.Frequently asked about ClickHouse
What is ClickHouse built with?
Mostly C++ compiled through a single root CMake project, with Python driving CI tooling and test scripts, and Rust used for a handful of native components (a build-cache client and vendored skim/prql/polyglot/wasmtime crates) integrated into the CMake build via Corrosion. It ships as Docker images built from Ubuntu and Alpine bases.
Does ClickHouse need ZooKeeper?
No. It ships its own Raft-based coordination service, ClickHouse Keeper, packaged as a separate Docker image (docker/keeper/Dockerfile) and built on the vendored NuRaft consensus library, which can replace ZooKeeper for replication and distributed DDL coordination.
Can I self-host ClickHouse?
Yes. The README documents a one-line install script for Linux/macOS/FreeBSD, and the repo publishes separate Docker images for the full server, ClickHouse Keeper, and a minimal "bare" variant, alongside instructions to build from source via the root CMakeLists.txt.
Does ClickHouse support Delta Lake and other lakehouse formats?
The repository is tagged with the "lakehouse" topic and vendors a Rust Delta Lake kernel (contrib/delta-kernel-rs) plus Apache Arrow and Avro (contrib/arrow, contrib/avro), giving the engine built-in readers for external table formats rather than requiring a separate connector.
How does ClickHouse handle cloud object storage?
AWS, Azure and Google Cloud client libraries are vendored directly into the C++ build (contrib/aws-c-s3, contrib/azure, contrib/google-cloud-cpp), so S3-, Blob- and GCS-backed storage is compiled into the server binary rather than bolted on as a plugin.
One email a month: new deep dives and stack trends
New source-audited architectures, head-to-head comparisons and the monthly stack report. No spam, unsubscribe anytime.
Similar architectures
- QuestDBClassicTime-Series SQL Database · 20+ PeopleShares Rust · C++ · Docker
- RustFSClassicS3-Compatible Object Storage · 20+ peopleShares Rust · gRPC · Docker
- DragonflyClassicMulti-Threaded In-Memory Key-Value Store · 20+ PeopleShares C++ · CMake · Python
- SurrealDBClassicMulti-Model Real-Time Database · 20+ PeopleShares Rust · Docker
- QdrantClassicVector Similarity Search Engine · 20+ PeopleShares Rust · Docker · gRPC
- MeilisearchClassicSearch Engine · 20+ peopleShares Rust · Docker