This handles horizontal database partitioning when you've outgrown a single server or need geographic distribution. It covers the main sharding strategies: range-based (split by ID ranges), hash-based (distribute via consistent hashing), and directory-based (lookup table routing). You get practical SQL examples for defining shards with constraint checks and routing logic. The approach is solid for multi-tenant isolation or when read/write throughput becomes your bottleneck. One thing to note is that cross-shard queries get messy fast, so pick your shard key carefully upfront. The reference guides break down each strategy separately, which helps when you're trying to decide between them based on your access patterns.

skills.sh installs
446
GitHub stars
379
last updated
Aug 21, 2026

Install

$ npx -y skills add aj-geddes/useful-ai-prompts --skill database-sharding --agent claude-code

Installs into .claude/skills of the current project.

Files

Database Sharding

Table of Contents

Overview

Implement horizontal data partitioning across multiple database servers. Covers sharding strategies, consistent hashing, shard key selection, and cross-shard querying patterns.

When to Use

  • Database size exceeds single server capacity
  • Read/write throughput needs horizontal scaling
  • Geographic data distribution requirements
  • Multi-tenant data isolation
  • Cost optimization through distributed architecture
  • Load balancing across database instances

Quick Start

Minimal working example:

-- Define shard ranges
-- Shard 0: user_id 0-999999
-- Shard 1: user_id 1000000-1999999
-- Shard 2: user_id 2000000-2999999

CREATE TABLE users_shard_0 (
  id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
  user_id BIGINT NOT NULL,
  email VARCHAR(255) NOT NULL,
  created_at TIMESTAMP DEFAULT NOW(),
  CONSTRAINT shard_0_range CHECK (user_id BETWEEN 0 AND 999999)
);

Sponsors

Details

Repository
github.com/aj-geddes/useful-ai-prompts
Categories
Backend & APIs, AI & Agent Building, Databases
First seen
Jun 3, 2026

More from aj-geddes/useful-ai-prompts

All 258
1bobmatnyc avatarhono-middlewarebobmatnyc/claude-mpm-skillsHono middleware patterns - creation, composition, built-in middleware, and execution order for web applications444skills.sh installs
2sickn33 avatardatabase-optimizersickn33/antigravity-awesome-skillsdatabase optimizer436skills.sh installs
3trading212-labs avatartrading212-apitrading212-labs/agent-skillstrading212 api433skills.sh installs
4bobmatnyc avatargolang-database-patternsbobmatnyc/claude-mpm-skillsGo database integration patterns using sqlx, pgx, and migration tools like golang-migrate414skills.sh installs
5sickn33 avatardatabase-migrationsickn33/antigravity-awesome-skillsdatabase migration398skills.sh installs
6kernel avatarkernel-authkernel/skillsUse Kernel managed auth whenever an agent needs to do something on a website as a logged-in user, including browsing, operating, automating, testing, debugging,397skills.sh installs