Apache CouchDB: Replication and Offline-First Design

An HTTP database built around MVCC and replication, where conflicts are data you must resolve rather than errors you can avoid.

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

CouchDB is the database whose entire design follows from one decision: **replication is the primary feature, and everything else accommodates it.** Documents carry revision tokens. Updates are optimistic. Two replicas that both change the same document produce a **conflict** that CouchDB stores rather than rejects, and your application resolves. The API is plain HTTP and JSON, which means `curl` is a complete client and any device that can make a request can be a replica.

Overview

That design makes CouchDB unusual and, for one class of problem, better than anything else available: **offline-first applications**. A field survey app on a tablet with no signal, a point-of-sale terminal on flaky wifi, a clinic in a region with intermittent power - these all want a local database that accepts writes while disconnected and reconciles when it reconnects. CouchDB, with PouchDB in the browser or on a device, does exactly that, bidirectionally, with checkpoints so a resumed replication does not start over.

The honest other side: CouchDB is not a general-purpose replacement for a relational database or for MongoDB. Its query layer (Mango selectors and map/reduce views) is less capable; views are built by background indexing and can be stale; it is not the fastest option for anything; and **conflict resolution is work your application must do and cannot delegate**. Choosing CouchDB means choosing replication as the thing you optimise for, and accepting that bill.

Seven modules, about 65 hours. The capstone is an offline field survey app with bidirectional replication and deterministic conflict resolution.

Introduction

This course assumes the programme's shared foundations. It does not assume SQL, and it does assume you are comfortable with HTTP - status codes, headers, request methods - because that *is* the database interface.

For a sandbox, CouchDB 3.x in Docker is one command: `docker run -p 5984:5984 -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=... couchdb:3`. Note that CouchDB 3 **requires** an admin to be configured - the "Admin Party" mode where anyone could do anything is gone, which is a welcome change. **Fauxton**, the built-in web interface, is at `/_utils` and is genuinely useful for inspecting documents and building views.

For Modules 3, 5 and the capstone you also want **PouchDB**, which is a CouchDB-compatible database that runs in a browser or Node process and replicates with a real CouchDB. The replication protocol is the whole point of this course, and you cannot really learn it with one server talking to itself.

One habit from the start: **use `curl -i` so you see the status codes and headers.** CouchDB communicates through HTTP semantics - `409 Conflict` when your revision is stale, `ETag` carrying the current revision, `201 Created` against `202 Accepted` depending on quorum. A client library that hides those is hiding the database.

What you will be able to do

  • Use the CouchDB HTTP API directly for all document operations
  • Explain MVCC, revision trees and what a revision token actually guarantees
  • Write Mango selectors and create the indexes they need
  • Build map/reduce views in design documents, including reduce and grouping
  • Decide between Mango and views, and state why
  • Explain what a conflict is, how CouchDB stores one, and detect them
  • Implement a deterministic conflict resolution policy and defend it
  • Consume the changes feed, including long polling and continuous mode
  • Explain view indexing, staleness and the cost of a first query after a write
  • Configure compaction, and explain why it is not optional
  • Set up bidirectional and filtered replication with checkpoints
  • Build an offline-first client that works disconnected and reconciles on reconnect
  • Explain cluster quorum, `n` and `q`, and what 202 Accepted means
  • Implement security objects, roles, validation functions and TLS
  • Produce a deployment, monitoring and cost checklist

What each level covers

5 levels · 7 lessons

  1. Beginner - Foundations

    HTTP as the database interface, revisions, and the modelling that replication forces on you.

    2 lessons 13 min of reading

    Start with The HTTP API, Documents and Revisions →
  2. Intermediate - Application Behaviour

    MVCC in practice, conflicts as data, and the changes feed that makes the database reactive.

    1 lesson 7 min of reading

    Start with MVCC, Conflicts and the Changes Feed →
  3. Advanced - Performance and Reliability

    View indexing and compaction; then replication, offline sync and cluster quorum.

    2 lessons 10 min of reading

    Start with View Indexing, Compaction and Partitioned Databases →
  4. Expert - Security and Production Architecture

    Security objects, validation functions that run on every write, and a deployment plan with an upgrade path.

    1 lesson 8 min of reading

    Start with Security Objects, Validation Functions and Operations →
  5. Capstone

    One offline field app, defended on deterministic resolution, measured sync and a stated cost.

    1 lesson 6 min of reading

    Start with Capstone - Offline Field Survey Application →

Guides and articles

Longer reading about this subject, written alongside the course.

Course guide How to work through this course Why you need two databases from Module 3, the demonstration that changes how you think, what to skip, and when CouchDB is the right answer. 3 min read

Before you start

  • CouchDB 3.x, in Docker or installed
  • curl, and a JSON formatter such as jq
  • Node.js with PouchDB for the replication modules
  • Comfort with HTTP methods, status codes and headers
  • The programme's shared foundations

Common questions

What does the Apache CouchDB: Replication and Offline-First 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 44 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?
CouchDB 3.x, in Docker or installed. curl, and a JSON formatter such as jq. Node.js with PouchDB for the replication modules. Comfort with HTTP methods, status codes and headers. 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?
Use the CouchDB HTTP API directly for all document operations. Explain MVCC, revision trees and what a revision token actually guarantees. Write Mango selectors and create the indexes they need. Build map/reduce views in design documents, including reduce and grouping. Decide between Mango and views, and state why. Explain what a conflict is, how CouchDB stores one, and detect them. Implement a deterministic conflict resolution policy and defend it. Consume the changes feed, including long polling and continuous mode. Explain view indexing, staleness and the cost of a first query after a write. Configure compaction, and explain why it is not optional. Set up bidirectional and filtered replication with checkpoints. Build an offline-first client that works disconnected and reconciles on reconnect. Explain cluster quorum, `n` and `q`, and what 202 Accepted means. Implement security objects, roles, validation functions and TLS. Produce a deployment, monitoring and cost checklist.