CLOUD CONCEPT

Sharding

Sharding divides a dataset into horizontal subsets distributed across storage or compute resources so that capacity and workload can scale beyond a single resource.

Cloud Concepts Hub →

What is Sharding

Each shard holds part of the data, and a routing mechanism determines which shard should handle a record or query. Sharding can increase storage capacity and aggregate read and write throughput, but its effectiveness depends on balanced distribution, query locality, and the cost of coordinating work across shards.

Sharding is horizontal data partitioning across independently managed storage or compute resources. Instead of storing every record on one database instance, a system distributes records among shards using a partitioning rule. A shard usually contains the same logical kinds of records as other shards but owns a different subset. Shards and servers are not necessarily one-to-one: a server can host several shards, and shard replicas can reside on other servers.

The partitioning rule must match the application's access patterns. Hash partitioning spreads records using a hash of a key, which generally helps distribute load. Range partitioning groups adjacent values, which can make time-window or ordered queries efficient but can concentrate new writes on one shard. Directory-based routing maintains a mapping between records or tenants and their locations. For example, routing orders by customer identifier keeps one customer's orders together, but an unusually large customer can become a hotspot.

Sharding is particularly useful when a single database writer cannot provide enough write throughput or when the dataset exceeds practical single-instance capacity. Read-intensive applications may first benefit from caching or read replicas without introducing sharding complexity. Replication copies the same data; sharding distributes different data. Replicas can improve availability and read capacity, but they do not inherently distribute writes to distinct portions of a dataset. Many architectures combine both techniques.

Queries that specify the shard key can target a small part of the system. Queries without suitable routing information may require scatter-gather execution: contacting many shards and merging their results. This can increase latency, network traffic, and sensitivity to slow shards. Cross-shard joins, uniqueness constraints, and transactions also require special consideration. Some databases support distributed transactions, but support and coordination costs vary; sharding does not inherently require eventual consistency or eliminate transaction guarantees.

For vector search, each shard holds a subset of vectors and its associated search index structures. A semantic search request may query several shards, obtain local candidates, and merge them into a final ranked result. More shards can enable parallelism and reduce the data held by each shard, but excessive sharding adds coordination, metadata, memory, and scheduling overhead. Approximate nearest-neighbor search also requires tuning candidate counts and search effort; distributing vectors does not automatically preserve the same recall and latency characteristics.

In Amazon OpenSearch Service, an index has primary shards and can have replica shards. Primary-shard count determines how the index's data is partitioned, while replicas provide additional copies for availability and search capacity. Engineers should size shards using measured vector dimensions, document counts, index structures, ingestion rates, concurrency, and available memory rather than assuming that more shards always improve performance. Changes to primary-shard layout require supported operations such as splitting or reindexing, subject to index and engine constraints.

Multiple indexes can separate specialized domains, such as legal documents and product manuals, allowing different mappings, retention policies, and retrieval settings. A hierarchical retrieval design can first select relevant domains or collections and then search their vector indexes. This reduces fan-out only when the first stage reliably selects the necessary data; incorrect routing can exclude relevant results. Logical domain separation is not automatically physical sharding, and a hierarchical retrieval pipeline is distinct from the graph hierarchy inside an HNSW vector index.

Operationally, monitor per-shard throughput, latency, storage, memory pressure, and throttling rather than relying only on cluster averages. Plan for growth, rebalancing, backups, recovery, and capacity during node failures. Adding nodes helps only if the system can redistribute shards or workload effectively. Routing must also preserve tenant authorization and required data placement: a shard key or separate index is not, by itself, an access-control boundary.

Key aspects of Sharding

Effective sharding balances data and traffic while preserving query locality, retrieval quality, availability, and manageable operating costs.

Horizontal distribution

Each shard owns a subset of records, allowing storage and processing to spread across resources. This differs from vertical partitioning, which separates columns or attributes, and replication, which maintains additional copies.

Access-pattern-driven shard keys

Choose a key that supports common queries while spreading both data volume and request traffic. High cardinality helps, but a heavily accessed individual key can still create a hotspot.

Targeted routing versus scatter-gather

Requests that identify the owning shard avoid unnecessary work elsewhere. Queries spanning many shards require coordination and result merging, which can offset the benefits of parallel execution.

Independent capacity and availability concerns

Sharding distributes data and workload, while replication protects copies and can add read capacity. Production designs commonly combine shard distribution with replicas placed across failure domains.

Vector retrieval fan-out and recall

Distributed vector search merges candidates from participating shards, so shard count, candidate counts, filtering, and search effort must be tested together. Domain-specific indexes and hierarchical routing can reduce search scope, but overly restrictive routing can reduce recall.

Rebalancing and operational overhead

Growth and skew can require moving data or changing the partitioning layout. Account for migration traffic, temporary capacity, recovery behavior, and the database's supported resharding operations.

Cloud services for Sharding

These services apply sharding at different layers rather than requiring one combined architecture. DynamoDB can hold operational records, OpenSearch Service can maintain a derived search or vector index, and ElastiCache can cache frequently accessed data or retrieval results. DocumentDB elastic clusters provide another option for sharded document workloads. When combining stores, design each store's partitioning for its own access patterns instead of assuming that one shard key fits every system. Propagate updates through a reliable ingestion pipeline, account for synchronization delays, and enforce authorization independently in each retrieval path.

Amazon OpenSearch Service image Amazon OpenSearch Service

Indexes distribute documents and vectors across primary shards, with replica shards providing additional copies. Shard sizing, domain-specific indexes, query routing, and approximate nearest-neighbor search settings jointly affect semantic search throughput, latency, and recall.

Open Amazon OpenSearch Service →
Amazon DynamoDB image Amazon DynamoDB

DynamoDB manages physical data partitions and uses the partition-key value to determine data placement. Key design remains important because concentrated traffic can create hot partitions; application-level write sharding can spread a hot logical key across multiple key values, at the cost of more complex reads.

Open Amazon DynamoDB →
Amazon ElastiCache image Amazon ElastiCache

Node-based ElastiCache deployments using Valkey or Redis OSS with cluster mode enabled distribute keys across shards using hash slots. Each shard has a primary and can have replicas; multi-key operations must respect cluster slot constraints, and concentrating related keys in one slot can create a hotspot.

Open Amazon ElastiCache →
Amazon DocumentDB image Amazon DocumentDB (with MongoDB compatibility)

Amazon DocumentDB elastic clusters use a collection's shard key to distribute document data and workload across shards. Choose shard keys around query targeting and load distribution, and distinguish elastic-cluster sharding from the architecture of instance-based DocumentDB clusters.

Open Amazon DocumentDB (with MongoDB compatibility) →