CockroachDB — Dependencies#
Module info#
- Module:
github.com/cockroachdb/cockroach - Go version: 1.25.5
- Direct dependencies: 216
- Indirect dependencies: 265 (481 total in go.mod)
- go.sum entries: 3,396 lines (~1,698 module versions)
Dependency categories#
Core infrastructure#
| Dependency | Role | Usage |
|---|---|---|
github.com/cockroachdb/errors | Error handling (custom fork) | 3,365 files — most-used dep |
github.com/cockroachdb/pebble | LSM storage engine | 165 files in pkg/storage |
github.com/cockroachdb/redact | Safe log/error redaction | 610 files |
github.com/cockroachdb/logtags | Structured log tags on ctx | 130 files |
github.com/cockroachdb/apd/v3 | Arbitrary-precision decimal | 146 files (SQL DECIMAL type) |
github.com/cockroachdb/cmux | Connection multiplexing | 7 files in pkg/server |
github.com/cockroachdb/tokenbucket | Rate limiting / admission | Used in admission control |
github.com/cockroachdb/crlib | Low-level CRDB utilities | 92 imports in pkg/ |
Key insight: CockroachDB maintains a substantial ecosystem of satellite packages under the cockroachdb/ GitHub org — these are not internal packages but separately versioned modules that have been extracted for reuse across CRDB tooling and the Pebble storage engine. The errors package alone is used in more than a third of all source files, functioning as a first-class citizen in the codebase.
Networking / RPC#
| Dependency | Role | Notes |
|---|---|---|
google.golang.org/grpc v1.57.2 | Primary inter-node RPC | 66 files; gRPC is the internal wire protocol |
storj.io/drpc v0.0.34 → CRDB fork | Lightweight alternative RPC | Added 2025; used in CLI clients and internal fast path |
github.com/gogo/protobuf v1.3.2 → CRDB fork | Protobuf serialization | 182 files — dominant protobuf library |
google.golang.org/protobuf v1.35.1 | Modern protobuf (google) | 19 files — limited to newer code |
github.com/grpc-ecosystem/grpc-gateway v1.16.0 | gRPC→HTTP transcoding | Admin API HTTP gateway |
github.com/cockroachdb/cmux | Protocol muxer on single port | Routes gRPC, HTTP, DRPC, PG wire |
Key insight: CockroachDB uses gogo/protobuf (their own fork: cockroachdb/gogoproto) rather than the official Google protobuf library. This predates the modern google.golang.org/protobuf API and gives them custom code generation extensions. The recent addition of storj.io/drpc (also forked as cockroachdb/drpc) represents an architectural shift — DRPC is a simpler, higher-performance RPC protocol used for CLI-to-server connections and select internal paths where gRPC overhead is undesirable.
Data / Storage#
| Dependency | Role | Notes |
|---|---|---|
github.com/cockroachdb/pebble | MVCC storage engine | LSM tree, RocksDB-inspired, pure Go |
github.com/jackc/pgx/v4 v4.18.3 | PostgreSQL client driver | 93 files; CRDB uses pgx to talk to itself |
github.com/jackc/pgx/v5 v5.7.2 | Newer PostgreSQL driver | 37 files (migration in progress) |
github.com/jackc/pgconn, pgtype, pgproto3 | pgwire protocol components | Wire protocol implementation |
github.com/lib/pq v1.10.9 | Legacy PostgreSQL driver | 78 files; older code paths |
github.com/apache/arrow/go/v11 | Columnar in-memory format | 22 files; vectorized execution engine (pkg/col) |
github.com/google/btree v1.1.3 | In-memory B-tree | 9 files; range cache, interval tree |
github.com/cockroachdb/swiss | Swiss-table hash map | High-perf map for hot paths |
github.com/golang/snappy v0.0.5 | Snappy compression | Network-level compression |
github.com/klauspost/compress v1.17.11 | Multi-algo compression | Backup/restore compression |
github.com/klauspost/pgzip | Parallel gzip | Bulk data operations |
github.com/pierrec/lz4/v4 | LZ4 compression | Changefeed sinks |
github.com/cockroachdb/datadriven | Data-driven test framework | 274 files — custom testing DSL |
Key insight: CockroachDB is its own storage engine user — it wraps Pebble (which it also develops). The separate pebble module versioning means Pebble can be released and tested independently. The Apache Arrow dependency powers the vectorized SQL execution engine (pkg/col), which operates on Arrow’s columnar batch format for OLAP-style query processing.
Cloud / Object Storage#
| Dependency | Role | Notes |
|---|---|---|
cloud.google.com/go/storage | GCS backup sink | Backup/restore, changefeed |
cloud.google.com/go/kms | Google KMS | Encryption-at-rest (CCL) |
cloud.google.com/go/pubsub | Google Pub/Sub | Changefeed sink |
github.com/aws/aws-sdk-go v1.40.37 | S3, AWS services (v1) | Backup/restore to S3 |
github.com/aws/aws-sdk-go-v2 | AWS SDK v2 (modern) | Migration in progress; S3, KMS, STS |
github.com/Azure/azure-sdk-for-go | Azure Blob, KMS, etc. | Azure backup, key management |
github.com/Azure/azure-sdk-for-go/sdk/... | Azure SDK v2 | Modern Azure integrations |
Key insight: CockroachDB carries both the old aws-sdk-go (v1) and the new aws-sdk-go-v2 simultaneously, indicating an ongoing migration. The cloud SDK dependencies are almost entirely confined to pkg/cloud/ and pkg/ccl/ (commercial features), particularly backup/restore and changefeed sinks.
Streaming / Message Queues (Changefeed)#
| Dependency | Role | Notes |
|---|---|---|
github.com/IBM/sarama v1.43.1 | Kafka client (Sarama) | Legacy Kafka sink in changefeedccl |
github.com/twmb/franz-go v1.18.0 | Kafka client (franz-go) | New Kafka client implementation |
github.com/apache/pulsar-client-go | Apache Pulsar sink | Changefeed → Pulsar |
github.com/cockroachdb/changefeedpb | Changefeed protobuf types | Serialization for CDC |
github.com/linkedin/goavro/v2 | Avro serialization | Kafka Avro format support |
github.com/snowflakedb/gosnowflake → CRDB fork | Snowflake sink | CDC to Snowflake DWH |
Key insight: The changefeed (CDC) system has two Kafka client libraries simultaneously — the older Sarama (IBM fork) and the newer franz-go. This dual-client situation mirrors the AWS SDK migration pattern and reflects the evolution of the streaming ecosystem. The franz-go library is widely adopted across the Go community and appears in multiple projects in this analysis set.
Observability#
| Dependency | Role | Notes |
|---|---|---|
github.com/prometheus/client_golang → CRDB fork | Metrics exposition | 40 files; CRDB forked to improve histogram perf |
github.com/prometheus/prometheus | Prometheus rules evaluation | 1.8.2-era; used for alerting rule support |
go.opentelemetry.io/otel | OpenTelemetry tracing | 48 files; traces, spans |
github.com/jaegertracing/jaeger | Jaeger integration | 5 files; trace export |
github.com/getsentry/sentry-go | Error reporting to Sentry | 4 files; crash/panic reporting |
github.com/DataDog/datadog-api-client-go/v2 | DataDog metrics | 37 files; cloud monitoring |
github.com/grafana/alloy/syntax | Grafana Alloy config syntax | 50 files; observability pipeline |
github.com/grafana/grafana-openapi-client-go | Grafana API | Dashboard management |
github.com/influxdata/influxdb-client-go/v2 | InfluxDB metrics | Time-series sink |
Key insight: The observability stack is unusually broad — CRDB supports Prometheus, OpenTelemetry, Jaeger, Sentry, DataDog, Grafana Alloy, and InfluxDB simultaneously. This reflects their enterprise customer base: different organizations use different monitoring stacks, and CockroachDB must integrate with all of them. The Prometheus fork (cockroachdb/client_golang) was created specifically to improve histogram update performance at CRDB’s scale.
Authentication / Security / Enterprise#
| Dependency | Role | Notes |
|---|---|---|
golang.org/x/crypto | TLS, bcrypt, SSH | Core cryptography |
github.com/coreos/go-oidc/v3 | OIDC / SSO | Enterprise auth (SAML/OIDC) |
github.com/go-ldap/ldap/v3 | LDAP authentication | Enterprise LDAP integration |
github.com/scim2/filter-parser/v2 | SCIM 2.0 user provisioning | Enterprise SSO user sync |
github.com/otan/gopgkrb5 | Kerberos / GSSAPI auth | Kerberos for PostgreSQL protocol |
github.com/lestrrat-go/jwx/v2 | JWT/JWK handling | OAuth2 token validation |
golang.org/x/oauth2 | OAuth2 client | Cloud provider auth |
github.com/99designs/keyring | OS keychain access | CLI credential storage |
cloud.google.com/go/kms, github.com/aws/aws-sdk-go-v2/service/kms | Cloud KMS | Encryption-at-rest keys |
CLI / Terminal UI#
| Dependency | Role | Notes |
|---|---|---|
github.com/spf13/cobra v1.6.1 | CLI framework | 142 files; all CLI commands |
github.com/spf13/pflag v1.0.5 | POSIX flags | Cobra companion |
github.com/spf13/viper v1.8.1 | Config management | 4 files (very light use) |
github.com/charmbracelet/bubbles → CRDB fork | TUI widget library | SQL shell |
github.com/knz/bubbline | Multi-line readline | SQL REPL input |
github.com/olekukonko/tablewriter → CRDB fork | Table rendering | CLI output |
github.com/fatih/color | ANSI color | Terminal output |
github.com/mattn/go-isatty | TTY detection | Terminal detection |
github.com/cockroachdb/ttycolor | CRDB tty coloring | Custom terminal coloring |
Geospatial#
| Dependency | Role | Notes |
|---|---|---|
github.com/golang/geo v0.0.0-... | S2 geometry library | Geographic indexing |
github.com/twpayne/go-geom v1.4.2 | Geometry types | WKT/WKB parsing (PostGIS compat) |
github.com/pierrre/geohash | Geohash encoding | Geospatial indexing |
github.com/twpayne/go-kml | KML format | Geospatial data export |
Testing#
| Dependency | Role | Notes |
|---|---|---|
github.com/stretchr/testify v1.11.1 | Test assertions | 2,175 files — dominant framework |
github.com/cockroachdb/datadriven | Data-driven tests | 274 files; custom DSL for SQL tests |
github.com/golang/mock v1.6.0 | Mock generation | Code-gen based mocking |
github.com/DATA-DOG/go-sqlmock | SQL mock driver | Database-level mocking |
github.com/leanovate/gopter | Property-based testing | Generative testing |
github.com/google/go-cmp | Deep equality | 7 files; struct comparison |
github.com/kylelemons/godebug | Diff output | Test failure diffs |
github.com/sasha-s/go-deadlock | Deadlock detection | Debug builds |
github.com/jordanlewis/gcassert | GC escape analysis assertions | Ensures critical code stays on stack |
Key insight: datadriven is CockroachDB’s most important testing innovation — a text-file-based testing DSL where test inputs and expected outputs are stored in human-readable files. This makes SQL query tests readable, reviewable, and rerunnable without recompilation. With 274 import sites, it’s the backbone of the SQL testing infrastructure.
Development Tools (go.mod tool directive)#
github.com/bufbuild/buf/cmd/buf # Protocol Buffer management
github.com/cockroachdb/crlfmt # CockroachDB-style Go formatter
github.com/cockroachdb/gostdlib/... # Pinned gofmt/goimports versions
github.com/cockroachdb/stress # Stress test runner
github.com/golang/mock/mockgen # Mock generation
github.com/grpc-ecosystem/grpc-gateway/.. # gRPC-gateway code gen
github.com/kevinburke/go-bindata/... # Binary asset embedding
github.com/kisielk/errcheck # Error return linting
github.com/mmatczuk/go_generics/... # Go generics emulation (pre-1.18)
github.com/pseudomuto/protoc-gen-doc/... # Proto documentation gen
github.com/swaggo/swag/cmd/swag # OpenAPI/Swagger doc gen
golang.org/x/perf/cmd/benchstat # Benchmark comparison
golang.org/x/tools/cmd/goyacc # yacc-based parser generator
honnef.co/go/tools/cmd/staticcheck # Static analysis
github.com/buchgr/bazel-remote # Remote Bazel cacheCockroachDB uses the Go 1.24+ tool directive (22 tool deps) to pin all development tool versions in go.mod, ensuring all contributors use identical versions of formatters, linters, and code generators — a practice not yet common in the Go ecosystem.
Other Notable Dependencies#
| Dependency | Role | Notes |
|---|---|---|
github.com/google/pprof | CPU/memory profiling | Profile visualization |
github.com/felixge/fgprof | Wall-clock profiling | Full-goroutine profiling |
github.com/maruel/panicparse/v2 | Panic stacktrace parsing | Better goroutine dumps |
gonum.org/v1/gonum | Numerical computing | Statistics, optimization |
github.com/axiomhq/hyperloglog | Cardinality estimation | SQL query planning stats |
github.com/VividCortex/ewma | Exponential moving avg | Metrics smoothing |
github.com/codahale/hdrhistogram | HDR histogram | Latency percentiles |
github.com/google/skylark | Skylark scripting | Bazel-related |
github.com/dave/dst | Go AST manipulation | Code generation |
github.com/RaduBerinde/btreemap | Ordered map | Internal data structures |
github.com/puzpuzpuz/xsync/v3 | Lock-free concurrent map | Hot-path concurrency |
github.com/grafana/grafana-openapi-client-go | Grafana API client | Monitoring setup |
honnef.co/go/tools | staticcheck linter | Code quality enforcement |
Stdlib reliance#
The standard library is deeply and heavily used across the codebase. Top stdlib packages by import count across pkg/:
| Package | Import count | Role |
|---|---|---|
context | 4,446 | Request scoping, cancellation — pervasive |
fmt | 3,102 | Formatting and error construction |
testing | 3,084 | Test infrastructure |
time | 2,221 | Timing, HLC, leases, timeouts |
strings | 1,951 | SQL string processing |
os | 990 | File I/O, process management |
bytes | 849 | Buffer operations, key encoding |
math | 676 | Numerical operations |
strconv | 659 | String/number conversion |
sort | 619 | General sorting |
io | 591 | Reader/Writer interfaces |
math/rand | 587 | Testing, jitter, sampling |
sync | 462 | Mutex, RWMutex, WaitGroup |
sync/atomic | 452 | Lock-free atomics |
path/filepath | 441 | Path manipulation |
reflect | 415 | Code generation, testing |
regexp | 395 | SQL regex support |
slices | 266 | Go 1.21+ slice utilities |
encoding/json | 251 | JSON marshaling |
net/http | 228 | Admin HTTP API, metrics |
unsafe | 154 | Performance-critical memory ops |
The ratio of stdlib to third-party usage is high: context, fmt, testing, and time alone account for more imports than any external package. CockroachDB’s philosophy is to use stdlib heavily and reach for external dependencies only when the need is clear and well-justified. Notably, golang.org/x/* packages are explicitly documented in go.mod as being treated as extended stdlib by the team.
Shared dependencies#
Dependencies shared with other projects in this 50-project analysis set (creating cross-project connections for the book):
| Dependency | Also used by |
|---|---|
github.com/spf13/cobra | etcd, kubernetes, terraform, rclone, k6, many others |
github.com/stretchr/testify | Nearly universal across Go projects |
google.golang.org/grpc | etcd, Prometheus, TiDB, and most distributed systems |
github.com/prometheus/client_golang | etcd, Prometheus itself, Grafana, k6 |
github.com/twmb/franz-go | Used by several streaming-adjacent projects |
github.com/klauspost/compress | Wide Go ecosystem adoption |
github.com/fatih/color | CLI tools across the ecosystem |
golang.org/x/crypto | Nearly universal |
honnef.co/go/tools (staticcheck) | Quality-focused Go projects |
github.com/google/go-cmp | Many Go testing suites |
gonum.org/v1/gonum | Scientific Go projects |
Vendoring#
No vendor directory. CockroachDB does not vendor its Go dependencies. With 216 direct dependencies and the total module graph, vendoring would be impractical (hundreds of MB of source). The project uses the standard Go module proxy (proxy.golang.org) and pins specific versions in go.mod. The Bazel build system uses its own dependency resolution separate from the module system, with gazelle and rules_go generating BUILD.bazel files from go.mod.
Notable dependency decisions#
1. The CockroachDB satellite ecosystem#
Rather than growing a monolithic codebase, CRDB has extracted key infrastructure into separately versioned modules under github.com/cockroachdb/: errors, pebble, redact, logtags, apd, tokenbucket, datadriven, crlib, cmux, swiss. These are real open-source packages usable by others, not just internal packages — a form of architectural discipline that forces clear API boundaries. This is unusual at this scale.
2. Forking upstream dependencies (replace directives)#
CockroachDB maintains 10 replace directives pointing to CRDB-maintained forks:
gogo/protobuf→cockroachdb/gogoproto: Extended protobuf with CRDB-specific code generationprometheus/client_golang→cockroachdb/client_golang: Histogram perf improvementscharmbracelet/bubbletea→cockroachdb/bubbletea: Bracketed paste mode (PR pending upstream)olekukonko/tablewriter→cockroachdb/tablewriter: Custom cell renderingstorj.io/drpc→cockroachdb/drpc: Custom DRPC extensionsgopkg.in/yaml.v2→cockroachdb/yaml: YAML parsing fixessnowflakedb/gosnowflake→cockroachdb/gosnowflake: Private API accessknz/strtime→cockroachdb/strtime: Time parsing fixes
This fork-and-maintain pattern is a significant operational burden but gives the team precise control over critical infrastructure. It also means upstream users may benefit when CRDB eventually upstreams their changes.
3. gogo/protobuf over google.golang.org/protobuf#
The 182-to-19 ratio of gogo/protobuf to google.golang.org/protobuf imports reflects CRDB’s deep historical investment in the older gogo/protobuf ecosystem. The gogo/protobuf library offers more code generation customization (custom marshal/unmarshal, nullable fields, etc.) that CRDB exploited heavily for KV encoding performance. Migration to the modern google.golang.org/protobuf API is clearly in progress but expected to take years given the codebase scale.
4. Two Kafka clients#
Both IBM/sarama (legacy) and twmb/franz-go (modern) are imported simultaneously for the Kafka changefeed sink. The franz-go library (twmb/franz-go) is a pure Go, high-performance Kafka client that the Go community broadly considers superior to Sarama. CRDB’s dual-client state indicates an active migration — new Kafka features are being built on franz-go while old ones remain on Sarama.
5. DRPC as gRPC alternative#
The 2025 addition of storj.io/drpc (via CRDB’s fork cockroachdb/drpc) is architecturally notable. DRPC is a lightweight binary RPC protocol: no HTTP/2, no header compression overhead, simpler connection management. CRDB uses it for CLI-to-cluster connections (pkg/rpc/drpc.go) and select internal fast paths where gRPC’s overhead is measurable. This reflects CRDB’s willingness to invest in custom infrastructure when performance demands it.
6. golang.org/x/* as extended stdlib#
The go.mod includes a rare explicit comment treating all golang.org/x/* packages as extended standard library, subject to the same upgrade review process as Go itself. This means golang.org/x/crypto, golang.org/x/net, golang.org/x/sync, etc. are treated with extreme conservatism — changes require broad reviewer involvement. This is a notable team process decision codified in the module file itself.
7. Go tool directive for reproducible dev tooling#
The tool (...) section pins 22 development tools (linters, code generators, formatters) to exact versions in go.mod, using the Go 1.24+ tool directive. This ensures every developer, CI machine, and Bazel build uses identical tool versions — eliminating “works on my machine” linter discrepancies. This is forward-looking practice not yet adopted by most Go projects.
8. gcassert for performance regression prevention#
github.com/jordanlewis/gcassert is used to add compile-time assertions that specific values do NOT escape to the heap. This is rare in the Go ecosystem — CRDB’s hot paths are so performance-sensitive that they assert memory allocation behavior in test code, catching accidental heap allocations before they reach production.