One-click install
npx skills add https://github.com/secondsky/claude-skills --skill database-sharding
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: database-sharding
Source: https://github.com/secondsky/claude-skills/tree/main/plugins/database-sharding/skills/database-sharding
Command: npx skills add https://github.com/secondsky/claude-skills --skill database-sharding

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides comprehensive database sharding patterns for PostgreSQL/MySQL, enabling horizontal scaling, multi-tenant isolation, and handling billions of records with hash, range, and directory strategies. It reduces complexity by offering concrete routing and governance rules for shard keys, queries, and rebalancing.

Core Features & Use Cases

  • Hash-based sharding for even distribution across shards
  • Range-based sharding for time-series or sequential data
  • Directory-based sharding for multi-tenant or tenant-specific routing
  • Clear guidance on shard key selection, distribution, and immutability
  • Patterns and templates for building shard routers and rebalancing strategies

Quick Start

  1. Pick a sharding strategy template (hash, range, or directory) and implement a router for your keys.
  2. Identify shard keys with high cardinality and immutability; design a router that targets a single shard when possible.
  3. Plan for rebalancing with consistent hashing or directory routing to minimize data movement.

Frequently Asked Questions about database-sharding

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I partition a PostgreSQL or MySQL database across multiple servers?

Database sharding partitions data horizontally across multiple database instances using a shard key. Hash, range, or directory-based strategies distribute records to specific shards, enabling horizontal scaling for billions of records while maintaining query isolation per shard.

What makes a good shard key for consistent hashing?

A shard key must have high cardinality, remain immutable after insertion, and route single queries to one shard when possible. Consistent hashing minimizes data reshuffling during rebalancing, reducing migration overhead and maintaining even distribution across shards.

Can I run cross-shard queries without downtime?

Cross-shard queries require routing logic that targets multiple shards and aggregates results. Two-phase commit or saga patterns handle distributed transactions, though latency increases. Dual-write migration strategies enable zero-downtime rebalancing when reshuffling data between shards.

How do I prevent SQL injection when sharding across tenants?

Input validation on shard identifiers and strict parameterized queries prevent injection attacks in multi-tenant deployments. Directory-based sharding isolates tenant data by routing requests through validated shard keys before query execution.

What's the difference between hash and range sharding?

Hash sharding distributes keys evenly across shards using consistent hashing, ideal for uniform load. Range sharding partitions sequential or time-series data by value ranges, simplifying range queries but requiring hotspot mitigation and manual rebalancing.

How do I monitor shard health and detect imbalanced data distribution?

Robust monitoring tracks per-shard record counts, query latency, and storage distribution to identify hotspots. Rebalancing strategies redistribute data when skew exceeds thresholds, maintaining performance and preventing single-shard bottlenecks.