Pinecone shard rebalancing error after blue‑green traffic switch

Problem – Shard Rebalancing Failure After Blue‑Green Traffic Switch

A production vector‑search service backed by Pinecone is deployed using a blue‑green pattern. Traffic is routed to the blue environment while a new green index is built and warmed. When the CI/CD pipeline flips the traffic switch, the Pinecone control plane initiates a shard rebalancing operation to move replica shards from the now‑idle blue index to the active green index. In several incidents the rebalancing step fails, leaving the index in a partially‑available state and causing data inconsistency errors such as:


2024-09-12T14:32:07.842Z ERROR [shard-rebalancer] Rebalance failed: 
    target_shard_id=shard-7b9c state=REBALANCING error=QuotaExceeded: 
    "Maximum concurrent rebalances (3) exceeded in region us-east-1"
2024-09-12T14:32:08.013Z WARN  [router] Query rejected: index=products-green 
    status=UNAVAILABLE reason="Shard rebalance in progress"

Symptoms observed by downstream services include:

  • HTTP 503 responses from the search API.
  • Stale or missing vectors when querying the green index.
  • Metrics showing pinecone_index_unavailable spikes.
  • CI/CD pipeline step “Switch Traffic” timing out.

Root Cause – Constrained Rebalance Quota and Inconsistent Replica Settings

Pinecone enforces a per‑region limit on the number of simultaneous shard rebalances. The limit defaults to three concurrent operations. During a blue‑green switch the deployment script creates a fresh index with the same replica_count as the blue index (e.g., 5 replicas per shard) and then issues a pinecone.update_index call that attempts to move all replicas at once. If the blue environment still has active queries, its shards are also undergoing internal maintenance (e.g., compaction). The combined load exceeds the quota, causing the control plane to abort the rebalance with a QuotaExceeded error.

Compounding the issue, the blue and green index configurations diverge in the metadata_config block. The blue index enables metadata_indexing=true while the green index omits it. Pinecone treats these as incompatible during a rebalance, aborting the operation after the quota check passes.

Debug – Step‑by‑Step Investigation

  1. Inspect index status via the Pinecone CLI.
    
    $ pinecone index describe products-blue
    {
      "name": "products-blue",
      "status": "READY",
      "shards": 12,
      "replicas_per_shard": 5,
      "metadata_config": {"indexed": true}
    }
    $ pinecone index describe products-green
    {
      "name": "products-green",
      "status": "REBALANCING",
      "shards": 12,
      "replicas_per_shard": 5,
      "metadata_config": {"indexed": false}
    }
    

    The mismatch in metadata_config is evident.

  2. Check the control‑plane quota.
    
    $ pinecone quota get --resource rebalance --region us-east-1
    {
      "limit": 3,
      "in_use": 3
    }
    

    All three slots are already occupied by background compaction jobs.

  3. Review CI/CD logs for the traffic‑switch stage.
    
    [2024-09-12 14:31:55] INFO  Initiating traffic switch to green
    [2024-09-12 14:31:58] INFO  Starting shard rebalance (12 shards)
    [2024-09-12 14:32:07] ERROR Rebalance failed: QuotaExceeded
    [2024-09-12 14:32:08] INFO  Rolling back traffic to blue
    

    The pipeline aborts after the first error, leaving the green index half‑rebuilt.

  4. Capture a packet trace of the control‑plane API call.
    
    $ tcpdump -i eth0 -w rebalance.pcap host api.pinecone.io and port 443
    

    Analysis of the capture shows a 429 HTTP response with body:

    
    {
      "error": "QuotaExceeded",
      "message": "Maximum concurrent rebalances (3) exceeded in region us-east-1"
    }
    

Solution – Controlled, Staged Rebalancing with Config Alignment

The fix consists of two coordinated changes:

  1. Synchronize index configurations. Ensure that the green index is created with the exact metadata_config and any other index‑level flags as the blue index.
  2. Throttle the rebalance operation. Instead of moving all replicas in a single API call, issue a series of incremental rebalance requests that respect the quota.

Implementation – Before / After

Before – Index creation script (faulty)


# create_green_index.py
import pinecone

pinecone.init(api_key="...", environment="us-east-1")

pinecone.create_index(
    name="products-green",
    dimension=1536,
    metric="cosine",
    shards=12,
    replicas=5,
    # metadata_config omitted – defaults to false
)

# Trigger full rebalance
pinecone.update_index(
    name="products-green",
    rebalancing={"mode": "full"}  # attempts to move all shards at once
)

After – Revised script with alignment and staged rebalance


# create_green_index.py (fixed)
import pinecone
import time

pinecone.init(api_key="...", environment="us-east-1")

# Pull configuration from the blue index to guarantee parity
blue_cfg = pinecone.describe_index("products-blue")
metadata_cfg = blue_cfg["metadata_config"]

pinecone.create_index(
    name="products-green",
    dimension=blue_cfg["dimension"],
    metric=blue_cfg["metric"],
    shards=blue_cfg["shards"],
    replicas=blue_cfg["replicas_per_shard"],
    metadata_config=metadata_cfg
)

# Wait for index to become READY
while True:
    status = pinecone.describe_index("products-green")["status"]
    if status == "READY":
        break
    time.sleep(5)

# Stage rebalance: move 4 shards at a time (max 3 concurrent + 1 buffer)
shard_batches = [list(range(i, i+4)) for i in range(0, 12, 4)]

for batch in shard_batches:
    pinecone.update_index(
        name="products-green",
        rebalancing={"shards": batch, "mode": "incremental"}
    )
    # Poll until batch completes
    while True:
        rebalance_status = pinecone.describe_index("products-green")["rebalance_status"]
        if rebalance_status == "IDLE":
            break
        time.sleep(10)

The script now:

  • Copies metadata_config from the blue index, eliminating incompatibility.
  • Splits the 12‑shard rebalance into three batches, keeping concurrent operations ≤2, well under the quota.
  • Polls for completion before proceeding, ensuring a deterministic state.

Verify – Confirming a Healthy Switch

  1. Check final index status.
    
    $ pinecone index describe products-green
    {
      "name": "products-green",
      "status": "READY",
      "shards": 12,
      "replicas_per_shard": 5,
      "metadata_config": {"indexed": true}
    }
    
  2. Run a sanity query against the green endpoint.
    
    $ curl -X POST https://products-green-abc123.svc.pinecone.io/query \
        -H "Api-Key: $PINECONE_API_KEY" \
        -d '{"vector": [0.12,0.34,...], "topK": 5}'
    {
      "matches": [...],
      "namespace": ""
    }
    
  3. Validate metrics. In Prometheus, confirm that pinecone_index_unavailable{index="products-green"} is zero for the last 5 minutes.
  4. Confirm traffic routing. Verify the load‑balancer or service‑mesh config now points 100 % of traffic to the green service.

Prevent – Operational Guardrails

  • Automated config parity check. Add a CI step that diffs the JSON output of pinecone.describe_index for blue and green before the switch.
  • Quota‑aware rebalance wrapper. Encapsulate update_index in a library that queries pinecone quota get and throttles requests accordingly.
  • Graceful traffic cut‑over. Use a canary phase (e.g., 5 % traffic) and monitor index_unavailable before full promotion.
  • Alert on rebalance failures. Create a Prometheus alert on the log pattern Rebalance failed with a severity of “critical”.
  • Scheduled maintenance windows. Perform the switch during low‑traffic periods to reduce concurrent background jobs that consume rebalance slots.

Related Topic Hub: Vector Databases Troubleshooting Hub

FAQ

  1. Why does the rebalance succeed in staging but fail in production? Production typically runs additional background jobs (e.g., compaction, snapshotting) that consume the rebalance quota. Staging environments have fewer active shards, leaving quota available.
  2. Can I increase the rebalance quota? The quota is a managed limit per Pinecone account tier. Contact Pinecone support to request a higher limit or upgrade to a tier that provides more concurrent rebalances.
  3. Is it safe to disable metadata indexing on the green index? Disabling it changes the index schema; existing queries that rely on metadata filters will return empty results, which appears as data loss. Align the flag across environments.
  4. What happens if a rebalance is interrupted mid‑switch? The index remains in a REBALANCING state and will reject queries. Rolling back traffic to the blue index restores availability, but any writes that occurred during the partial rebalance may be lost unless write‑through replication is enabled.
  5. How can I monitor the number of active rebalances? Use the Pinecone quota API:
    
    $ pinecone quota get --resource rebalance --region us-east-1
    

    Integrate this call into your deployment pipeline to abort or delay a switch when in_use >= limit.