liveBook · Manning

Hotspot

As explained in MongoDB 8.0 in Action, Third Edition

A hotspot is a concentration of sharded data or database activity on a subset of shards that creates uneven load and can reduce performance.

A hotspot is a concentration of data or database activity on a subset of shards. In MongoDB, an overloaded shard—often called a hot shard—can become a bottleneck and reduce overall cluster performance. Poor shard-key choices can cause uneven data distribution, load imbalance, and inefficient queries. section 9.3.3 section 9.6

Reduce hotspot risk by checking how the proposed shard key distributes data and activity:

  • Choose fields that distribute documents and query activity across shards instead of concentrating writes or frequently accessed ranges. section 9.3.3
  • Check monotonicity: a non-monotonic shard-key sequence creates less risk of directing new writes repeatedly to specific shards. section 9.3.5
  • Use analyzeShardKey with sampled query data before sharding, then inspect query distribution and key characteristics. section 9.3.5
  • Consider presplitting when ingesting large volumes or using monotonically changing keys in an unbalanced cluster. section 9.6
Listing 9.13 Analyzing a proposed shard key
Atlas [mongos] sample_training>
➥db.routes.analyzeShardKey({ src_airport: 1,
➥dst_airport: 1,"airline.name": 1 })
{
  keyCharacteristics: {
    numDocsTotal: Long('66985'),
    avgDocSizeBytes: Long('184'),
    numDocsSampled: Long('66985'),
    isUnique: false,
    numDistinctValues: Long('66984'),
    mostCommonValues: [
      {
        value: {
          src_airport: 'HAM',
          dst_airport: 'AMS',
          'airline.name': 'Eurowings'
        },
        frequency: Long('2')
      },
      {
        value: {
          src_airport: 'KTM',
          dst_airport: 'DXB',
         'airline.name': 'Fly Dubai'
        },
        frequency: Long('1')
      },
      {
        value: {
         src_airport: 'ADB',
         dst_airport: 'ARN',
         'airline.name': 'SunExpress'
        },
        frequency: Long('1')
      },
      {
        value: {
          src_airport: 'FOC',
          dst_airport: 'TNA',
          'airline.name': 'Air China'
        },
        frequency: Long('1')
      },
      {
        value: {
          src_airport: 'DTW',
          dst_airport: 'MEX',
          'airline.name': 'AeroMéxico'
        },
        frequency: Long('1')
      }
    ],
    monotonicity: {
      recordIdCorrelationCoefficient: 0.0163877874,
      type: 'not monotonic'
    }
  },
  readDistribution: {
    sampleSize: {
      total: Long('525'),
      find: Long('525'),
      aggregate: Long('0'),
      count: Long('0'),
      distinct: Long('0')
    },
    percentageOfSingleShardReads: 84.1904761905,
    percentageOfMultiShardReads: 12.1904761905,
    percentageOfScatterGatherReads: 3.6190476191,
  writeDistribution: {
    sampleSize: {
      total: Long('0'),
      update: Long('0'),
      delete: Long('0'),
      findAndModify: Long('0')
    }
  },
  ok: 1,
  '$clusterTime': {
    clusterTime: Timestamp({ t: 1712596218, i: 99 }),
    signature: {
      hash: Binary.createFromBase64('E31gLvizNd2gwwpFIx9AESXDg8A=', 0),
      keyId: Long('7352622473289924630')
    }
  },
  operationTime: Timestamp({ t: 1712596218, i: 99 })
}
Atlas [mongos] sample_training>

Review a proposed routes collection shard key and its sampled distribution metrics before enabling sharding. section 9.3.5

How MongoDB 8.0 in Action, Third Edition covers it

How deep it goes
Explains causes, monotonicity risk, analysis, and presplitting, but does not detail hotspot remediation commands.
Examples
Uses the routes collection, a compound shard key, analyzeShardKey metrics, monotonicity, and presplitting scenarios.
What it assumes
Assumes familiarity with MongoDB collections and shards while explaining shard keys, chunks, and distribution from context.
What you can do after
Diagnose hotspot risk by evaluating shard-key distribution, query isolation, monotonicity, and ingestion patterns.
How it connects
Connects shard keys with sharded clusters, chunks, data distribution, query performance, and load balancing.

Also explained in

Compare how 4 books explain hotspot →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of MongoDB 8.0 in Action, Third Edition. The section links point to the parts of the book it draws on.