/polymath-database:partitioning-shardingfrom polymath-database
Design table partitioning and shard keys — pruning, hot shards, cross-shard queries, resharding. Not whether to shard.
Ships in polymath-database. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
The partition key is the schema's most expensive decision: it fixes which queries are cheap, which are scatter-gather, and which shards run hot. Choose it from the access pattern, and plan how you'll change it.
Mode: analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked [TBD] or [VERIFY], never filled in.
polymath-database:db-scaling-strategy concluded sharding is required and you must pick the key, scheme, and routing.Not this when: you haven't established that partitioning/sharding is needed — polymath-database:db-scaling-strategy. Key-value/wide-column stores (DynamoDB, Cassandra, Cosmos) have their own model — polymath-database:nosql-partition-design.
A. Single-node partitioning (one database, many partitions)
DELETE), maintenance (smaller vacuum/index/backup units), or load spreading. If none apply, don't partition.WHERE, or pruning never fires.pg_partman, native ALTER TABLE … DETACH PARTITION [CONCURRENTLY], MySQL EXCHANGE PARTITION), a default partition or alert for out-of-range rows, and a runbook for backfills.B. Sharding (many databases/nodes)
polymath-architecture:distributed-consistency), never ad hoc two-phase commit without a clear owner. Global uniqueness needs a coordinated id scheme (ULID/snowflake, or a per-shard prefix) or a global lookup. Reference/dimension tables are replicated to every shard.polymath-backend:migration-plan.Partitioning/sharding design: ledger_entries (4.2 B rows, +30 M/day)
Stage A — partition (single node)
Purpose: retention + pruning. Key: posted_at, RANGE monthly (≈ 900 M rows/month → [VERIFY: check partition size vs RAM; consider weekly]).
PK becomes (id, posted_at) — unique id enforced via ULID generation; FK entries→accounts kept (account side unpartitioned).
Lifecycle: pg_partman pre-creates 3 months; detach+archive > 24 months; DEFAULT partition + alert on any row.
Expected: hot queries (account_id, posted_at range) prune to ≤ 2 partitions — confirm with EXPLAIN.
Stage B — shard (trigger: write ceiling inside 6 months, see db-scaling-strategy)
Key: account_id. Single-shard requests: 97% (transfers between accounts on different shards = 3% → saga with outbox).
Skew: top account = 0.8% of writes; no whale tenant [VERIFY: re-check quarterly].
Scheme: 1,024 logical shards (hash(account_id) mod 1024) → 8 nodes; directory table maps logical → node (cached 60 s).
Cross-shard: reporting via CDC → warehouse; global entry id = ULID; accounts/currencies tables replicated to all nodes.
Hot shard: per-shard dashboards; move logical shards between nodes online (logical replication + checksum + cutover).
Reshard: add nodes, move logical shards — no rehash. Rollback: keep source shard read-only 7 days.
Migration: shadow reads → dual write → per-account cutover flag → decommission. Owner: platform-db.
[VERIFY] until measured.hash(key) mod N with N physical nodes, making every resharding a full rewrite.user_id when the dominant access is by organization_id — every request fans out.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub mohammadbafkar/polymath --plugin polymath-databaseOther plugins' skills for the same job
8 skills in this plugin
/data-retention-archivingDesign retention and archiving — tiers, partition-drop purges, legal hold, deletion requests, restore tests — for DBs, event logs, lakes./db-io-tuningCut database IO — cache and working set, read/write amplification, WAL/fsync, checkpoints, bloat, volume IOPS limits. Not plans or indexes./db-performance-triageTriage a slow or saturated database top-down (workload, waits, plans, IO, locks, pools) to ONE bottleneck. Engine-agnostic; not one query plan.