Databases 7 min read

Hybrid Hash‑Range Sharding Strategy with Group‑Based Allocation

This article presents a hybrid sharding approach that combines range partitioning to assign ID ranges to groups and hash modulo on the total number of tables to achieve uniform data distribution while avoiding hotspots and eliminating the need for data migration during scaling.

Architect's Tech Stack
Architect's Tech Stack
Architect's Tech Stack
Hybrid Hash‑Range Sharding Strategy with Group‑Based Allocation

Building on a previous discussion of traditional sharding methods, the article compares the hash‑modulo scheme, which prevents hotspots but requires data migration, with the range‑based scheme, which avoids migration but can create hotspots.

To obtain the advantages of both, a hybrid solution is proposed: first use a range strategy to allocate an ID range to a logical group, then within that group apply a hash‑modulo operation on the total number of tables to distribute data evenly.

The concept of a "group" is introduced; for example, Group01 covers IDs 0–40 million and contains three databases with a total of ten tables. Mapping rules are defined so that an ID’s modulo 10 determines the target table, and tables are assigned to databases (DB0 receives four tables, DB1 and DB2 each receive three), allowing distribution proportional to server capacity.

This design resolves hotspot issues and enables flexible data allocation based on server performance and storage capabilities.

When scaling, a new group (e.g., Group02) can be added with its own ID range, eliminating the need for data migration and preserving the hotspot‑avoidance properties.

The system architecture consists of three tables linking groups, databases, and tables; caching of the mapping in the JVM is recommended for performance, and dynamic configuration can be managed with Zookeeper, avoiding service restarts in large‑scale environments.

The article concludes that the hybrid approach provides a practical, scalable sharding solution for distributed databases.

distributed systemsscalabilityDatabaseShardinghashrange
Architect's Tech Stack
Written by

Architect's Tech Stack

Java backend, microservices, distributed systems, containerized programming, and more.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.