# 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 concept. Updated 2026-10-29. Page: https://blowstack.com/tools/cloud-concepts-hub/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.

Practice exams covering Sharding: [AIP-C01 AWS Certified Generative AI Developer - Professional](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional), [SAA-C03 AWS Certified Solutions Architect - Associate](https://blowstack.com/practice-exams/aws-certified-solutions-architect-associate).

## 6 key aspects of Sharding

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

1. **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.
2. **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.
3. **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.
4. **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.
5. **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.
6. **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](https://blowstack.com/tools/cloud-services-hub/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.
- **[Amazon DynamoDB](https://blowstack.com/tools/cloud-services-hub/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.
- **[Amazon ElastiCache](https://blowstack.com/tools/cloud-services-hub/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.
- **[Amazon DocumentDB (with MongoDB compatibility)](https://blowstack.com/tools/cloud-services-hub/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.

## Sharding exam questions

Real practice exam questions on Sharding, with the correct answer and its explanation.

### Question 1 (SAA-C03)

**Question:**

A software company runs a multi-tenant billing application on Amazon RDS for PostgreSQL. Thousands of tenants generate approximately equal volumes of write traffic. Every transaction and query includes a tenant ID and accesses data for only that tenant. The application requires relational joins and atomic transactions within each tenant but does not require operations across tenants.

The database uses the largest supported DB instance class. Performance testing shows that executing write transactions saturates the database CPU. Queries and indexes are optimized, read traffic is minimal, and storage performance is not a bottleneck. The company expects write traffic to triple and can modify the application's database routing logic.

Which solution will provide additional write capacity while preserving the required transaction behavior?

**Correct answer:** Create multiple independent RDS for PostgreSQL DB instances with the same schema. Distribute tenants across the instances by hashing tenant ID, and route all operations for a tenant to its assigned instance.

**Explanation:** Distributing different tenants across independent database instances spreads write processing across multiple CPUs. Keeping all of a tenant's data on one instance preserves local relational joins and atomic transactions. The similar tenant workloads and tenant-scoped access patterns make tenant ID an appropriate distribution key.

### Question 2 (AIP-C01)

**Question:**

A company operates a read-heavy RAG application on an Amazon OpenSearch Service provisioned domain with 12 identical data nodes. Its vector index has six primary shards and no replicas. Every retrieval request searches the entire corpus by using Faiss HNSW. Ingestion traffic is negligible.

At peak concurrency, requests queue on the six nodes that host primary shards, while the other six data nodes have substantial unused CPU capacity. Each shard's native vector index requires 18 GiB of memory, and each node has a 24-GiB native vector memory budget. Profiling confirms that individual searches meet the latency target when requests do not queue.

The company must increase concurrent retrieval throughput using the existing nodes, preserve the current retrieval quality, and avoid increasing the number of shard-level searches for each request. Which change best meets these requirements?

**Correct answer:** Configure one replica for the index and distribute the resulting 12 shard copies evenly across the data nodes. Allow OpenSearch to select a primary or replica copy for each shard-level search.

**Explanation:** One replica creates six additional searchable shard copies, allowing all 12 nodes to serve concurrent requests. Each node can hold one 18-GiB native vector index within its 24-GiB budget. A request still searches one copy from each of the six shard groups, so fan-out remains unchanged. Replication preserves the corpus and ANN configuration.

## Practice Sharding in a full exam

Questions on Sharding in each practice exam, with every answer option and an explanation for each:

- [AIP-C01](https://blowstack.com/practice-exams/aws-certified-generative-ai-developer-professional): 4 questions
- [SAA-C03](https://blowstack.com/practice-exams/aws-certified-solutions-architect-associate): 3 questions

## What is Sharding

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.

## Learn Sharding in lessons

3 short lessons on Sharding in 2 certification courses.

- SAA-C03: Sharding: partition keys and query routing (Premium), https://app.blowstack.com/lessons/sharding-partition-keys-and-query-routing-saa-c03
- AIP-C01: Hierarchical Indexing vs Sharding (Premium), https://app.blowstack.com/lessons/hierarchical-indexing-vs-sharding-aip-c01
- AIP-C01: Sharding: vector search partitioning (Premium), https://app.blowstack.com/lessons/sharding-vector-search-partitioning-aip-c01
