clickhouse-go

The official Go driver for ClickHouse, pairing a fast native protocol client with full database/sql compatibility.

Library
Go
vv2.49.0
3,353 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
95 /100 Excellent
Development Activity 100
Maintenance 96
Community 84
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
88 /100 Excellent
Architecture 88
Code Quality 90
Innovation 85
Learning Curve 88

clickhouse-go is ClickHouse’s official Golang database driver, maintained by the ClickHouse team itself. It exposes two ways to talk to a ClickHouse server: a ClickHouse-specific driver.Conn interface (clickhouse.Open) that speaks the native wire protocol for maximum throughput, and a standard database/sql-compatible interface (clickhouse.OpenDB / sql.Open) for teams that want to reuse existing tooling, ORMs, and connection-pooling conventions.

Both interfaces work over TCP-native and HTTP transports, and the driver leans on ClickHouse’s own low-level ch-go client for column encoding, decoding, and compression. It covers the breadth of ClickHouse’s type system (including newer types like BFloat16, Dynamic, Variant, and geo types), supports bulk batch inserts, async inserts, connection pooling with failover/load balancing, structured logging via log/slog, JWT authentication, and OpenTelemetry-aware query context.

What You Get

  • A native driver.Conn interface (clickhouse.Open) using ClickHouse’s binary wire protocol for the fastest column-oriented reads and writes
  • A standard database/sql implementation (clickhouse.OpenDB) that works with existing Go database tooling, migration tools, and ORMs expecting the stdlib interface
  • Bulk batch insert support (PrepareBatch) and async inserts for high-throughput ingestion workloads
  • Connection pooling with configurable open strategies (in-order, round-robin, random) and automatic failover across multiple ClickHouse addresses
  • Broad ClickHouse type coverage — Decimal, Map, Array, Tuple, Nested, JSON, geo types, BFloat16, Dynamic, and Variant — with struct scanning/marshaling helpers
  • Structured logging via Go’s log/slog, JWT auth, LZ4/ZSTD/Brotli/GZIP compression, and OpenTelemetry-aware query context

Common Use Cases

  • Powering analytics dashboards and reporting services that query ClickHouse directly from Go backends
  • High-throughput event or log ingestion pipelines that batch-insert rows via the native protocol
  • Migrating an existing database/sql-based Go service onto ClickHouse without rewriting its data-access layer
  • Building internal tooling or CLIs that need typed access to ClickHouse-specific column types (JSON, geo, Dynamic/Variant)
  • Streaming query results or inserts in raw formats (CSV, JSONEachRow, Parquet) over HTTP for interop with external systems

Under The Hood

Architecture

The driver is organized as a small set of layers rather than one monolithic client: the top-level clickhouse package exposes Open/OpenDB entry points that dispatch to one of two transport implementations — a native TCP path (conn.go, conn_pool.go, backed by an internal circular-queue connection pool with lifetime-based eviction) or an HTTP path (conn_http.go) — both implementing a shared internal transport interface so the rest of the driver is protocol-agnostic. Row/column encoding and the ClickHouse wire format live in lib/column and lib/proto, decoupled from connection handling, while lib/driver defines the public driver.Conn/driver.Batch contracts that both the native API and the database/sql adapter (clickhouse_std.go) implement against. This separation means the database/sql surface is a thin wrapper reusing the same dial/connect functions as the native client rather than a parallel implementation, so a change to the wire protocol only needs to happen once.

Tech Stack

Built on Go 1.25 with the toolchain pinned in go.mod. Column encoding, decoding, and compression delegate to ClickHouse’s own low-level ch-go library rather than reimplementing the wire format locally. Compression support spans LZ4, ZSTD, GZIP, Deflate, and Brotli (andybalholm/brotli). Integration tests spin up real ClickHouse instances via testcontainers-go and Docker Compose rather than mocks. Additional dependencies cover OpenTelemetry tracing (go.opentelemetry.io/otel), geo types (paulmach/orb), arbitrary-precision decimals (shopspring/decimal), and UUID generation (google/uuid).

Code Quality

The repository carries an extensive test suite — 259 _test.go files covering unit tests, benchmark tests, and fuzz tests (e.g. conn_http_errors_fuzz_test.go) built on testify assertions, alongside a tests/ directory of integration tests that run against live ClickHouse containers. CI (.github/workflows/) runs separate workflows for head-of-branch tests, ClickHouse Cloud tests, linting, and CodeQL static analysis, plus a docs-sync check that keeps the published documentation in step with the code. Error handling is explicit throughout, using sentinel errors.New values (ErrBatchInvalid, ErrConnectionClosed, etc.) and a typed OpError wrapper rather than bare error strings.

API Design The defining design choice is offering two API surfaces — a ClickHouse-native interface for performance-sensitive code and a database/sql-compatible one for drop-in use with existing Go tooling — built on the same underlying connection and encoding layers so neither is a second-class citizen. On top of that it exposes ClickHouse-specific ergonomics that a generic SQL driver wouldn’t: typed struct scanning/appending, batch-release-connection helpers, named/numeric/positional parameter binding, and direct support for ClickHouse’s more unusual types (Dynamic, Variant, LineString) without falling back to raw bytes.

Used by 19 apps in this directory

Go
49%
MIT

Bytebase

Devops

14,625

An open-source database CI/CD and DevSecOps platform — schema migration review, GitOps-driven changes, data masking, and access control across MySQL, PostgreSQL, Oracle, Snowflake, MongoDB, and more.

View details
92
Repo Health
73
Technical
68
Dependency
Built with
Go 49%
TypeScript 43%
Updated 6 days ago
Go
63%
Apache 2.0

Coroot

Analytics · Monitoring

7,982

eBPF-powered observability with AI root cause analysis — zero code changes required, full-stack visibility out of the box.

View details
88
Repo Health
80
Technical
66
Dependency
Built with
Go 63%
Vue 35%
Updated 1 weeks ago
Go
76%
Other

Flipt

Developer Tools · Devops

4,926

Git-native feature flag platform that stores, versions, and deploys feature toggles directly in your own Git repositories with no external database required.

View details
90
Repo Health
83
Technical
68
Dependency
Built with
Go 76%
TypeScript 23%
Updated 5 days ago
TypeScript
71%
Other

highlight.io

Analytics · Developer Tools · Monitoring

9,384

Open-source full-stack monitoring that unifies session replay, error tracking, logging, and distributed tracing so you can stop context-switching between tools.

View details
76
Repo Health
78
Technical
65
Dependency
Built with
TypeScript 71%
Go 16%
Updated 6 days ago
TypeScript
97%
MIT

HyperDX

Analytics · Developer Tools · Monitoring

9,963

Open source observability platform that unifies logs, traces, metrics, and session replays on ClickHouse — now the core of ClickStack.

View details
89
Repo Health
83
Technical
64
Dependency
Built with
TypeScript 97%
Updated 5 days ago
TypeScript
66%
MIT

Jitsu

Data Engineering

5,110

Open-source, fully-scriptable data ingestion engine that streams events from web, apps, and APIs to any data warehouse in real time.

View details
89
Repo Health
79
Technical
66
Dependency
Built with
TypeScript 66%
Go 32%
Updated 6 days ago
Go
97%
MIT

Formance Ledger

Databases · Developer Tools · Invoicing Finance

1,448

The programmable open source core ledger for fintech — build money-moving applications with atomic multi-posting transactions, account-based modeling, and Numscript, a built-in DSL for financial logic.

View details
91
Repo Health
8
Technical
68
Dependency
Built with
Go 97%
Updated 5 days ago
Go
97%
Other

Netmaker

Automation · Security

11,836

Automate secure WireGuard mesh networks from homelab to enterprise scale without manual configuration.

View details
92
Repo Health
79
Technical
70
Dependency
Built with
Go 97%
Updated 6 days ago
Go
98%
Apache 2.0

Nightingale

Monitoring

13,383

Open-source alerting engine that connects to any time-series or log data source and routes alarms to 20+ notification channels with AI-assisted triage.

View details
95
Repo Health
77
Technical
67
Dependency
Built with
Go 98%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers