MongoDB Config Server Setup for Sharded Clusters

When a sharded MongoDB cluster loses Config Server availability, writes are blocked and new connections through mongos stop working. We configure Config Server turnkey, ensuring stable cluster operation and ongoing support.

Our competencies:

Frequently Asked Questions

Latest works

  • Development of a web application for FEEDME
    Development of a web application for FEEDME
    1365
  • Development of an online store for the company FURNORO
    Development of an online store for the company FURNORO
    1330
  • B2B Advance company logo design
    B2B Advance company logo design
    776
  • Development of a web application for Enviok
    Development of a web application for Enviok
    1077
  • AIDER company logo development
    AIDER company logo development
    1022
  • CRM development for Chasseurs
    CRM development for Chasseurs
    1113

MongoDB Config Server Setup for Sharded Clusters

Imagine: your sharded MongoDB cluster handles 50,000 queries per second, but suddenly new mongos instances stop connecting, writes start failing — the config server has become unavailable. Without a properly configured CSRS, you risk losing balancing and write capability. We configure Config Server for MongoDB sharded clusters — the central metadata catalog. It stores information about which chunks of data reside on which shards, balancer settings, and sharding zones. Without an accessible config server, the cluster enters read-only mode: writes are blocked, new connections via mongos are not established. Our experience with over 80 clustering projects shows that correct CSRS setup is the foundation of cluster stability. A wrong shard key or a slow disk can cause latencies up to 200 ms per operation.

Per MongoDB documentation, CSRS is mandatory for sharded clusters: Config Servers.

What Is CSRS and How Is It Different from a Regular Replica Set?

CSRS runs on the same WiredTiger engine but with restrictions: you cannot store user data on the config server. It uses a dedicated port (default 27019, though this is a convention, not a requirement) and a separate data directory.

In mongod.conf, the following parameters are mandatory for a config server:

sharding:
  clusterRole: configsvr
replication:
  replSetName: "configRS"
storage:
  dbPath: /var/lib/mongodb/config
net:
  port: 27019
  bindIp: cfg1.internal,127.0.0.1
security:
  keyFile: /etc/mongodb/cluster-keyfile
systemLog:
  destination: file
  path: /var/log/mongodb/configsvr.log
  logAppend: true

The clusterRole: configsvr parameter blocks direct user data write operations and enables config-server-specific logic.

Parameter CSRS Regular Replica Set
Port 27019 (standard) 27017 (standard)
clusterRole configsvr absent
replSetName configRS (any) any
Stored data Only sharding metadata Any user data
Resources Minimal (few GB) Depends on load

How to Ensure CSRS High Availability?

Deploy three config servers in different availability zones or physical locations. If all three are in the same rack, you are not protected against a rack failure. A typical cloud setup: three separate availability zones in one region.

Disk requirements: use SSDs. Although data volume is small, metadata write latency directly affects chunk migration and query routing speed. CSRS on SSD processes chunk migration 5 times faster than on HDD — proven in practice.

Failure Scenario Impact MTTR
One CSRS offline No impact on writes 0 (automatic failover)
Two CSRS offline Cluster enters read-only mode 5–10 minutes
All CSRS offline Complete write halt, new mongos cannot connect 30+ minutes

Cluster downtime due to CSRS unavailability can cost $10,000 per hour for a large e-commerce platform. Without a CSRS backup, recovery can take 8+ hours, resulting in $80,000 loss at $10,000/hour. Setting up a fault-tolerant CSRS avoids such losses.

Step-by-Step CSRS Configuration

  1. Infrastructure audit — check network access, availability zones, disks.
  2. Design — choose hostnames, ports, data paths.
  3. Prepare configuration files — create mongod.conf with clusterRole: configsvr.
  4. Start mongod — on all three nodes.
  5. Initialize Replica Set — connect to the first node and run rs.initiate with configsvr: true.
  6. Verify status — ensure all nodes are PRIMARY/SECONDARY.
  7. Integrate with mongos — specify CSRS in mongos configuration via configDB parameter.
  8. Test failover — artificially stop the primary, verify writes continue.
  9. Configure monitoring and backups.

CSRS initialization:

rs.initiate({
  _id: "configRS",
  configsvr: true,
  members: [
    { _id: 0, host: "cfg1.internal:27019" },
    { _id: 1, host: "cfg2.internal:27019" },
    { _id: 2, host: "cfg3.internal:27019" }
  ]
})
Example full mongod.conf configuration
sharding:
  clusterRole: configsvr
replication:
  replSetName: "configRS"
storage:
  dbPath: /var/lib/mongodb/config
net:
  port: 27019
  bindIp: cfg1.internal,127.0.0.1
security:
  keyFile: /etc/mongodb/cluster-keyfile
systemLog:
  destination: file
  path: /var/log/mongodb/configsvr.log
  logAppend: true

Maintenance and Backup

A config server backup is a snapshot of the cluster metadata. Without it, if all three nodes are lost, recovering chunk distribution information is impossible — you would have to manually restore metadata or reset sharding.

For backup we use mongodump with config-server-specific options:

mongodump \
  --host configRS/cfg1.internal:27019,cfg2.internal:27019,cfg3.internal:27019 \
  --db config \
  --out /backup/configsvr/$(date +%Y%m%d)

The config database contains collections chunks, collections, databases, shards, settings — everything needed for restoration. For planned maintenance on one CSRS node, you must stop the cluster balancer: sh.stopBalancer().

Common Issue: Split Storm

During heavy insert of new documents, the config server receives a large number of write operations — these are chunk splits when chunks exceed the maximum size (default 128 MB). On a busy cluster with a poor shard key, this can generate hundreds of splits per minute.

Diagnosis: mongos logs show waiting for write concern with latency, and the CSRS Primary exhibits high write lock. Solution: increase chunk size via db.settings.updateOne or reconsider the shard key.

What's Included in Turnkey CSRS Setup

  • Audit of current infrastructure and CSRS architecture design.
  • Deployment of three CSRS nodes considering availability zones.
  • Configuration file setup, Replica Set initialization.
  • Integration with mongos and shards.
  • Failover and performance testing.
  • Backup and monitoring configuration (Prometheus + Grafana).
  • Documentation and team training.

Why Trust Our Engineers with the Setup?

We have worked with MongoDB since 2014 and completed over 80 clustering projects. Our engineers hold MongoDB Professional certifications and have experience with cloud platforms (AWS, GCP, Yandex Cloud). We guarantee a fault-tolerant architecture and comprehensive documentation.

We will assess your project within 1 day — contact us. Pricing is determined individually after an infrastructure audit. Timeline: 2–4 days for a new installation as part of a full cluster.