Couchbase
Memory-first document database: the cache IS the database, persistence is asynchronous.
Couchbase inverts the usual write path: writes land in a managed memory layer first and acknowledge immediately, then queue asynchronously to append-only storage files. Documents are JSON, queries speak N1QL (SQL for JSON), and the cluster distributes documents by vBucket with masterless replication.
Memory-first architecture
The managed cache (memcached lineage) is the system of record on write: mutations acknowledge from RAM, then a background writer appends to Couchstore files. Sets are O(1) hot-path.
vBucket distribution
The keyspace splits into 1024 virtual buckets mapped to nodes; each vBucket has one active and N replicas. Rebalancing moves vBuckets, not documents.
N1QL: SQL for JSON
Ad-hoc SQL queries with JOINs, GROUP BY, and indexes over JSON documents — secondary indexes (GSI) maintained separately from the data path.
XDCR cross-datacenter replication
Active-active multi-cluster replication with filtering — the disaster-recovery and geo-distribution story built into the product.
Cache-first is a different contract
Classical engines persist then acknowledge; Couchbase acknowledges from memory and persists in the background. Durability is tunable per operation (replicate-to / persist-to), but the default contract assumes the memory layer plus replication is enough — a design inherited from the memcached lineage.
The consequence: reads of active working sets never touch disk, and write latency is memory-speed. The cost is the persistence queue — crash before persistence loses the queue, which is why the bucket config, replicas, and the disk writer matter.
UPSERT INTO orders (KEY, VALUE)
VALUES ('order-42', { 'customer': 'ann', 'total': 42 });
SELECT o.total
FROM orders o
WHERE o.customer = 'ann';
N1QL: joining the document and SQL worlds
N1QL treats arrays and nested objects as first-class: UNNEST flattens arrays, ANY/EVERY quantify them, and indexes cover nested paths. Secondary indexes (GSI) live on query nodes and are updated asynchronously from the data path.
Diagrams
[caption] Durability knobs are per-operation — the default is memory + replication.
Writes acknowledge from the managed memory layer, replicate to vBucket replicas, and queue to the asynchronous disk writer (Couchstore append-only files).
1024 vBuckets mapped onto cluster nodes — active plus replica copies, rebalanced on topology change.
[caption] Illustrative: 3 nodes × 1024 vBuckets (active + replicas). Rebalance moves vBuckets, not keys.
1024 vBuckets mapped onto cluster nodes — active plus replica copies, rebalanced on topology change.