## 10.2.4 Sharding Mechanics 

The following documents describe sharded cluster processes. 

Sharded Collection Balancing (page 684) Balancing distributes a sharded collection’s data cluster to all of the shards. 

Chunk Migration Across Shards (page 685) MongoDB migrates chunks to shards as part of the balancing process. 

Chunk Splits in a Sharded Cluster (page 687) When a chunk grows beyond the configured size, MongoDB splits the chunk in half. 

Shard Key Indexes (page 688) Sharded collections must keep an index that starts with the shard key. 

Sharded Cluster Metadata (page 689) The cluster maintains internal metadata that reflects the location of data within the cluster. 

## Sharded Collection Balancing 

Balancing is the process MongoDB uses to distribute data of a sharded collection evenly across a sharded cluster . When a shard has too many of a sharded collection’s chunks compared to other shards, MongoDB automatically balances the chunks across the shards. The balancing procedure for sharded clusters is entirely transparent to the user and application layer. 

## Cluster Balancer 

The balancer process is responsible for redistributing the chunks of a sharded collection evenly among the shards for every sharded collection. By default, the balancer process is always enabled. 

Any mongos instance in the cluster can start a balancing round. When a balancer process is active, the responsible mongos acquires a “lock” by modifying a document in the lock collection in the Config Database (page 737). 

Note: Changed in version 2.0: Before MongoDB version 2.0, large differences in timekeeping (i.e. clock skew) between mongos instances could lead to failed distributed locks. This carries the possibility of data loss, particularly with skews larger than 5 minutes. Always use the network time protocol (NTP) by running ntpd on your servers to minimize clock skew. 

To address uneven chunk distribution for a sharded collection, the balancer migrates chunks (page 685) from shards with more chunks to shards with a fewer number of chunks. The balancer migrates the chunks, one at a time, until there is an even distribution of chunks for the collection across the shards. For details about chunk migration, see Chunk Migration Procedure (page 686). 

Changed in version 2.6: Chunk migrations can have an impact on disk space. Starting in MongoDB 2.6, the source shard automatically archives the migrated documents by default. For details, see moveChunk directory (page 687). 

Chunk migrations carry some overhead in terms of bandwidth and workload, both of which can impact database performance. The balancer attempts to minimize the impact by: 

• Moving only one chunk at a time. See also Chunk Migration Queuing (page 686). 

• Starting a balancing round only when the difference in the number of chunks between the shard with the greatest number of chunks for a sharded collection and the shard with the lowest number of chunks for that collection reaches the migration threshold (page 685). 

You may disable the balancer temporarily for maintenance. See Disable the Balancer (page 717) for details. 

You can also limit the window during which the balancer runs to prevent it from impacting production traffic. See Schedule the Balancing Window (page 716) for details. 

