How do MongoDB drivers manage connections, and what goes wrong in Kubernetes?
Short answer
Each MongoDB driver (MongoClient) keeps a connection pool per server and is meant to be created once and reused for the life of the app. Problems appear when apps create a new client per request (connection storms), when pools × pods exceed the server's connection capacity, or in serverless functions that never reuse clients.
Right vs wrong (Node.js)
// ✅ create once at startup and reuse
const client = new MongoClient(process.env.MONGO_URL, { maxPoolSize: 20 });
await client.connect();
app.locals.db = client.db("shop");
// ❌ new client for every request → thousands of connections
app.get("/orders", async (req, res) => { const c = new MongoClient(url); await c.connect(); ... });
Check connections
db.serverStatus().connections // { current: 4123, available: 47077, totalCreated: ... }
Sizing
maxPoolSize (default 100 in many drivers) × replicas × app instances should fit what the cluster handles (Atlas tiers have connection limits). Lower maxPoolSize for apps with many pods; set maxIdleTimeMS.
What to say in the interview
"Drivers maintain a pool per server and the client should be a long-lived singleton. In Kubernetes, pool size times pod count must fit cluster or Atlas tier limits, so we tune maxPoolSize, and serverless code caches the client across invocations."