Databases 2 min read

How Horizontal Sharding Boosts Database Performance with Hash Routing

Horizontal sharding splits a large table into multiple databases using hash‑modulo routing, improving performance and scalability; the article explains the basic algorithm, shows example calculations for a 4‑shard setup, and demonstrates how to expand shards from four to eight.

Java High-Performance Architecture
Java High-Performance Architecture
Java High-Performance Architecture
How Horizontal Sharding Boosts Database Performance with Hash Routing

Horizontal sharding splits the contents of a large table into different tables to improve database performance. 1 table → N tables.

Sharding is decided by a routing algorithm. Common routing algorithms: hash value modulo.

For example, divide the database into 4 shards.

Set the modulo value to 1024 .

Thus each shard occupies 256 positions. Compute the shard for the value test1234:

hash(test1234) = 3109729401 % 1024 = 537

How to expand shards? For example, to expand from 4 shards to 8, split each original shard into 2, so each shard occupies 128 positions.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Scalabilitydatabase shardinghorizontal partitioningHash Routing
Java High-Performance Architecture
Written by

Java High-Performance Architecture

Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.

0 followers
Reader feedback

How this landed with the community

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.