Why we run MongoDB as a replica set everywhere
Even on a laptop. Transactions need a replica set, and we refuse to have a code path that only exists in production.
Wanjiru Mwangi
Engineering Manager
1 min read
On this page
Publishing an article writes three things: the article, a revision and an audit event. They commit together or not at all — and multi-document transactions require a replica set.
A single-node replica set
services:
mongo:
image: mongo:8
command: ["--replSet", "rs0", "--bind_ip_all"]
ports: ["27017:27017"]One container, one command to initiate it, and local development behaves exactly like production. CI does the same; a missing database fails the build rather than skipping tests.
Optimistic concurrency
Every update matches on { _id, version } and increments the version. Zero matched documents means someone else won — we surface that, we never overwrite.