This hands-on exercise shows how to detect a hot-shard condition and apply targeted remediation. You’ll practice traffic routing, metric inspection, and corrective actions such as adjusting routing weights, scaling, or reassigning shard ranges.
- Route follower traffic to the shard cluster to reproduce a hot-shard scenario.
- Monitor shard metrics (request rate, latency, CPU/memory) to identify the hot shard.
- Apply fixes to redistribute traffic and reduce overload on the hot shard.
- Validate that the cluster returns to balanced traffic distribution.
Step-by-step guide
- Route follower traffic to the shard cluster
- Purpose: Direct follower requests so they hit the shard layer. This lets you reproduce imbalanced traffic patterns.
- How to do it:
- Update your router / gateway to send follower traffic to the shard cluster. This is typically a configuration change in your control plane or ingress (e.g., altering weights, endpoint lists, or route rules).
- Example (conceptual placeholder — adapt to your control plane):
- Update route weight:
POST /api/routes/<route-id>/weightswith payload to setshard-clusterweight to1.0.
- Update route weight:
- If you use Kubernetes Services and want to target a specific shard for testing, update the Endpoints object or point a test client directly to
http://<shard-ip>:<port>.
- Generate load to reproduce the hot shard
- Purpose: Create traffic to cause one shard to become overloaded so you can observe symptoms.
- Example commands:
- Using a simple loop:
- Using
fortio(recommended for realistic load): - Replace
<follower-endpoint>with your test endpoint.
- Using a simple loop:
- Observe and identify the hot shard
- What to watch (Prometheus/Grafana queries):
- Request rate by shard:
- 95th percentile latency by shard:
- CPU usage (per pod):
- Request rate by shard:
- Quick
kubectlchecks:- List pods and status:
- Resource usage (metrics-server):
- List pods and status:
- Symptom mapping:
You will make live changes to routing or shard assignments. Validate changes in a staging environment first if possible. Roll back quickly if error rates increase or user impact grows.
- Apply fixes to rebalance traffic Choose one or more actions depending on diagnostics:
-
Adjust routing weights (preferred quick fix)
- Reduce weight to the hot shard and increase weight to other shards.
- Example conceptual API call:
- Verify the new distribution quickly using request-rate metrics.
-
Scale the overloaded shard
- If the shard is CPU-bound, scale replicas or increase resources:
- If the shard is CPU-bound, scale replicas or increase resources:
-
Reassign shard ranges (reshard)
- If the root cause is uneven key distribution, move some key ranges from the hot shard to others.
- Reshard steps typically include:
- Pause writes to affected ranges (if your system requires it).
- Move key ranges or update shard metadata in the control plane.
- Drain and re-route traffic for moved ranges.
- Exact commands depend on your sharding system — follow your platform’s resharding procedure.
-
Evict or restart unhealthy instances
- If a pod has degraded performance but is not resource-limited, restart it:
- If a pod has degraded performance but is not resource-limited, restart it:
- Validate remediation
- Confirm request rate and latency have evened out:
- Re-run the Prometheus queries from step 3 and confirm no single shard dominates traffic.
- Confirm resource usage normalized:
- Check error rates dropped:
- If you adjusted routing weights, validate routing config is persisted and that the control plane has applied the new weights.
- Record the root cause (routing config, key distribution, insufficient capacity).
- Capture the exact remediation steps and timestamps.
- Consider long-term mitigations:
- Improve hashing or shard key selection.
- Add autoscaling rules for shard replicas.
- Implement more granular routing or a circuit breaker for hot shards.
- Kubernetes Documentation
- Prometheus Querying Basics
- Grafana Dashboards
- Service Mesh / Router docs (Envoy/Traefik/NGINX)