Siddhant DevalAuthor
Senior Full-Stack Engineer·Jul 26, 2026·18 min read
Cloud-Native & Distributed SQL: CockroachDB and the Horizontal SQL Layer
Distributed SQL solves PostgreSQL's horizontal scaling ceiling — but it introduces cross-region write latency, serializable isolation overhead, and 2PC coordination costs that must be fully understood before committing. This article covers CockroachDB's Raft architecture, multi-region topology, GDPR data residency, and the failure modes that appear reliably at scale.
Technical Series
Modern Database Paradigms
Part 4 of 8
Cloud-Native & Distributed SQL: CockroachDB and the Horizontal SQL Layer
Selecting the right database is a foundational architectural decision; data gravity ultimately dictates the scalability and resilience of an application — choose the paradigm first, the product second. The broken pattern is reaching for distributed SQL because PostgreSQL "doesn't scale" — without first understanding what "scale" means for your workload. Most teams that hit Postgres's ceiling have a connection pooling problem (solved with PgBouncer), not a sharding problem. Distributed SQL is justified only when you simultaneously need horizontal scale, multi-region high availability, and PostgreSQL wire compatibility. This article shows you what you gain, what you pay, and the failure modes that appear reliably in production CockroachDB deployments.
1. Why PostgreSQL Cannot Shard Horizontally
sql
PostgreSQL's architecture is built on a single Write-Ahead Log (WAL) on a single primary. All writes must flow through the primary — read replicas can offload SELECT traffic but cannot accept writes. This is not a bug; it is a design choice that makes strong consistency and ACID semantics straightforward. The ceiling is a single machine's write throughput.
Manual sharding solves the write throughput problem but creates new ones: cross-shard joins require application-layer stitching, rebalancing shards when data grows unevenly is manual and risky, and a shard failure requires manual failover.
CockroachDB's approach: eliminate the manual sharding layer entirely.
2. CockroachDB Architecture — Raft Consensus Groups
The key insight: data is divided into ranges (default 128MB). Each range has its own Raft consensus group. There is no global single writer — different ranges can be written by different nodes simultaneously. When a node fails, Raft promotes a follower to leader for the affected ranges in seconds, automatically, with no manual intervention.
sql
3. Serializable Isolation — Correctness vs. Throughput
sql
Performance / Safety Warning
Under high write contention on a narrow key range (e.g., a global counter, a leaderboard top row), CockroachDB's serializable isolation causes a retry storm: many transactions fail with
40001 and must be retried, amplifying write load. Design hot-row access patterns with explicit lock ordering or move high-contention state to Redis (atomic INCR).4. Data Modeling
4.1 Partition Key Design — Avoiding Range Hotspots
sql
4.2 Multi-Region Table Classification
sql
Crucial Requirement
GDPR Compliance: CockroachDB's distributed replication physically copies data across all configured regions.
REGIONAL BY ROW is the only configuration that pins EU user data to EU-only regions. Verify your CRDB topology satisfies GDPR Article 44–46 (cross-border data transfers) before production deployment. CRDB Cloud provides explicit region compliance attestations — self-hosted deployments require manual verification.4.3 Index Design Under Raft
sql
5. Multi-Region Write Path

Expand
For a
REGIONAL BY TABLE table in us-east1, writes from a European client look like:REGIONAL BY ROW reduces this to intra-region writes for EU users — their rows live in the EU region replica, and the Raft leader for those rows is in the EU cluster.6. Cost Model at Scale
| Tier | Monthly Cost | When It Fits |
|---|---|---|
| CRDB Serverless (0–50M RU/mo) | Free | Development, low-traffic staging |
| CRDB Serverless (paid) | ~$0.20 per million Request Units | Unpredictable traffic, < 1M RU/day average |
| CRDB Dedicated (2 vCPU / 8GB × 3 nodes) | ~$450/mo | Production, predictable workload, > 500K RU/day |
| CRDB Dedicated + Multi-Region (3 regions × 3 nodes) | ~$2,700/mo | Global HA, multi-region REGIONAL BY ROW |
| Self-Hosted (3× c5.2xlarge on EC2) | ~$300/mo compute + egress | Ops expertise available, cost-optimized |
Architectural Note
Cross-region network egress costs are often the hidden expense in multi-region CRDB deployments. A cluster with 3 regions replicating a 100GB table generates continuous cross-region WAL traffic. Calculate egress costs before committing to a multi-region topology — they can exceed compute costs at large datasets.
7. Security
sql
All CRDB inter-node communication and client connections require TLS — there is no option to disable it in production clusters. Client certificate authentication (mTLS) is supported and recommended for service-to-service connections.
8. When NOT to Use Distributed SQL
| Scenario | Why CRDB Fails | Better Alternative |
|---|---|---|
| Single-region deployment | Raft consensus overhead is pure cost with no benefit | PostgreSQL + PgBouncer + streaming replicas |
| Read-heavy workload (> 95% reads) | Postgres read replicas serve this at 1/3 the cost | PostgreSQL + read replicas |
| Sub-1ms write latency requirement | Cross-node Raft coordination adds unavoidable ms-level latency | Redis (in-memory), DynamoDB (single-region) |
| Budget-constrained MVP | CRDB Dedicated is 5–10× more expensive than single-node Postgres | PostgreSQL on a managed cloud (RDS, Supabase) |
| No distributed systems expertise on team | Clock skew, serialization retries, and compaction require deep familiarity | PostgreSQL — failure modes are well-documented and simpler |
Summary
| Concept | Rule |
|---|---|
| When CRDB is justified | Distributed SQL is justified only when horizontal scale, multi-region HA, and PostgreSQL wire compatibility are simultaneously required. |
| Serializable isolation cost | Serializable isolation is CRDB's default — profile for lock contention before production deployment. |
| Multi-region write latency | REGIONAL BY ROW reduces cross-region write RTT for geographically partitioned datasets; GLOBAL tables pay 2× RTT on every write. |
| Wire compatibility | PostgreSQL wire compatibility is ~95% — run integration tests, not just schema diffs, before declaring a migration done. |
| Clock skew | NTP clock skew above 500ms causes cluster instability — this is a hard infrastructure prerequisite, not a recommendation. |
What's Next
In Part 5, we cover the specialized data stores — Redis, Elasticsearch, Cassandra, Neo4j, and a beginner-level introduction to vector databases — each solving an access pattern that general-purpose databases serve poorly.
Research & Synthesis Note
This article was developed with AI-assisted deep search, specification cross-referencing, and technical research synthesis.
#CockroachDB#Distributed SQL#Horizontal Scaling#Raft Consensus#Multi-Region#GDPR#CAP Theorem
Technical Series
Modern Database Paradigms
Part 4 of 8