Home›Learn›MongoDB 6: when it breaks
MongoDB · Chapter 6

When MongoDB breaks

Something is wrong right now. Where do I start?

Confirm what is really happening, find the cause, then fix the smallest thing that works.

Chapter 6 · When it breaks

Start from what you see

Each playbook starts from a symptom, confirms it read-only, names the likely causes in the order I see them, and only then suggests a fix with its risk. The same playbooks drive the DBA agent.

PlaybookToo many connectionsNew connections fail with "too many connections" (MySQL) or "sorry, too many clients already" (PostgreSQL), or the app's pool times out waiting for one. Often right after a deploy, a failover or a traffic spike.PlaybookCPU at 100%The database CPU is pinned and everything is slower. Often no single query looks slow on its own.PlaybookThe disk is filling upFree space is falling faster than the data is growing, or an alert fired at 85%.PlaybookA replica is far behindReads from replicas return old data, or the lag alert fired. A failover now would lose more, or take longer.PlaybookQueries waiting on locks, or timing outRequests hang, then fail with lock wait timeouts or deadlock errors. CPU may be low: things are waiting, not working.PlaybookOne query suddenly got slowA query that took milliseconds yesterday takes seconds today. The code did not change.PlaybookEverything is slow and the disk is busyRead latency is up across many queries. Disk reads per second climbed, and CPU waits on I/O.PlaybookOut of memory, or the server restartedThe database process was killed by the operating system, or restarted on its own. Clients saw connection errors.PlaybookWrites and commits are slowReads are fine, but inserts and updates take longer. Commit latency rose while CPU is low.PlaybookTables grow but rows do notTable size keeps rising while the row count is flat. Scans get slower over weeks.PlaybookMongoDB replica set: no primary, or elections keep happeningWrites fail with "not primary" or NotWritablePrimary errors. rs.status() shows no PRIMARY, or the primary changes every few minutes.PlaybookMongoDB replica set: a member is stale, or majority writes hangA secondary is stuck in RECOVERING, or "too stale to catch up". Or writes with w: majority hang while w: 1 writes work.

When every write lands on one shard

Every new write lands on one shard. That node runs at 100 percent while the rest idle, and inserts slow for every customer. Check distribution, not totals. A monotonic shard key sends every new write to the same shard.

The fix is the key, not more shards. Hash-prefix a monotonic shard key, or give the whale tenant its own shard. Choose the shard key from the query pattern before launch.

How to host MongoDB on-prem, on EC2, in Kubernetes, or on Atlas is on the Cloud page.

Before you leave, check this

One command. It tells you how long a secondary can stay down and still catch up.

The oplog window: size divided by write rate

10 GB oplogfixed size, capped
÷
5 MB/min writesthe current rate
=
34-hour windowlongest survivable downtime
→
Rate grows 10xsame oplog, 3.4-hour window
rs.printReplicationInfo()

Read "log length start to end". That is the window in hours. Compare it to your longest maintenance.

← Chapter 5: Running it as a DBREYou finished the MongoDB trackBack to chapter 1Or pick another database in the Learn menu.
Part 1 of 4 · Learn · 56 pagesAll pages

How do databases actually work? From one row on disk to transactions: the words you need, PostgreSQL, MySQL and MongoDB from the files up, then Redis, Cassandra and vector search, side by side, and the query and concurrency traps.

Start 1: the basicsStart 2: ten conceptsStart 3: how a query travelsStart 4: napkin mathThe courseShort videosPostgreSQL 1: why PostgreSQLPostgreSQL 2: how it stores your dataPostgreSQL 3: what happens on every writePostgreSQL 4: high availability with PatroniPostgreSQL 5: running it as a DBREPostgreSQL 6: when it breaksPostgreSQL on Kubernetes: CloudNativePGMySQL 1: why MySQLMySQL 2: how it stores your dataMySQL 3: what happens on every writeMySQL 4: high availability with InnoDB ClusterMySQL 5: running it as a DBREMySQL 6: when it breaksMySQL failover with OrchestratorMySQL on Kubernetes: the Percona operatorsMongoDB 1: why MongoDBMongoDB 2: how it stores your dataMongoDB 3: what happens on every writeMongoDB 4: high availability with replica setsMongoDB 5: running it as a DBREMongoDB 6: when it breaksMongoDB on Kubernetes: the Percona operatorB-tree and LSM treeRedis 1: why RedisRedis 2: how it stores your dataRedis 3: high availabilityRedis 4: running it as a DBRERedis 5: when it breaksCassandra 1: why CassandraCassandra 2: how it stores your dataCassandra 3: high availabilityCassandra 4: running it as a DBRECassandra 5: when it breaksVector databases 1: why vector searchVector databases 2: how it stores your dataVector databases 3: high availabilityVector databases 4: running it as a DBREVector databases 5: when it breaksDatabase familiesEngines side by sideQueries that look fine and are notLost updates and write skewMany servers 1: keep a copy runningMany servers 2: who is the leaderMany servers 3: CAP as settingsMany servers 4: unique IDsMany servers 5: split the dataMany servers 6: across servicesMany servers 7: a thousand databasesStaff path, zero to architect