CockroachDB: Distributed SQL and Multi-Region Design

Serializable transactions across a cluster, the retry loop you cannot skip, and what "multi-region" actually costs in milliseconds.

Taught by Noshad Alam 7 lessons 39 min Published 30 Nov 2026

CockroachDB speaks the PostgreSQL wire protocol, accepts most PostgreSQL SQL, and is a fundamentally different database underneath. It stores your tables as a single sorted key space cut into **ranges**, replicates each range three or more times using **Raft**, and gives every transaction **serializable** isolation - the strongest level in the standard - across all of them.

Overview

Those three facts set the shape of this course. Because data is ranged and replicated, where a row lives is now a design decision with a latency consequence. Because consensus is involved, a write costs a round trip to a quorum, and if that quorum spans continents it costs the speed of light. And because isolation is serializable rather than snapshot, the database will sometimes refuse a transaction that it cannot order safely and tell you to try again - which means **every application that writes to CockroachDB must implement a retry loop**, and an application that does not is not finished.

The PostgreSQL compatibility is genuinely useful and it is also a trap. `psql` connects, your ORM works, and the first surprise arrives in production rather than in development: a `40001` error code your code does not handle, a sequential primary key that has turned one range into the whole cluster's bottleneck, or a multi-region table whose writes take 180 ms because the leaseholder is in another continent. Module 1 draws the compatibility boundary explicitly so that you know which of your PostgreSQL instincts to keep.

Seven modules, about 85 hours. The capstone is a multi-region order service with retry-safe writes and a simulated regional outage.

Introduction

This course assumes the programme's shared foundations and solid SQL. **It is much easier if you have done the PostgreSQL course first**, because this course spends its time on what is different rather than re-teaching SQL, and the differences are most visible against a PostgreSQL baseline.

For a sandbox, `cockroach demo` starts a multi-node in-memory cluster in one command and is the fastest way to see ranges and replicas move. `cockroach start-single-node --insecure` gives you something more persistent. For the multi-region work in Modules 5 and 6 you need either `cockroach demo --nodes 9 --demo-locality` or a CockroachDB Cloud cluster; the free tier is enough for the design exercises and the serverless pricing model is itself worth seeing.

Two habits to form from the first lab. First, **keep the DB Console open** - it is at port 8080 and it shows ranges, replicas, leaseholders and hot spots graphically, which is far more instructive than any query. Second, when something is slow, assume it is a network round trip until you have ruled that out. In a single-node PostgreSQL the first guess is a missing index. Here it is just as often geography.

What you will be able to do

  • Explain ranges, replicas, leaseholders and Raft, and read them in the DB Console
  • State accurately where CockroachDB does and does not behave like PostgreSQL
  • Choose primary keys that distribute rather than concentrate writes
  • Design locality-aware schemas with regional and global tables
  • Write a correct transaction retry loop and explain why it is mandatory
  • Diagnose contention and the 40001 and 40003 error classes
  • Read a distributed EXPLAIN plan and identify work that crosses nodes
  • Find and fix a hot range
  • Explain admission control and what it protects
  • Survive a node failure, and state the survival goal a cluster is configured for
  • Perform backup and restore, and record a measured RPO and RTO
  • Implement roles, TLS and certificate-based authentication
  • Use follower reads deliberately, and state their staleness
  • Produce a deployment and cost checklist, including egress and the price of consistency

What each level covers

5 levels · 7 lessons

  1. Beginner - Foundations

    What a distributed SQL database actually is, where the PostgreSQL resemblance stops, and a schema whose keys do not fight the architecture.

    2 lessons 11 min of reading

    Start with Ranges, Replicas and the PostgreSQL Compatibility Boundary →
  2. Intermediate - Application Behaviour

    Serializable isolation, the retry loop every writer needs, and how work spreads across nodes.

    1 lesson 4 min of reading

    Start with Serializable Transactions, Retries and Distributed Execution →
  3. Advanced - Performance and Reliability

    Finding the hot range and reading a distributed plan; then surviving node loss and stating the survival goal.

    2 lessons 12 min of reading

    Start with Plans, Hot Ranges, Admission Control and Latency →
  4. Expert - Security and Production Architecture

    Certificates, roles, follower reads used on purpose, rolling upgrades, and a cost model where the network is a line item.

    1 lesson 8 min of reading

    Start with Roles, TLS, Follower Reads and Cloud Cost →
  5. Capstone

    One multi-region service, defended on retry-safe correctness, per-region measurement, a survived outage and a stated cost.

    1 lesson 4 min of reading

    Start with Capstone - Multi-Region Order Service →

Guides and articles

Longer reading about this subject, written alongside the course.

Course guide How to work through this course Why to do PostgreSQL first, the one habit that matters most, what the DB Console teaches, and what to skip. 3 min read

Before you start

  • CockroachDB v24 or later, or CockroachDB Cloud
  • One programming language with a PostgreSQL driver
  • Solid SQL, including transactions and window functions
  • The PostgreSQL course, strongly recommended
  • The programme's shared foundations

Common questions

What does the CockroachDB: Distributed SQL and Multi-Region Design course cover?
It is 5 levels and 7 lessons: Beginner - Foundations; Intermediate - Application Behaviour; Advanced - Performance and Reliability; Expert - Security and Production Architecture; Capstone. Each level ends with a quiz, and the last one is an exam over the whole course.
How long does it take?
About 39 minutes of reading and exercises - roughly 0.7 hours. It is self-paced with no cohort and no start date, so you can leave and come back and the site remembers where you were.
What do I need to know first?
CockroachDB v24 or later, or CockroachDB Cloud. One programming language with a PostgreSQL driver. Solid SQL, including transactions and window functions. The PostgreSQL course, strongly recommended. The programme's shared foundations.
Is it free?
Yes. Every lesson, example and quiz in this course is free to read, and you do not need an account to read them. Signing in only adds progress tracking and quiz results.
What will I be able to do afterwards?
Explain ranges, replicas, leaseholders and Raft, and read them in the DB Console. State accurately where CockroachDB does and does not behave like PostgreSQL. Choose primary keys that distribute rather than concentrate writes. Design locality-aware schemas with regional and global tables. Write a correct transaction retry loop and explain why it is mandatory. Diagnose contention and the 40001 and 40003 error classes. Read a distributed EXPLAIN plan and identify work that crosses nodes. Find and fix a hot range. Explain admission control and what it protects. Survive a node failure, and state the survival goal a cluster is configured for. Perform backup and restore, and record a measured RPO and RTO. Implement roles, TLS and certificate-based authentication. Use follower reads deliberately, and state their staleness. Produce a deployment and cost checklist, including egress and the price of consistency.