Course contentsShow
← Databases & SQL
Lesson 1707 of 1,95316. Distributed Data ArchitecturesFree lesson

Hotspot Mitigation Techniques

Identify and refactor partition keys that cause uneven data distribution due to popularity skew.

In this lesson, you will learn how to identify and resolve performance bottlenecks caused by uneven data distribution, known as "hotspots," resulting from popularity skew.

The Problem: Popularity Skew

In distributed systems using Hash-Based Sharding, we distribute keys uniformly across nodes to ensure balanced load. However, real-world data is rarely uniform. If you use a user_id as a partition key, you might encounter a "celebrity" user whose account generates 1,000x more traffic than the average user. All requests for that specific key are routed to a single shard, turning it into a hotspot. This shard becomes a performance bottleneck, causing high latency or even crashing the node while others sit idle.

Refactoring the Partition Key

To mitigate this, you must transform the skewed partition key into one that distributes load more evenly. A common technique is to introduce a Salt or Suffix to the key.

Instead of partitioning strictly by user_id, you can append a random integer to create a composite key:

-- Original key: user_123
-- Refactored key: user_123_shard_suffix
-- Example: user_123_0, user_123_1, ..., user_123_n

By appending a random suffix (e.g., a number from 0 to 19), you force the data for a single "hot" user to be distributed across 20 different shards instead of one.

Implementation Considerations

When you refactor a key, you must remember that your retrieval logic now requires a "Scatter-Gather" pattern. Because the data for user_123 is now split across multiple shards, a read query for that user must query all 20 potential shards and merge the results in the application layer. While this adds complexity to your query logic, it prevents the system from hitting the resource limits of a single node and preserves the throughput of the cluster.

If certain data is inherently static and highly popular (like a configuration file or a trending celebrity profile), consider offloading these keys to a dedicated read-cache or using Shard Affinity to pin them to high-capacity nodes, ensuring they do not degrade the performance of the rest of the sharded cluster.

Key Takeaway: When a partition key causes a hotspot due to popularity skew, mitigate the load by salting the key to distribute traffic across multiple shards, then use a scatter-gather approach to reassemble the data during reads.