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#

DependencyRoleUsage
github.com/cockroachdb/errorsError handling (custom fork)3,365 files — most-used dep
github.com/cockroachdb/pebbleLSM storage engine165 files in pkg/storage
github.com/cockroachdb/redactSafe log/error redaction610 files
github.com/cockroachdb/logtagsStructured log tags on ctx130 files
github.com/cockroachdb/apd/v3Arbitrary-precision decimal146 files (SQL DECIMAL type)
github.com/cockroachdb/cmuxConnection multiplexing7 files in pkg/server
github.com/cockroachdb/tokenbucketRate limiting / admissionUsed in admission control
github.com/cockroachdb/crlibLow-level CRDB utilities92 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#

DependencyRoleNotes
google.golang.org/grpc v1.57.2Primary inter-node RPC66 files; gRPC is the internal wire protocol
storj.io/drpc v0.0.34 → CRDB forkLightweight alternative RPCAdded 2025; used in CLI clients and internal fast path
github.com/gogo/protobuf v1.3.2 → CRDB forkProtobuf serialization182 files — dominant protobuf library
google.golang.org/protobuf v1.35.1Modern protobuf (google)19 files — limited to newer code
github.com/grpc-ecosystem/grpc-gateway v1.16.0gRPC→HTTP transcodingAdmin API HTTP gateway
github.com/cockroachdb/cmuxProtocol muxer on single portRoutes 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#

DependencyRoleNotes
github.com/cockroachdb/pebbleMVCC storage engineLSM tree, RocksDB-inspired, pure Go
github.com/jackc/pgx/v4 v4.18.3PostgreSQL client driver93 files; CRDB uses pgx to talk to itself
github.com/jackc/pgx/v5 v5.7.2Newer PostgreSQL driver37 files (migration in progress)
github.com/jackc/pgconn, pgtype, pgproto3pgwire protocol componentsWire protocol implementation
github.com/lib/pq v1.10.9Legacy PostgreSQL driver78 files; older code paths
github.com/apache/arrow/go/v11Columnar in-memory format22 files; vectorized execution engine (pkg/col)
github.com/google/btree v1.1.3In-memory B-tree9 files; range cache, interval tree
github.com/cockroachdb/swissSwiss-table hash mapHigh-perf map for hot paths
github.com/golang/snappy v0.0.5Snappy compressionNetwork-level compression
github.com/klauspost/compress v1.17.11Multi-algo compressionBackup/restore compression
github.com/klauspost/pgzipParallel gzipBulk data operations
github.com/pierrec/lz4/v4LZ4 compressionChangefeed sinks
github.com/cockroachdb/datadrivenData-driven test framework274 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#

DependencyRoleNotes
cloud.google.com/go/storageGCS backup sinkBackup/restore, changefeed
cloud.google.com/go/kmsGoogle KMSEncryption-at-rest (CCL)
cloud.google.com/go/pubsubGoogle Pub/SubChangefeed sink
github.com/aws/aws-sdk-go v1.40.37S3, AWS services (v1)Backup/restore to S3
github.com/aws/aws-sdk-go-v2AWS SDK v2 (modern)Migration in progress; S3, KMS, STS
github.com/Azure/azure-sdk-for-goAzure Blob, KMS, etc.Azure backup, key management
github.com/Azure/azure-sdk-for-go/sdk/...Azure SDK v2Modern 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)#

DependencyRoleNotes
github.com/IBM/sarama v1.43.1Kafka client (Sarama)Legacy Kafka sink in changefeedccl
github.com/twmb/franz-go v1.18.0Kafka client (franz-go)New Kafka client implementation
github.com/apache/pulsar-client-goApache Pulsar sinkChangefeed → Pulsar
github.com/cockroachdb/changefeedpbChangefeed protobuf typesSerialization for CDC
github.com/linkedin/goavro/v2Avro serializationKafka Avro format support
github.com/snowflakedb/gosnowflake → CRDB forkSnowflake sinkCDC 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#

DependencyRoleNotes
github.com/prometheus/client_golang → CRDB forkMetrics exposition40 files; CRDB forked to improve histogram perf
github.com/prometheus/prometheusPrometheus rules evaluation1.8.2-era; used for alerting rule support
go.opentelemetry.io/otelOpenTelemetry tracing48 files; traces, spans
github.com/jaegertracing/jaegerJaeger integration5 files; trace export
github.com/getsentry/sentry-goError reporting to Sentry4 files; crash/panic reporting
github.com/DataDog/datadog-api-client-go/v2DataDog metrics37 files; cloud monitoring
github.com/grafana/alloy/syntaxGrafana Alloy config syntax50 files; observability pipeline
github.com/grafana/grafana-openapi-client-goGrafana APIDashboard management
github.com/influxdata/influxdb-client-go/v2InfluxDB metricsTime-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#

DependencyRoleNotes
golang.org/x/cryptoTLS, bcrypt, SSHCore cryptography
github.com/coreos/go-oidc/v3OIDC / SSOEnterprise auth (SAML/OIDC)
github.com/go-ldap/ldap/v3LDAP authenticationEnterprise LDAP integration
github.com/scim2/filter-parser/v2SCIM 2.0 user provisioningEnterprise SSO user sync
github.com/otan/gopgkrb5Kerberos / GSSAPI authKerberos for PostgreSQL protocol
github.com/lestrrat-go/jwx/v2JWT/JWK handlingOAuth2 token validation
golang.org/x/oauth2OAuth2 clientCloud provider auth
github.com/99designs/keyringOS keychain accessCLI credential storage
cloud.google.com/go/kms, github.com/aws/aws-sdk-go-v2/service/kmsCloud KMSEncryption-at-rest keys

CLI / Terminal UI#

DependencyRoleNotes
github.com/spf13/cobra v1.6.1CLI framework142 files; all CLI commands
github.com/spf13/pflag v1.0.5POSIX flagsCobra companion
github.com/spf13/viper v1.8.1Config management4 files (very light use)
github.com/charmbracelet/bubbles → CRDB forkTUI widget librarySQL shell
github.com/knz/bubblineMulti-line readlineSQL REPL input
github.com/olekukonko/tablewriter → CRDB forkTable renderingCLI output
github.com/fatih/colorANSI colorTerminal output
github.com/mattn/go-isattyTTY detectionTerminal detection
github.com/cockroachdb/ttycolorCRDB tty coloringCustom terminal coloring

Geospatial#

DependencyRoleNotes
github.com/golang/geo v0.0.0-...S2 geometry libraryGeographic indexing
github.com/twpayne/go-geom v1.4.2Geometry typesWKT/WKB parsing (PostGIS compat)
github.com/pierrre/geohashGeohash encodingGeospatial indexing
github.com/twpayne/go-kmlKML formatGeospatial data export

Testing#

DependencyRoleNotes
github.com/stretchr/testify v1.11.1Test assertions2,175 files — dominant framework
github.com/cockroachdb/datadrivenData-driven tests274 files; custom DSL for SQL tests
github.com/golang/mock v1.6.0Mock generationCode-gen based mocking
github.com/DATA-DOG/go-sqlmockSQL mock driverDatabase-level mocking
github.com/leanovate/gopterProperty-based testingGenerative testing
github.com/google/go-cmpDeep equality7 files; struct comparison
github.com/kylelemons/godebugDiff outputTest failure diffs
github.com/sasha-s/go-deadlockDeadlock detectionDebug builds
github.com/jordanlewis/gcassertGC escape analysis assertionsEnsures 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 cache

CockroachDB 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#

DependencyRoleNotes
github.com/google/pprofCPU/memory profilingProfile visualization
github.com/felixge/fgprofWall-clock profilingFull-goroutine profiling
github.com/maruel/panicparse/v2Panic stacktrace parsingBetter goroutine dumps
gonum.org/v1/gonumNumerical computingStatistics, optimization
github.com/axiomhq/hyperloglogCardinality estimationSQL query planning stats
github.com/VividCortex/ewmaExponential moving avgMetrics smoothing
github.com/codahale/hdrhistogramHDR histogramLatency percentiles
github.com/google/skylarkSkylark scriptingBazel-related
github.com/dave/dstGo AST manipulationCode generation
github.com/RaduBerinde/btreemapOrdered mapInternal data structures
github.com/puzpuzpuz/xsync/v3Lock-free concurrent mapHot-path concurrency
github.com/grafana/grafana-openapi-client-goGrafana API clientMonitoring setup
honnef.co/go/toolsstaticcheck linterCode quality enforcement

Stdlib reliance#

The standard library is deeply and heavily used across the codebase. Top stdlib packages by import count across pkg/:

PackageImport countRole
context4,446Request scoping, cancellation — pervasive
fmt3,102Formatting and error construction
testing3,084Test infrastructure
time2,221Timing, HLC, leases, timeouts
strings1,951SQL string processing
os990File I/O, process management
bytes849Buffer operations, key encoding
math676Numerical operations
strconv659String/number conversion
sort619General sorting
io591Reader/Writer interfaces
math/rand587Testing, jitter, sampling
sync462Mutex, RWMutex, WaitGroup
sync/atomic452Lock-free atomics
path/filepath441Path manipulation
reflect415Code generation, testing
regexp395SQL regex support
slices266Go 1.21+ slice utilities
encoding/json251JSON marshaling
net/http228Admin HTTP API, metrics
unsafe154Performance-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):

DependencyAlso used by
github.com/spf13/cobraetcd, kubernetes, terraform, rclone, k6, many others
github.com/stretchr/testifyNearly universal across Go projects
google.golang.org/grpcetcd, Prometheus, TiDB, and most distributed systems
github.com/prometheus/client_golangetcd, Prometheus itself, Grafana, k6
github.com/twmb/franz-goUsed by several streaming-adjacent projects
github.com/klauspost/compressWide Go ecosystem adoption
github.com/fatih/colorCLI tools across the ecosystem
golang.org/x/cryptoNearly universal
honnef.co/go/tools (staticcheck)Quality-focused Go projects
github.com/google/go-cmpMany Go testing suites
gonum.org/v1/gonumScientific 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/protobufcockroachdb/gogoproto: Extended protobuf with CRDB-specific code generation
  • prometheus/client_golangcockroachdb/client_golang: Histogram perf improvements
  • charmbracelet/bubbleteacockroachdb/bubbletea: Bracketed paste mode (PR pending upstream)
  • olekukonko/tablewritercockroachdb/tablewriter: Custom cell rendering
  • storj.io/drpccockroachdb/drpc: Custom DRPC extensions
  • gopkg.in/yaml.v2cockroachdb/yaml: YAML parsing fixes
  • snowflakedb/gosnowflakecockroachdb/gosnowflake: Private API access
  • knz/strtimecockroachdb/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.