Distributed Vector Search and Sharding Architecture in Production: Horizontal Partitioning, Scatter-Gather Tail Latency, Filter-Aware Routing, and Dynamic Rebalancing

Scaling vector search beyond tens of millions of high-dimensional embeddings inevitably hits a physical boundary: the single-node memory wall. Because graph-based approximate nearest neighbor (ANN) algorithms such as Hierarchical Navigable Small World (HNSW) require random memory access patterns across graph vertices and high-dimensional vectors, keeping embeddings and index structures in RAM is critical for sub-20ms query latencies. A collection of 100 million 1,536-dimensional float32 vectors

8 min
Distributed Vector Search and Sharding Architecture in Production: Horizontal Partitioning, Scatter-Gather Tail Latency, Filter-Aware Routing, and Dynamic Rebalancing

Scaling vector search beyond tens of millions of high-dimensional embeddings inevitably hits a physical boundary: the single-node memory wall. Because graph-based approximate nearest neighbor (ANN) algorithms such as Hierarchical Navigable Small World (HNSW) require random memory access patterns across graph vertices and high-dimensional vectors, keeping embeddings and index structures in RAM is critical for sub-20ms query latencies.

A collection of 100 million 1,536-dimensional float32 vectors requires approximately 614 GB of raw storage solely for the vector coordinates. When adding HNSW graph adjacency lists, index metadata, and vector payload attributes, the in-memory footprint routinely exceeds 900 GB to 1.2 TB. When dataset scale surpasses what can economically or practically reside on a single compute instance, engineering teams must transition from vertical hardware scaling to distributed sharding architectures.

Designing a distributed vector search cluster introduces complex trade-offs between scatter-gather latency amplification, partition pruning, memory fragmentation, and write-time indexing contention.

Horizontal Partitioning Topologies

Partitioning vector data across a cluster requires selecting a distribution strategy that balances ingestion uniformity against query-time fan-out.

+-----------------------------------------------------------------------+
|                       Horizontal Partitioning Models                  |
+-----------------------------------------------------------------------+
| 1. Random / Round-Robin: Uniform data spread; 100% query broadcast.   |
| 2. Consistent Hash: Deterministic ID lookup; 100% query broadcast.    |
| 3. Shard / Partition Keys: Deterministic routing; 1-shard targeted.   |
| 4. Semantic / Voronoi: Centroid-based; risk of boundary recall drop.  |
+-----------------------------------------------------------------------+

Random and Hash-Based Sharding

The simplest distribution model assigns incoming vectors to shards randomly or via consistent hashing over the document identifier. This approach guarantees an even distribution of data and write throughput across all data nodes in the cluster.

However, because vector similarity is metric-space dependent and uncorrelated with document IDs, hash-based sharding provides no semantic locality. Every similarity search query must be broadcast to every shard in the cluster. This 100% broadcast requirement turns every query into a distributed scatter-gather operation.

Custom Shard Keys and Metadata Partitioning

To avoid cluster-wide broadcast, modern vector engines implement deterministic routing via shard keys, such as Qdrant Custom Sharding and Milvus Partition Keys.

Under this pattern, vectors are partitioned based on a categorical metadata field, such as tenant_id, user_id, or region. When an incoming query specifies a filter matching the partition key, the coordinator proxy routes the search request exclusively to the specific shard holding that partition.

Targeted shard routing reduces network overhead and compute utilization from O(N)O(N) shards down to O(1)O(1). For multi-tenant applications where search scopes are isolated per organization, partition keys eliminate scatter-gather bottlenecks entirely.

Semantic and Centroid-Based Partitioning

An alternative approach partitions the vector space geometrically using coarse quantization (such as k-means centroids or Voronoi cells). Queries are first compared against cluster centroids, and execution is routed only to the shards whose Voronoi regions are proximate to the query vector.

While semantic partitioning reduces query fan-out without requiring explicit tenant keys, it introduces severe production failure modes:

  • Recall Degradation at Boundaries: Vectors near cluster borders require searching multiple neighboring shards. Omitting adjacent partitions causes immediate recall drops.
  • Data Skew and Hotspots: Real-world embeddings cluster around dense semantic regions, causing specific shards to receive disproportionate storage and query traffic.
  • Re-clustering Overhead: As the embedding distribution shifts over time, centroids drift, requiring expensive global dataset re-indexing.

The Scatter-Gather Bottleneck and Latency Tail Mathematics

When queries cannot be pruned to a single partition, the system must execute a distributed scatter-gather workflow across NN shards.

Distributed Scatter-Gather Architecture

The Distributed Query Workflow

The scatter-gather execution cycle proceeds across three primary stages:

  1. Query Fan-Out: The stateless coordinator proxy receives the query vector and search parameters (top-kk, distance metric, metadata filters), serializes the request, and dispatches it concurrently to all target shard worker nodes.
  2. Local Segment Execution: Each worker node executes a local ANN search against its resident index segments, identifying its local top-kk nearest candidates.
  3. Global Reduce: Each worker returns its candidate list (kk IDs and distance scores) over the internal network to the proxy. The proxy merges the NN sorted arrays using a min-heap or priority queue to produce the final global top-kk result set.

Tail Latency Amplification

In a distributed scatter-gather system, query completion is bounded by the slowest responding shard. If TiT_i represents the latency of shard ii, the total query latency TqueryT_{\text{query}} is:

Tquery=max(T1,T2,,TN)+Tnetwork+TreduceT_{\text{query}} = \max(T_1, T_2, \dots, T_N) + T_{\text{network}} + T_{\text{reduce}}

If each individual shard has an independent probability pp of experiencing a latency outlier exceeding threshold LL (due to garbage collection, cache misses, or background compaction), the probability PclusterP_{\text{cluster}} that at least one of the NN shards experiences an outlier is:

Pcluster=1(1p)NP_{\text{cluster}} = 1 - (1 - p)^N

For a cluster sharded across 16 nodes with an individual node p99 outlier rate of 1% (p=0.01p = 0.01):

Pcluster=1(10.01)16=1(0.99)1614.85%P_{\text{cluster}} = 1 - (1 - 0.01)^{16} = 1 - (0.99)^{16} \approx 14.85\%

Nearly 15% of all cluster queries will experience tail latency delays, degrading the effective cluster-level 99th percentile far beyond the single-node profile.

Empirical evaluation in When More Cores Hurts: The Vector Database Scaling Paradox in HPC (arXiv:2606.08950) demonstrates this phenomenon: when partitioning an 88-million vector dataset across increasing segment counts (from 1 to 8 segments), search latency increased from 4.19 seconds to 22.65 seconds due to partition fan-out, memory bus saturation, and synchronization overhead.

Segment Architecture vs. Monolithic Shard Graphs

Production vector engines organize shard storage into segments to manage data ingestion and index lifecycle.

+-----------------------------------------------------------------------+
|                       Shard Segment Topology                          |
+-----------------------------------------------------------------------+
| [Incoming Writes]                                                     |
|        │                                                              |
|        ▼                                                              |
| ┌─────────────────────────┐         ┌──────────────────────────────┐  |
| │ Growing / Unindexed     │ ──Flush─▶│ Sealed / Immutable Segments  │  |
| │ Segment (MemTable/WAL)  │         │ (HNSW / DiskANN / Quantized) │  |
| │ (Exhaustive Scan)       │         │ (Graph Traversal)            │  |
| └─────────────────────────┘         └──────────────────────────────┘  |
+-----------------------------------------------------------------------+

Growing vs. Sealed Segments

When new vectors are inserted into systems like Milvus or Qdrant, building an HNSW graph incrementally for every single write introduces lock contention on graph neighbor arrays. To maintain high ingestion throughput:

  • Growing Segments: Incoming vectors are written to an append-only write-ahead log (WAL) and an in-memory buffer without an ANN graph. Queries hitting growing segments must perform a brute-force flat scan.
  • Sealed Segments: Once a growing segment reaches a configured threshold (e.g., 512 MB or 1 million vectors), it is sealed, marked immutable, and handed off to background index workers to construct the HNSW or quantized index.

Ingestion Contention and Query Degradation

During continuous high-volume ingestion, the presence of unindexed vectors in growing segments creates immediate tail latency spikes.

The empirical benchmark in When More Cores Hurts (arXiv:2606.08950) highlights this trade-off: under concurrent insertion and querying, Milvus, Weaviate, and Qdrant experience significant performance shifts. While Weaviate updates active HNSW graphs in-place (creating memory contention), Qdrant and Milvus isolate writes into growing segments, trading short-term brute-force scan overhead on small buffers for predictable bulk indexing throughput.

In decoupled architectures like Milvus Storage/Compute Disaggregation, index building is entirely offloaded to dedicated IndexNode pools, preventing CPU-intensive graph construction from stealing cycles from QueryNodes.

Filter Pushdown and Selective Shard Traversal

Vector search queries in production rarely execute in isolation; they almost always include business logic filters (e.g., status = "active" AND created_at > 1700000000).

+-----------------------------------------------------------------------+
|                    Metadata Filtering Strategies                      |
+-----------------------------------------------------------------------+
| 1. Pre-Filtering: Inverted index scan first -> vector search on set.  |
|    Pitfall: Inefficient if filter matches 90% of entire dataset.      |
|                                                                       |
| 2. Post-Filtering: Global ANN top-K -> prune non-matching items.      |
|    Pitfall: May return fewer than K results if filter is selective.   |
|                                                                       |
| 3. Integrated / Single-Stage Filtering: Traverse HNSW graph while     |
|    checking bitset masks in the inner distance evaluation loop.       |
|    Optimal: Balances recall guarantees and traversal speed.           |
+-----------------------------------------------------------------------+

Integrated Single-Stage Filtering

In integrated filtering, the query engine evaluates payload boolean conditions during the graph exploration phase. A bitset or roaring bitmap representing matching document IDs is constructed prior to graph traversal. As the algorithm explores neighboring vertices in the HNSW layer, it skips non-matching candidates from the candidate queue while maintaining graph connectivity.

When distributed across shards, the coordinator pushes filter ASTs down to individual query nodes. If a shard's metadata index indicates zero matching documents within its local segments, the shard aborts vector distance calculations immediately, returning an empty result set in sub-millisecond time.

Dynamic Shard Rebalancing and High Availability

Maintaining low latency and fault tolerance across distributed vector clusters requires robust consensus, replication, and data migration mechanisms.

Consensus and Topology Management

Distributed vector databases rely on consensus layers—such as Raft in Qdrant or etcd in Milvus—to track cluster topology, shard assignments, and node health states. The consensus engine maintains a centralized routing table mapping collections, shards, and replica locations across physical nodes.

Shard Migration Under Live Traffic

When a node experiences resource exhaustion or hardware degradation, the cluster orchestrates dynamic shard migration without downtime:

  1. Snapshot Creation: The source node creates an immutable snapshot of the target shard's sealed segments and index files.
  2. Bulk Transfer: The snapshot is streamed over the network to the destination node. During transfer, the source node continues serving read and write traffic.
  3. Delta Sync & Catch-Up: Writes occurring during the bulk transfer are recorded in a local replication buffer and streamed to the destination node.
  4. Raft State Cutover: Once the destination replica's replication lag reaches zero, a Raft consensus transaction updates the cluster routing table, redirecting coordinator traffic to the new shard location and decommissioning the old instance.

Read Replicas and Bounded Staleness

To scale read throughput independently of dataset size, shards are assigned replication factors (RF2RF \ge 2). The proxy coordinator balances read queries across replica sets using round-robin, least-loaded, or latency-aware routing.

Systems allow tunable consistency levels:

  • Strong Consistency: Queries read exclusively from shards that have acknowledged all writes up to the current timestamp oracle (TSO) checkpoint.
  • Bounded Staleness / Eventual Consistency: Queries execute against local replica state, achieving higher throughput and lower p99 latency by avoiding distributed synchronization barriers.

Production Sizing and Capacity Planning

Estimating hardware and network capacity for a distributed vector cluster requires accounting for vector dimensions, graph parameters, payload size, and network serialization overhead.

+-----------------------------------------------------------------------+
|                    Vector Cluster Sizing Equations                    |
+-----------------------------------------------------------------------+
| Raw Vectors (Bytes) = Count * Dimension * 4 (float32)                 |
| HNSW Index (Bytes)  = Count * M * 2 * 4 (bidirectional edges) + Meta  |
| Shard VRAM/RAM (GB) = (Raw Vectors + HNSW Graph + Payloads) * 1.35    |
| Network Bandwidth   = QPS * Top-K * (Vector ID + Payload Size)        |
+-----------------------------------------------------------------------+

Memory Sizing Formula

For a collection with NtotalN_{\text{total}} vectors of dimensionality DD:

  • Raw Vector Memory: Mraw=Ntotal×D×4 bytesM_{\text{raw}} = N_{\text{total}} \times D \times 4\text{ bytes}
  • HNSW Edge Memory: For connectivity parameter MM (typically 16 to 64), each node stores up to 2M2M bidirectional edge pointers:

MHNSWNtotal×(2M×8 bytes)+Ntotal×16 bytes (metadata)M_{\text{HNSW}} \approx N_{\text{total}} \times (2M \times 8\text{ bytes}) + N_{\text{total}} \times 16\text{ bytes (metadata)}

  • Buffer Overhead: Add a 30% to 40% headroom multiplier to accommodate growing segment buffers, OS page cache, query execution heaps, and merge priority queues.

For 100 million 1536-dimensional vectors with M=32M = 32:

  • Mraw=100M×1536×4=614.4 GBM_{\text{raw}} = 100\text{M} \times 1536 \times 4 = 614.4\text{ GB}
  • MHNSW=100M×(64×8+16)=52.8 GBM_{\text{HNSW}} = 100\text{M} \times (64 \times 8 + 16) = 52.8\text{ GB}
  • Total Memory Requirement with headroom: (614.4+52.8)×1.35900.7 GB(614.4 + 52.8) \times 1.35 \approx 900.7\text{ GB}

Distributed across 8 query nodes, each node requires at least 128 GB of RAM to sustain in-memory graph search.

Network and Coordinator Throughput

At high query volumes (e.g., 2,000 QPS with top-k=100k = 100), the coordinator proxy must ingest, deserialize, and merge 2000×100×Nshards2000 \times 100 \times N_{\text{shards}} candidate records per second.

To prevent coordinator CPU saturation:

  • Use binary serialization protocols (gRPC with Protobuf or FlatBuffers) over raw JSON.
  • Avoid returning full payload attributes during the initial vector search phase; retrieve document IDs and distance scores first, perform the global reduce, and fetch full payload blobs only for the final top-kk items.
  • Deploy proxy instances behind a Layer 4 load balancer to scale query ingestion horizontally.

Architecture Decision Matrix

+-------------------+--------------------+--------------------+--------------------+
| Parameter         | Single-Node        | Custom Sharding    | Global Scatter-    |
|                   | (pgvector/Qdrant)  | (Tenant Keys)      | Gather (Milvus)    |
+-------------------+--------------------+--------------------+--------------------+
| Target Vector Vol | < 10M - 20M        | 10M - 1B+          | 100M - 10B+        |
| Query Fan-Out     | None (Local)       | Single Shard       | All Shards (N)     |
| Tail Latency (p99)| Predictable / Low  | Isolated / Low     | Amplified (Max N)  |
| Memory Footprint  | Single Box Limit   | Distributed Nodes  | Disaggregated Pods |
| Ingestion Scaling | Limited by Disk/CPU| Partition-Isolated | Independent WAL/   |
|                   |                    |                    | Index Nodes        |
+-------------------+--------------------+--------------------+--------------------+

Sources

Written by

More to read

  • Modern Hopfield Networks: How Continuous Energy Landscapes Explain Transformer Attention and Exponential Memory

    When Vaswani et al. introduced the Transformer architecture in 2017, scaled dot-product self-attention was presented primarily as a pragmatic computational mechanism: an efficient, highly parallelizable alternative to recurrence and convolutions. By computing pairwise inner products between queries and keys, normalizing via softmax, and taking a weighted sum of values, attention allowed models to route information dynamically across arbitrarily distant tokens. For several years, self-attention

    1 min
  • Fine-Grained Access Control in Enterprise RAG: Pre-Filtering vs. Post-Filtering, Zanzibar ReBAC Models, and Zero-Trust Retrieval Architecture

    Deploying Retrieval-Augmented Generation (RAG) across enterprise knowledge repositories introduces a security boundary that simple vector search was never designed to enforce. In corporate environments spanning Google Workspace, Microsoft SharePoint, Notion, Confluence, and internal ticket systems, access permissions are dynamic, hierarchical, and deeply nested. Attempting to enforce security at the prompt generation layer by instructing language models to ignore unauthorized context is fundame

    1 min
  • Inside Ulanqab: How Inner Mongolia Became the 12.5GW Epicenter of China's AI Data Center Boom

    Located approximately 350 kilometers northwest of Beijing, the grassland municipality of Ulanqab in Inner Mongolia has transformed into China's primary hub for artificial intelligence compute infrastructure. Historically recognized for agriculture and mineral extraction, the city now hosts nearly 100 enterprise data centers operating or under active construction, with technology firms pledging an aggregate capacity of 12.5 gigawatts (GW). According to a research note published by Goldman Sachs,

    1 min