Free book sample

Database Sharding Essentials

Scaling Your RPC Infrastructure for High-Performance Applications

Many developers assume that adding more database servers automatically solves performance problems—but without proper sharding strategy, you'll end up with bottlenecks, inconsistent data, and operational nightmares.

191 pages10 chaptersApr 28, 2026Databases

Download sample:

About this book

Database sharding is a powerful technique for scaling RPC systems, but it's often misunderstood and poorly implemented. This book cuts through the complexity and shows you exactly how sharding works, when to use it, and how to implement it correctly. You'll learn how to choose the right sharding key, design sharding architectures that handle your growth, manage data consistency across shards, and avoid common pitfalls that plague distributed systems. Whether you're building a blockchain RPC node, a high-traffic API service, or a distributed application, this guide provides practical strategies and real-world patterns you can apply immediately. Master the fundamentals of sharding and build systems that scale reliably.

Table of contents

  1. IntroductionWhy Sharding Matters for Modern Applications, What You'll Learn in This Book, How to Use This GuideRead below
  2. Chapter 1: Understanding Database Scaling ChallengesVertical vs. Horizontal Scaling, RPC Performance Bottlenecks, When Scaling Becomes Necessary
  3. Chapter 2: Sharding FundamentalsWhat Is Sharding and How It Works, Sharding vs. Replication and Caching, Benefits and Trade-offs of Sharding
  4. Chapter 3: Choosing Your Sharding KeyCriteria for Selecting a Sharding Key, Common Sharding Keys in Practice, Avoiding Hotspots and Uneven Distribution, Immutability and Long-term Viability
  5. Chapter 4: Sharding Strategies and ArchitecturesRange-Based Sharding, Hash-Based Sharding, Directory-Based Sharding, Geographic and Hybrid Sharding
  6. Chapter 5: Implementing Sharding in RPC SystemsDesigning Your Sharded Architecture, Implementing Shard Routing Logic, Data Migration and Initial Sharding
  7. Chapter 6: Managing Consistency and TransactionsSingle-Shard Transactions, Cross-Shard Transactions and Distributed Consensus, Eventual Consistency Models, Conflict Resolution Strategies
  8. Chapter 7: Querying Across ShardsOptimizing Single-Shard Queries, Executing Cross-Shard Queries, Aggregation and Join Patterns
  9. Chapter 8: Resharding and RebalancingWhen and Why You Need to Reshard, Resharding Approaches and Techniques, Achieving Zero-Downtime Resharding, Handling Failures During Resharding
  10. Chapter 9: Monitoring and ObservabilityKey Metrics for Sharded Systems, Detecting Hotspots and Imbalances, Alerting and Response Strategies
  11. Chapter 10: Common Pitfalls and How to Avoid ThemPoor Sharding Key Selection, Underestimating Operational Complexity, Data Consistency and Synchronization Issues
  12. ConclusionKey Takeaways, Next Steps in Your Sharding Journey

Introduction

Every successful application eventually hits a wall. Traffic grows, data accumulates, and what once felt like a robust database setup starts showing cracks. Queries slow down. Response times climb. Users notice. Engineers scramble. This is not a hypothetical scenario — it is a pattern that plays out across startups and enterprise systems alike, often at the worst possible moment. The question is never really if your database will struggle under load, but when, and whether you will be ready when it does.

Database sharding is one of the most powerful tools available for handling that growth. At its core, sharding means splitting your data across multiple database instances so that no single server carries the full load. Instead of one database handling every read and write, the work gets distributed. Each piece of the system handles a smaller, more manageable slice of the total data. Done well, sharding can dramatically reduce latency, increase throughput, and give your system room to grow without a complete architectural overhaul. Done poorly, it creates a different set of problems that can be even harder to untangle.

This book focuses specifically on sharding in the context of RPC (Remote Procedure Call) infrastructure. RPC systems are the backbone of many modern distributed applications, from blockchain nodes processing thousands of transactions per second to microservice architectures where dozens of services communicate in real time. These systems have unique performance demands. They need low latency, high availability, and consistent behavior under unpredictable load. Sharding, when applied thoughtfully, addresses all of these needs. But the path from "we need to shard" to "we have a working, well-tuned sharded system" is full of decisions that can make or break your architecture.

This guide is built for developers and engineers who already have a working knowledge of databases and distributed systems but want to go deeper on sharding specifically. You will not find vague advice here. Instead, you will find concrete strategies, real trade-offs, and practical patterns you can apply to your own systems. Whether you are designing a sharded architecture from scratch or trying to fix one that is already struggling, this book gives you the tools to make better decisions at every step.

Why Sharding Matters for Modern Applications

Modern applications generate data at a scale that would have seemed extraordinary just a decade ago. A mid-sized e-commerce platform might process millions of orders per day. A blockchain RPC node might field tens of thousands of API calls per minute. A real-time analytics service might ingest billions of events per week. Traditional single-server database setups were never designed for this kind of volume, and the cracks show up fast when traffic spikes or data grows beyond what one machine can comfortably handle.

The most common first response to database performance problems is vertical scaling: adding more CPU, RAM, or faster storage to the existing server. This works up to a point. A bigger machine can handle more load, and for many applications, vertical scaling buys enough headroom to keep things running smoothly. But vertical scaling has hard limits. At some point, you hit the ceiling of what a single machine can provide, and the cost of each incremental upgrade grows steeply. A server with 512 GB of RAM costs far more than twice what a 256 GB server costs, and it still represents a single point of failure.[1]

Horizontal scaling, by contrast, means adding more machines rather than making one machine bigger. Sharding is the primary way to apply horizontal scaling to a database layer. Instead of one giant database server, you have multiple smaller ones, each responsible for a portion of the data. This approach scales more linearly with cost, removes single points of failure, and allows different parts of the system to grow independently. It is the architectural pattern behind some of the largest data systems in the world, including those used by major social media platforms, financial services, and cloud infrastructure providers.

For RPC systems specifically, sharding matters because RPC calls are often latency-sensitive. When a client makes a remote procedure call, it expects a fast response. If the database backing that call is overloaded, the entire call chain slows down. In a microservices environment, one slow database can cascade into slow responses across multiple services. Sharding reduces the load on any individual database node, which directly translates to faster query execution and lower end-to-end latency for RPC calls.

Consider a concrete example. Imagine a blockchain RPC service that stores transaction data for a public network. As the chain grows, the transaction table might reach hundreds of millions of rows. A query to look up a specific transaction by hash on a single-node database might take several hundred milliseconds under load. With sharding, that same query hits only one shard containing a fraction of the total data, and the response time drops to single-digit milliseconds. The difference is not just a performance improvement — it changes what the system can realistically offer to its users.

Sharding also enables geographic distribution. By placing shards in different regions, you can route users to the shard closest to them, reducing network latency. A user in Europe querying a shard hosted in Frankfurt will get a faster response than if their query had to travel to a data center in Virginia. This kind of geographic sharding is increasingly important as applications serve global audiences and regulatory requirements push data residency into specific jurisdictions.

None of this comes for free. Sharding introduces real complexity. Cross-shard queries become harder. Distributed transactions require careful coordination. Rebalancing data when shards grow unevenly is a significant operational challenge. The goal of this book is not to make sharding sound easy — it is to give you a clear-eyed view of both the benefits and the costs, so you can make informed decisions and implement sharding in a way that actually works for your system.

Sharding is not a silver bullet. It is a trade-off: you exchange the simplicity of a single database for the scalability of many, and you take on the responsibility of managing that complexity carefully.

Understanding why sharding matters is the first step. The rest of this book is about understanding how to do it right, from choosing the correct sharding key to monitoring your shards in production and handling the inevitable challenges that come with running a distributed data system.

What You'll Learn in This Book

This book covers the full lifecycle of database sharding in RPC systems, from foundational concepts to production operations. Each chapter builds on the previous one, so by the end you will have a complete mental model of how sharding works and how to apply it in practice. Here is a breakdown of what each part of the book covers and why it matters.

Chapter 1: Understanding Database Scaling Challenges sets the stage by examining why databases struggle under load and what the realistic options are for addressing that. You will learn the difference between vertical and horizontal scaling, understand where RPC performance bottlenecks typically originate, and develop a framework for recognizing when your system actually needs to scale. This chapter helps you avoid the common mistake of reaching for sharding before simpler solutions have been exhausted.

Chapter 2: Sharding Fundamentals explains what sharding actually is at a technical level, how it differs from replication and caching, and what the core trade-offs look like. Many engineers have a rough idea of what sharding means but lack a precise mental model. This chapter builds that model clearly, so every subsequent decision rests on a solid foundation.

Chapter 3: Choosing Your Sharding Key is arguably the most important chapter in the book. The sharding key determines how data gets distributed across shards, and a poor choice here causes problems that are extremely difficult to fix later. You will learn the criteria for evaluating sharding keys, see common examples from real-world systems, and understand how to avoid hotspots and uneven distribution. You will also learn why immutability matters and how to think about long-term viability when making this decision.

Chapter 4: Sharding Strategies and Architectures covers the four main approaches to sharding:

  • Range-based sharding, where data is divided by value ranges (for example, user IDs 1–1,000,000 on shard one, 1,000,001–2,000,000 on shard two)
  • Hash-based sharding, where a hash function determines which shard receives each record
  • Directory-based sharding, where a lookup table maps each record to its shard
  • Geographic and hybrid sharding, which combines multiple strategies for complex, globally distributed systems
Each strategy has distinct trade-offs in terms of implementation complexity, query flexibility, and the cost of rebalancing data as the system grows.

Chapter 5: Implementing Sharding in RPC Systems moves from theory to practice. You will learn how to design a sharded architecture, implement shard routing logic that directs queries to the correct shard, and plan a data migration strategy for moving from a single database to a sharded setup. This chapter includes concrete patterns and code-level guidance for building the routing layer that sits between your application and your database shards.

Chapter 6: Managing Consistency and Transactions addresses one of the hardest problems in sharded systems. Single-shard transactions are straightforward, but cross-shard transactions require distributed coordination. You will learn about eventual consistency models, the trade-offs between strong and eventual consistency, and practical conflict resolution strategies. This chapter gives you the vocabulary and the tools to reason clearly about consistency in your own system.

Chapters 7 through 10 cover the operational realities of running a sharded system in production:

  • Chapter 7 explains how to query across shards efficiently, including aggregation and join patterns that work at scale
  • Chapter 8 covers resharding and rebalancing, including how to achieve zero-downtime resharding and handle failures during the process
  • Chapter 9 focuses on monitoring and observability, with specific metrics to track, methods for detecting hotspots, and alerting strategies
  • Chapter 10 catalogs the most common pitfalls in sharding implementations and gives you concrete guidance for avoiding each one

By the time you finish this book, you will be able to evaluate whether sharding is the right solution for a given system, design a sharding architecture that fits your data access patterns, implement that architecture with confidence, and operate it effectively in production. These are skills that apply across database technologies and system types, making them valuable well beyond any single project.

The book also emphasizes something that technical guides often skip: knowing when not to shard. Sharding adds complexity, and complexity has costs. Sometimes a well-tuned single database with good indexing, caching, and read replicas is the right answer. Understanding the full landscape of scaling options makes you a better engineer, not just a better sharding practitioner.

How to Use This Guide

This book is designed to work for you whether you read it cover to cover or jump directly to the chapters most relevant to your current situation. The chapters are ordered to build understanding progressively, so if you are new to sharding or want a complete picture, reading from the beginning is the best approach. If you already have a working sharded system and are dealing with a specific problem, the chapter structure makes it easy to navigate directly to what you need.

Here is a quick reference for common situations and where to start:

  • You are evaluating whether to shard at all: Start with Chapter 1 and Chapter 2. These chapters help you understand the problem space and decide whether sharding is the right tool for your situation.
  • You are designing a new sharded system: Read Chapters 2 through 5 in order. These chapters cover the foundational decisions that shape everything else.
  • You are dealing with hotspots or uneven data distribution: Go directly to Chapter 3 (sharding key selection) and Chapter 9 (detecting imbalances).
  • You are planning a migration from a single database to a sharded setup: Chapter 5 covers data migration strategy in detail.
  • You are struggling with cross-shard queries or consistency issues: Chapters 6 and 7 address these problems specifically.
  • You need to reshard an existing system: Chapter 8 is dedicated to this challenge.
  • You are setting up monitoring for a sharded system: Chapter 9 covers the key metrics and alerting strategies you need.

Throughout the book, you will find several recurring elements designed to make the content more useful. Concrete examples appear in every chapter, grounding abstract concepts in real scenarios. These examples draw from common system types including blockchain RPC nodes, API gateways, e-commerce platforms, and analytics services. The goal is to show how the same principles apply across different contexts, so you can adapt them to your own situation.

Trade-off summaries appear at key decision points. Sharding involves a lot of choices where there is no universally correct answer, only answers that are better or worse for a given set of requirements. These summaries lay out the relevant factors clearly so you can make an informed decision rather than guessing. They are especially useful when you need to explain a technical decision to teammates or stakeholders who want to understand the reasoning.

The book also includes anti-patterns alongside recommended approaches. Knowing what not to do is often as valuable as knowing what to do, especially in a domain where mistakes are expensive to fix. Each anti-pattern comes with an explanation of why it causes problems and what to do instead. Chapter 10 is dedicated entirely to common pitfalls, but anti-patterns appear throughout the book wherever they are most relevant to the topic at hand.

A note on technology choices: this book is deliberately technology-agnostic where possible. The concepts and strategies covered here apply whether you are working with PostgreSQL, MySQL, MongoDB, Cassandra, or a custom data store. Where specific technologies are mentioned, they serve as concrete illustrations of a broader principle rather than prescriptions. Your choice of database technology will influence implementation details, but the core sharding concepts remain consistent across systems.

You will get the most out of this book if you approach it as a practitioner rather than a passive reader. When a concept is introduced, think about how it applies to a system you are currently working on or have worked on in the past. When a trade-off is presented, consider which side of that trade-off your system's requirements push you toward. When an example is given, ask yourself what would change if the numbers or constraints were different. This kind of active engagement turns the concepts from abstract knowledge into practical intuition.

Finally, it is worth being honest about what this book does not cover. It is not a comprehensive guide to any specific database technology. It does not cover every possible sharding implementation in detail. It does not address every edge case you might encounter in production. What it does provide is a strong conceptual foundation, a set of proven strategies, and the analytical tools to reason clearly about sharding decisions. With that foundation in place, you will be well-equipped to dig into the specifics of your own technology stack and adapt the patterns here to your particular needs.

The best sharding decisions come from understanding the principles deeply enough to apply them flexibly, not from following a rigid recipe. This book aims to give you that depth.

Scaling a database system is one of the more challenging problems in software engineering, but it is also one of the most rewarding to solve well. A well-sharded system can handle growth that would have been impossible otherwise, and it can do so reliably and efficiently. The chapters ahead will give you everything you need to build systems like that. Let's get started.

Back to contents

Notes

Introduction

  1. 1. Martin Kleppmann, Designing Data-Intensive Applications, O'Reilly Media, 2017

This is the end of the free sample. The full book has 10 chapters.

Want this book written for you?

Tell us your goals and background, and get your own version of this book, tailored by AI to you.

User avatar
User avatar
User avatar
User avatar
User avatar
9,168 books created by readers like you
As seen on:
Product HuntRedditMediumDEV

Benefits of AI-tailored books

Read one book, not ten:
all the Databases knowledge you need, gathered into a single book.
Save days of learning:
tell us your goals, choose your topics, and the whole book is built around them.
Learn effortlessly:
Databases book written for your specific background and expertise.
Understand at a glance:
includes charts, tables, timelines, checklists, decision trees, and more.
Stay current:
written the day you order it, not years ago.
Trust what you read:
every book is checked for accuracy, with real research when your subject needs it.

Create your unique book in 3 steps

1. Select your focus

Select the focus of your Databases book and share your background

Your Databases book focus
2. Personalize your book

Specify your goals and choose sub-topics to include

3. Get your tailored book

Your book is ready in 10 minutes. Read it online, download as EPUB or PDF, or send to Kindle.

Frequently asked questions

What is TailoredRead?

TailoredRead creates complete, full-length nonfiction ebooks, written specifically for you. Tell us what you want to learn and why, and TailoredRead writes you a complete ebook on it, with charts, tables, and diagrams throughout. Read it online, on Kindle, or on any e-reader, or download it as a PDF or EPUB. Every book is written fresh the day you order it.

How is the book tailored to me?

Before anything is written, you answer a few short questions about your goals, your background, and the topics you care about. Your book is then planned around your answers: written at your level, focused on your goals, and covering the topics you chose, instead of the one-size-fits-all book a store sells everyone.

Will it read like generic AI content?

No. Your book isn't a chat transcript: it's planned chapter by chapter before a single word is written, told in a clear book voice, and explains ideas visually with charts, tables, and diagrams. After writing, every book goes through an editorial pass that polishes chapters so the book reads consistent from start to finish. Judge for yourself: browse thousands of sample books on our Explore Books page.

How accurate is the content?

Our AI first checks whether your subject needs live research. Niche and fast-moving subjects are researched before writing, and the book plan and chapters are grounded in what it finds. After writing, every book goes through a quality pass that checks its facts and consistency, and researched books list their sources in a Notes section at the back.

How long is the book?

You choose the length: Comprehensive (250-300 pages), Detailed (150-200 pages), Essential (70-100 pages), or Short (30-50 pages).

Does the book include visuals?

Yes. Every book includes charts, tables, and diagrams: timelines, checklists, step-by-step guides, decision trees, comparison tables, matrices, and bar charts. A typical book includes dozens of these visual elements.

Can I read it on Kindle? What formats can I download?

Yes. Every book can be read in our online reader or downloaded as a PDF or EPUB. The EPUB can be opened with Kindle, Apple Books, Kobo, and any e-reader. The Commercial and Author licenses also include an editable Word (DOCX) and Markdown download.

How much does it cost?

About the price of a regular ebook. The exact price depends on your book's length and complexity, from $2 for the shortest books to $35 for the most comprehensive, and it's shown when you review your book, before you commit to anything. Each book is a one-time purchase, yours to keep, no subscription. Licenses that let you share, teach, or publish your book range from $35.99 to $49.99.

Can I preview the book before purchasing?

Before you pay, you'll see what your book will cover: the title, a detailed description, the estimated length, and the complete chapter-by-chapter table of contents, so you know what you're getting before you decide. The full text itself is written after you purchase.

How long does it take to create a book?

About 10 minutes. You can start reading the opening chapters while the rest is still being written.

Personalize and buy this book

Get your personalized version, tailored by AI to your goals, background, and interests