Menu

1 / 4

What happens to MongoDB writes when the primary dies

DEV Community: mongodb·Alex Georgiev·about 17 hours ago
#PkroM3NL
#devtomongodb#devto#dev#primary#write
Long article (1516 words) — no AI summary yet.
Reading 0:00
15s threshold

I expected killing a MongoDB primary to cause a short gap in writes while the replica set sorted itself out. What I didn't expect was that whether there was a gap at all would depend almost entirely on how the primary left, not on how long an election takes. A hard crash and a polite request to step down produced completely different outcomes for the exact same three-node set, and I only found that out because I tested both rather than stopping at the first result.

I ran this locally: three mongo:8.0 containers (v8.0.38) on a plain Docker bridge network, formed into a replica set with default settings, no cloud, no managed service. A Python 3.13 script using pymongo 4.20.2 wrote one document roughly every 100ms against the replica set, and I disrupted the primary in various ways while it ran.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.