Token导航 LogoToken导航

Agent Skill · 前端设计

database-sharding(数据库分片)

用于辅助前端页面、组件、样式和交互逻辑的开发与维护。它适合让 Agent 生成或审查 React、Next.js、Vue、Tailwind、CSS 等相关代码,整理组件结构,或定位布局和性能问题。使用时需要结合项目现有设计系统、路由和构建方式,避免只生成孤立片段;涉及页面改动时,应配合本地预览和构建检查确认视觉效果。

database-sharding 是前端设计类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为只读;许可证为 MIT,第三方扫描已通过,按安装量在前端设计类的 10,216 个 Skill 里排第 1,822。

总安装 3,696周安装 151GitHub Stars 126下载 1,196核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
MIT

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:database-sharding(数据库分片)
来源仓库:https://github.com/secondsky/claude-skills
仓库路径:skills/database-sharding
安装命令:
npx skills add https://github.com/secondsky/claude-skills --skill database-sharding
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。不同来源提供的安装方式可能略有差异;本站展示可直接复制的安装命令,安装前请核对来源页面。

skills.shnpx skills
npx skills add https://github.com/secondsky/claude-skills --skill database-sharding

这个 Skill 是做什么的

前端设计类 Skill 关注页面结构、视觉规范和组件写法,输出通常是可运行的界面代码。

用于辅助前端页面与组件的开发与维护。database-sharding 属于前端设计类 Skill,可作为该场景下的辅助能力补充。适合生成 React、Vue 等框架代码或审查样式实现。使用时需结合项目路由结构和设计系统,避免孤立片段。页面改动后应通过本地预览确认布局和响应式表现。

建议配合构建命令检查编译错误和依赖兼容性。

来源仓库内路径:skills/database-sharding

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/secondsky/claude-skills --skill database-shard…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它标注为只读,先用只读任务试一次,确认行为符合预期再扩大使用范围。

常见问题

6 条

database-sharding 怎么安装?

在终端执行 npx skills add https://github.com/secondsky/claude-skills --skill database-sharding。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

database-sharding 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

database-sharding 需要什么权限?

权限级别是只读。该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

database-sharding 是免费的吗?

来源标注的许可证是 MIT。本站不代收任何费用,也不托管安装包;能否商用、要不要署名,以许可证原文为准。

database-sharding 用的人多吗?

公开数据是累计安装 3,696 次,近一周安装 151 次,下载 1,196 次,GitHub 126 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

database-sharding 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 3 个目录同时收录,说明这个 Skill 流传比较广。
  • 许可证明确为 MIT,商用和分发边界好判断。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理前端设计类任务、又不想每次都手写提示词的人。
  • 需要许可证清楚、并且有第三方扫描结果的团队项目。

不太适合

  • 需要厂商级技术支持和 SLA 的生产系统。

前端设计类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
frontend-design

前端设计 · Codex、Claude

8,823,360126,072只读MIT通过
vercel-composition-patterns

Vercel 组合模式 · Codex、Claude

3,858,81625,893需要联网MIT通过
vercel-react-native-skills

Vercel React native skills 前端 · Codex、Claude

2,468,66425,878只读MIT通过
adapt

adapt 搜索 · Codex、Claude

2,027,04023,125操作浏览器未明确通过
bolder

bolder 分析 · Codex、Claude

2,004,28823,130只读未明确通过
database-sharding

数据库分片 · 本页

3,696126只读MIT通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

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:

# 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:

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

RuleReason
Include shard key in queriesAvoid scanning all shards (100x slower)
Monitor shard distributionDetect hotspots before they cause outages
Plan for rebalancing upfrontCannot easily add shards later
Choose immutable shard keyChanging key = data migration nightmare
Test distribution with production dataSynthetic data hides real hotspots
Denormalize for data localityKeep related data on same shard

✗ Never Do

Anti-PatternWhy It's Bad
Sequential ID with range shardingLatest shard gets all writes (hotspot)
Timestamp as shard keyRecent shard overwhelmed
Cross-shard transactions without 2PCData corruption, inconsistency
Simple modulo without consistent hashingCannot add shards without full re-shard
Nullable shard keySpecial NULL handling creates hotspots
No shard routing layerHardcoded shards = cannot rebalance

Top 7 Critical Errors

Error 1: Wrong Shard Key Choice (Hotspots)

Symptom: One shard receives 80%+ of traffic Fix:

// ❌ Bad: Low cardinality (status field)
shard_key = order.status; // 90% are 'pending' → shard_0 overloaded

// ✅ Good: High cardinality (user_id)
shard_key = order.user_id; // Millions of users, even distribution

Error 2: Missing Shard Key in Queries

Symptom: Queries scan ALL shards (extremely slow) Fix:

// ❌ Bad: No shard key
SELECT * FROM orders WHERE status = 'shipped'; // Scans all 100 shards!

// ✅ Good: Include shard key
SELECT * FROM orders WHERE user_id = ? AND status = 'shipped'; // Targets 1 shard

Error 3: Sequential IDs with Range Sharding

Symptom: Latest shard gets all writes Fix:

// ❌ Bad: Range sharding with auto-increment
// Shard 0: 1-1M, Shard 1: 1M-2M, Shard 2: 2M+ → All new writes to Shard 2!

// ✅ Good: Hash-based sharding
const shardId = hash(id) % shardCount; // Even distribution

Error 4: No Rebalancing Strategy

Symptom: Stuck with initial shard count, cannot scale Fix:

// ❌ Bad: Simple modulo
const shardId = hash(key) % shardCount; // Adding 5th shard breaks ALL keys

// ✅ Good: Consistent hashing
const ring = new ConsistentHashRing(shards);
const shardId = ring.getNode(key); // Only ~25% of keys move when adding shard

Error 5: Cross-Shard Transactions

Symptom: Data inconsistency, partial writes Fix:

// ❌ Bad: Cross-shard transaction (will corrupt)
BEGIN;
UPDATE shard_1.accounts SET balance = balance - 100 WHERE id = 'A';
UPDATE shard_2.accounts SET balance = balance + 100 WHERE id = 'B';
COMMIT; // If shard_2 fails, shard_1 already committed!

// ✅ Good: Two-Phase Commit or Saga pattern
const txn = new TwoPhaseCommitTransaction();
txn.addOperation(shard_1, 'UPDATE accounts SET balance = balance - 100 WHERE id = ?', ['A']);
txn.addOperation(shard_2, 'UPDATE accounts SET balance = balance + 100 WHERE id = ?', ['B']);
await txn.execute(); // Atomic across shards

Error 6: Mutable Shard Key

Symptom: Records move shards, causing duplicates Fix:

// ❌ Bad: Shard by country (user relocates)
shard_key = user.country; // User moves US → CA, now in different shard!

// ✅ Good: Shard by immutable user_id
shard_key = user.id; // Never changes

Error 7: No Monitoring

Symptom: Silent hotspots, sudden performance degradation Fix:

// ✅ Required metrics
- Per-shard record counts (should be within 20%)
- Query distribution (no shard > 40% of queries)
- Storage per shard (alert at 80%)
- Latency p99 per shard

Load references/error-catalog.md for all 10 errors with detailed fixes.


Sharding Strategies

StrategyBest ForProsCons
HashUser data, even load criticalNo hotspots, predictableRange queries scatter
RangeTime-series, logs, append-onlyRange queries efficient, archivalRecent shard hotspot
DirectoryMulti-tenancy, complex routingFlexible, easy rebalancingLookup overhead, SPOF

Load references/sharding-strategies.md for detailed comparisons with production examples (Instagram, Discord, Salesforce).


Shard Key Selection Criteria

CriterionImportanceCheck Method
High cardinalityCriticalCOUNT(DISTINCT shard_key) > shard_count × 100
Even distributionCriticalNo value > 5% of total
ImmutableCriticalValue never changes
Query alignmentHigh80%+ queries include it
Data localityMediumRelated records together

Decision Tree:

  • User-focused app → user_id
  • Multi-tenant SaaS → tenant_id
  • Time-series/logs → timestamp (range sharding)
  • Product catalog → product_id

Load references/shard-key-selection.md for comprehensive decision trees and testing strategies.


Configuration Summary

Hash-Based Router

import { HashRouter } from './templates/hash-router';

const router = new HashRouter([
  { id: 'shard_0', connection: { /* PostgreSQL config */ } },
  { id: 'shard_1', connection: { /* PostgreSQL config */ } },
]);

// Automatically routes to correct shard
const user = await router.query('user_123', 'SELECT * FROM users WHERE id = $1', ['user_123']);

Range-Based Router

import { RangeRouter } from './templates/range-router';

const router = new RangeRouter(shardConfigs, [
  { start: Date.parse('2024-01-01'), end: Date.parse('2024-04-01'), shardId: 'shard_q1' },
  { start: Date.parse('2024-04-01'), end: Date.parse('2024-07-01'), shardId: 'shard_q2' },
  { start: Date.parse('2024-07-01'), end: Infinity, shardId: 'shard_q3' },
]);

// Range queries target specific shards
const janEvents = await router.queryRange(
  Date.parse('2024-01-01'),
  Date.parse('2024-02-01'),
  'SELECT * FROM events WHERE created_at BETWEEN $1 AND $2'
);

Directory-Based Router

import { DirectoryRouter } from './templates/directory-router';

const router = new DirectoryRouter(directoryDBConfig, shardConfigs);

// Assign tenant to specific shard
await router.assignShard('tenant_acme', 'shard_enterprise');

// Route automatically
const users = await router.query('tenant_acme', 'SELECT * FROM users');

When to Load References

Choosing Strategy

Load references/sharding-strategies.md when:

  • Deciding between hash, range, directory
  • Need production examples (Instagram, Discord)
  • Planning hybrid approaches

Selecting Shard Key

Load references/shard-key-selection.md when:

  • Choosing shard key for new project
  • Evaluating existing shard key
  • Testing distribution with production data

Implementation

Load references/implementation-patterns.md when:

  • Building shard router from scratch
  • Implementing consistent hashing
  • Need transaction handling (2PC, Saga)
  • Setting up monitoring/metrics

Cross-Shard Operations

Load references/cross-shard-queries.md when:

  • Need to aggregate across shards (COUNT, SUM, AVG)
  • Implementing cross-shard joins
  • Building pagination across shards
  • Optimizing scatter-gather patterns

Rebalancing

Load references/rebalancing-guide.md when:

  • Adding new shards
  • Migrating data between shards
  • Planning zero-downtime migrations
  • Balancing uneven load

Error Prevention

Load references/error-catalog.md when:

  • Troubleshooting performance issues
  • Reviewing shard architecture
  • All 10 documented errors with fixes

Complete Setup Checklist

Before Sharding:

  • Tested shard key distribution with production data
  • Shard key in 80%+ of queries
  • Monitoring infrastructure ready
  • Rebalancing strategy planned

Router Implementation:

  • Shard routing layer (not hardcoded shards)
  • Connection pooling per shard
  • Error handling and retries
  • Metrics collection (queries/shard, latency)

Shard Configuration:

  • 4-8 shards initially (room to grow)
  • Consistent hashing or virtual shards
  • Replicas per shard (HA)
  • Backup strategy per shard

Application Changes:

  • All queries include shard key
  • Cross-shard joins eliminated (denormalized)
  • Transaction boundaries respected
  • Connection pooling configured

Production Example

Before (Single database overwhelmed):

// Single PostgreSQL instance
const db = new Pool({ host: 'db.example.com' });

// All 10M users on one server
const users = await db.query('SELECT * FROM users WHERE status = $1', ['active']);
// Query time: 5000ms (slow!)
// DB CPU: 95%
// Disk: 500GB, growing

After (Sharded across 8 servers):

// Hash-based sharding with 8 shards
const router = new HashRouter([
  { id: 'shard_0', connection: { host: 'db0.example.com' } },
  { id: 'shard_1', connection: { host: 'db1.example.com' } },
  // ... 6 more shards
]);

// Query single user (targets 1 shard)
const user = await router.query('user_123', 'SELECT * FROM users WHERE id = $1', ['user_123']);
// Query time: 10ms (500x faster!)

// Query all shards (scatter-gather)
const allActive = await router.queryAll('SELECT * FROM users WHERE status = $1', ['active']);
// Query time: 800ms (parallelized across 8 shards, 6x faster than single)

// Result: Each shard handles ~1.25M users
// DB CPU per shard: 20%
// Disk per shard: 65GB
// Can scale to 16 shards easily (consistent hashing)

Known Issues Prevention

All 10 documented errors prevented:

  1. ✅ Wrong shard key (hotspots) → Test distribution first
  2. ✅ Missing shard key in queries → Code review, linting
  3. ✅ Cross-shard transactions → Use 2PC or Saga pattern
  4. ✅ Sequential ID hotspots → Use hash-based sharding
  5. ✅ No rebalancing strategy → Consistent hashing from day 1
  6. ✅ Timestamp sharding hotspots → Hybrid hash+range approach
  7. ✅ Mutable shard key → Choose immutable keys (user_id)
  8. ✅ No routing layer → Abstract with router from start
  9. ✅ No monitoring → Track per-shard metrics
  10. ✅ Weak hash function → Use MD5, MurmurHash3, xxHash

See: references/error-catalog.md for detailed fixes


Resources

Templates:

  • templates/hash-router.ts - Hash-based sharding
  • templates/range-router.ts - Range-based sharding
  • templates/directory-router.ts - Directory-based sharding
  • templates/cross-shard-aggregation.ts - Aggregation patterns

References:

  • references/sharding-strategies.md - Strategy comparison
  • references/shard-key-selection.md - Key selection guide
  • references/implementation-patterns.md - Router implementations
  • references/cross-shard-queries.md - Query patterns
  • references/rebalancing-guide.md - Migration strategies
  • references/error-catalog.md - All 10 errors documented

Production Examples:

  • Instagram: Range sharding for media
  • Discord: Hash sharding for messages
  • Salesforce: Directory sharding for orgs

Production-tested | 10 errors prevented | MIT License

平台分布

windsurf

52.05%
按下载量换算623

Cursor

28.68%
按下载量换算343

Codex

12.82%
按下载量换算153

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

只读

该 Skill 主要提供规则、说明或参考内容,本身偏只读;真正读写文件、联网或执行命令仍取决于宿主 Agent 的任务。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。

继续浏览同类 Skills