CockroachDB Administration for Distributed SQL Databases
We help teams deploy and maintain CockroachDB — a distributed SQL database compatible with PostgreSQL, built on Raft consensus. Unlike Cassandra (eventual consistency) or MongoDB sharding, CockroachDB guarantees ACID transactions across the entire cluster, even between nodes in different regions. The trade-off: serializable isolation requires round-trips between nodes for transaction coordination. For write-heavy workloads with global distribution, this is an important limitation that we factor in when designing the schema.
A common issue: developers migrate a monolithic PostgreSQL schema and encounter unexpected transaction conflicts due to Raft latency. Or they try to use auto-increment and get hot spots on a single range. We solve these problems during the audit stage, saving hours of production incidents.
Our specialists have 5+ years of experience with distributed databases and dozens of projects on CockroachDB. We offer a turnkey service: audit of your current schema, cluster deployment, monitoring and backup setup. Timelines range from 2 to 5 days for a basic cluster. We have completed 30+ CockroachDB implementations, including multi-region configurations with geo-partitioning.
Cluster Topology and Zones
Minimum production cluster: 3 nodes in one region. This doubles fault tolerance compared to a single instance — Raft requires a quorum of 2/3. For multi-region deployment, we use 3–5 nodes per region. CockroachDB automatically replicates ranges (approximately 64 MB each) according to zone configurations.
Starting a node:
cockroach start \
--certs-dir=/cockroach/certs \
--store=/cockroach/data \
--listen-addr=node1.internal:26257 \
--advertise-addr=node1.internal:26257 \
--http-addr=node1.internal:8080 \
--join=node1.internal:26257,node2.internal:26257,node3.internal:26257 \
--locality=region=us-east1,zone=us-east1-a \
--background--locality is a key parameter. CockroachDB uses these labels for replica placement. Initializing the cluster (only once):
cockroach init --certs-dir=/cockroach/certs --host=node1.internal:26257 How to Configure Geo-Partitioning for Low Latency?
Zone configs define where replicas for a specific database, table, or row are stored. Example of multi-region replication setup:
-- Replication across three regions with 5 replicas
ALTER DATABASE production CONFIGURE ZONE USING
num_replicas = 5,
constraints = '[+region=us-east1:2, +region=eu-west1:2, +region=ap-southeast1:1]',
lease_preferences = '[[+region=us-east1]]';lease_preferences determines which region holds the leaseholder — the node that handles reads without a round-trip. Set this to the region where most read requests originate.
For tables partitioned by region, you can pin data of a specific region to physical nodes — this is called geo-partitioning. Read the official CockroachDB documentation for details.
Monitoring and Diagnostics
Admin UI on port 8080 and Prometheus metrics at /_status/vars. Key SQL queries:
-- Slow queries
SELECT query, count, mean, p99
FROM crdb_internal.node_statement_statistics
ORDER BY mean DESC
LIMIT 20;
-- Hot spots — ranges with high QPS
SELECT range_id, reads_per_second, writes_per_second
FROM crdb_internal.kv_node_status;Hot spots are a typical problem: a sequential primary key (e.g., serial) creates a single range. Solution — use UUID or gen_random_uuid() as the primary key, or configure hash sharding.
How to Avoid Hot Spots?
The best way is to avoid sequential primary keys. Use UUID v4 or gen_random_uuid(), which does not create ordered keys. If a table already uses serial, you can migrate to UUID or apply a hash index. Monitor ranges via crdb_internal.kv_node_status to see which partitions are overloaded. Zone configs with constraints help distribute load evenly.
Backup and Restore
-- Full backup to S3
BACKUP INTO 's3://my-bucket/backups/full?AUTH=implicit' AS OF SYSTEM TIME '-10s';
-- Restore
RESTORE FROM 's3://my-bucket/backups/full?AUTH=implicit';CockroachDB supports AS OF SYSTEM TIME — time travel queries up to 25 hours back.
CockroachDB vs PostgreSQL for Global Applications
| Criteria | CockroachDB | PostgreSQL (with BDR/Patroni) |
|---|---|---|
| ACID cross-region | Yes, out of the box | Requires synchronous replication, high latency |
| Automatic sharding | Yes | No (manual needed) |
| Network partition tolerance | Yes (Raft) | Partial (with Patroni) |
| Geo-partitioning | Built-in zone configs | Via extensions |
Common Mistakes
- Using sequential primary keys — leads to hot spots.
- Incorrect zone configs — replicas end up in one region.
- Missing retry logic in the application — transactions fail with
40001. - Too small ranges (small tables) — increase overhead.
What's Included
- Audit of existing schema and transactions
- Deployment of single or multi-region cluster
- Setup of TLS, zone configs, monitoring (Prometheus + Grafana)
- Operational documentation and runbook
- Team training (1–2 sessions)
- First month of support
Estimated Timelines
| Configuration | Timeline |
|---|---|
| Single-region cluster, 3 nodes | 2–3 days |
| Multi-region with geo-partitioning | 4–5 days |
| Migration from PostgreSQL | 3–7 days (depends on schema and data volume) |
Cost is calculated individually after analyzing your architecture. We offer a project assessment — just reach out via chat or email. Order an audit of your CockroachDB schema to avoid mistakes from the start.
Why CockroachDB is Better Than PostgreSQL for Global Applications
CockroachDB provides ACID transactions across the entire cluster without manual sharding. While PostgreSQL requires extensions and complex configuration for multi-region consistency, CockroachDB handles it out of the box. With 3 nodes in different regions, p99 latency for writes is around 5–15 ms, which is 2–3 times lower than PostgreSQL with synchronous replication.
How We Work
- Audit — check SQL compatibility and workload.
- Design — choose topology, configure zone configs.
- Deployment — launch cluster with TLS and monitoring.
- Testing — chaos testing: kill nodes, verify recovery.
- Handover — documentation and training.
Get a consultation for your project — contact us.







