database-sharding

Solid

Database sharding for PostgreSQL/MySQL with hash/range/directory strategies. Use for horizontal scaling, multi-tenant isolation, billions of records, or encountering wrong shard keys, hotspots, cross-shard transactions, rebalancing issues.

API & Backend 168 stars 27 forks Updated 4 weeks ago MIT

Install

View on GitHub

Quality Score: 89/100

Stars 20%
74
Recency 20%
90
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# database-sharding Comprehensive database sharding patterns for horizontal scaling with hash, range, and directory-based strategies. --- ## Quick Start (10 Minutes) **Step 1**: Choose sharding strategy from templates: ```bash # Hash-based (even distribution) cat templates/hash-router.ts # Range-based (time-series data) cat templates/range-router.ts # Directory-based (multi-tenancy) cat templates/directory-router.ts ``` **Step 2**: Select shard key criteria: - ✅ **High cardinality** (millions of unique values) - ✅ **Even distribution** (no single value > 5%) - ✅ **Immutable** (never changes) - ✅ **Query alignment** (in 80%+ of WHERE clauses) **Step 3**: Implement router: ```typescript import { HashRouter } from './hash-router'; const router = new HashRouter([ { id: 'shard_0', connection: { host: 'db0.example.com' } }, { id: 'shard_1', connection: { host: 'db1.example.com' } }, { id: 'shard_2', connection: { host: 'db2.example.com' } }, { id: 'shard_3', connection: { host: 'db3.example.com' } }, ]); // Query single shard const user = await router.query('user_123', 'SELECT * FROM users WHERE id = $1', ['user_123']); ``` --- ## Critical Rules ### ✓ Always Do | Rule | Reason | |------|--------| | **Include shard key in queries** | Avoid scanning all shards (100x slower) | | **Monitor shard distribution** | Detect hotspots before they cause outages | | **Plan for rebalancing upfront** | Cannot easily add shards later | | **Choose immutable shard key** | Chang...

Details

Author
secondsky
Repository
secondsky/claude-skills
Created
7 months ago
Last Updated
4 weeks ago
Language
TypeScript
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category