What is MongoDB Replica Set?
A single MongoDB container is fine until it restarts mid-write. A replica set is the unit of production MongoDB: automatic failover, rollback safety, and the topology that change streams and transactions actually require. This template runs a 3-member replica set (rs0) on the stock mongo image - the --replSet flags ride each service’s command, no custom build.
A tiny rs-init sidecar waits for the members, runs rs.initiate() exactly once (idempotent - re-runs detect the initialized set and skip), then idles at a hard 128 MiB cap. Each member keeps its data on its own 10 GB volume.
Everything is internal-only by design: this template ships without auth, so the project network is the security boundary - exactly like a VPC-peered Atlas cluster, minus the bill. Apps connect with the standard multi-host connection string and get driver-level failover for free.
What you get
- MongoDB 8, 3-member replica set rs0 - transactions and change streams work
- Stock mongo image with command passthrough; no custom image to maintain
- Idempotent self-initialization (rs-init sidecar, 128 MiB)
- Automatic primary election and driver failover on node loss
- Per-member 10 GB persistent volumes
- Internal-only: never exposed to the internet
How it runs on Lyngbak
| Service | Role | Public |
|---|---|---|
mongo-1..3 | replica-set members (:27017) | no |
rs-init | one-time rs.initiate(), then idles | no |
Sizing and billing
1 GiB per member suits small-to-medium working sets; WiredTiger sizes its cache to the container limit. Grow volumes with your data - 10 GB each is the starting point.
A resource is a flat monthly price, with RAM and disk add-ons when the stack needs a little more than a tier, and room for your own apps on a larger one. On Usage Billing each service takes the smallest size that fits it and is billed by the second it runs, so a stopped stack stops costing CPU and RAM. Its 29.3 GiB of volumes cost $0.15 per GiB a month ($4.40/mo) for as long as they exist. One workspace can use both. See pricing
Compared with the managed service
| Service | Plan | Price | Includes |
|---|---|---|---|
| MongoDB Atlas | M10 dedicated | $57/mo | 3-node replica set, 2 GB RAM per node, 10-128 GB storage |
| MongoDB Atlas | Flex | Usage-based | usage-tiered, capped $8-30/mo - shared infrastructure, the pre-dedicated entry point |
Prices from each vendor's pricing page, June 2026.
Run it locally first
The same compose file runs with plain Docker Compose. Clone the template source, copy .env.example to .env, and run docker compose up -d.
Questions
How much cheaper is this than MongoDB Atlas?
Atlas prices dedicated clusters by tier; M10, its smallest, is one 2 GB node-equivalent cluster. This 3-member replica set fits a 4 GiB plan, with capacity left for the apps that use it.
Why a replica set instead of a single mongod?
Failover, durability, and features: multi-document transactions and change streams require a replica set. With three members, the set survives any single node failure with automatic primary election - your driver reconnects on its own.
How do applications connect?
From the same Lyngbak project: mongodb://mongo-1:27017,mongo-2:27017,mongo-3:27017/?replicaSet=rs0. Listing all members lets the driver discover the topology and fail over automatically.
Is it safe to run MongoDB without authentication?
Only because nothing outside the project network can reach it: all members are private with no ingress route, the same trust model as a database inside a VPC. Never expose these services publicly; if you need cross-project access, add keyfile auth first.
Can I use this for transactions and change streams?
Yes - both require a replica set, which is exactly what this is. Point your ODM (Mongoose, Prisma, Spring Data) at the rs0 connection string and they work out of the box.