Database Sharding

Database Sharding

Guides an AI agent to implement database sharding for horizontal scaling, covering hash, range and directory strategies, shard keys and cross-shard queries.

Skill files6 files

references/

scripts/

templates/

SKILL.md89 lines
1
---
2
name: database-sharding
3
description: >
4
Implement database sharding for horizontal scalability. Use when scaling large
5
databases, distributing data across multiple servers, or designing sharded
6
architectures.
7
---
8
9
# Database Sharding
10
11
## Table of Contents
12
13
- [Overview](#overview)
14
- [When to Use](#when-to-use)
15
- [Quick Start](#quick-start)
16
- [Reference Guides](#reference-guides)
17
- [Best Practices](#best-practices)
18
19
## Overview
20
21
Implement horizontal data partitioning across multiple database servers. Covers sharding strategies, consistent hashing, shard key selection, and cross-shard querying patterns.
22
23
## When to Use
24
25
- Database size exceeds single server capacity
26
- Read/write throughput needs horizontal scaling
27
- Geographic data distribution requirements
28
- Multi-tenant data isolation
29
- Cost optimization through distributed architecture
30
- Load balancing across database instances
31
32
## Quick Start
33
34
Minimal working example:
35
36
```sql
37
-- Define shard ranges
38
-- Shard 0: user_id 0-999999
39
-- Shard 1: user_id 1000000-1999999
40
-- Shard 2: user_id 2000000-2999999
41
42
CREATE TABLE users_shard_0 (
43
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
44
user_id BIGINT NOT NULL,
45
email VARCHAR(255) NOT NULL,
46
created_at TIMESTAMP DEFAULT NOW(),
47
CONSTRAINT shard_0_range CHECK (user_id BETWEEN 0 AND 999999)
48
);
49
50
CREATE TABLE users_shard_1 (
51
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
52
user_id BIGINT NOT NULL,
53
email VARCHAR(255) NOT NULL,
54
created_at TIMESTAMP DEFAULT NOW(),
55
CONSTRAINT shard_1_range CHECK (user_id BETWEEN 1000000 AND 1999999)
56
);
57
58
-- Function to determine shard
59
CREATE OR REPLACE FUNCTION get_shard_id(p_user_id BIGINT)
60
RETURNS INT AS $$
61
BEGIN
62
// ... (see reference guides for full implementation)
63
```
64
65
## Reference Guides
66
67
Detailed implementations in the `references/` directory:
68
69
| Guide | Contents |
70
|---|---|
71
| [Range-Based Sharding](references/range-based-sharding.md) | Range-Based Sharding |
72
| [Hash-Based Sharding](references/hash-based-sharding.md) | Hash-Based Sharding |
73
| [Directory-Based Sharding](references/directory-based-sharding.md) | Directory-Based Sharding |
74
75
## Best Practices
76
77
### ✅ DO
78
79
- Follow established patterns and conventions
80
- Write clean, maintainable code
81
- Add appropriate documentation
82
- Test thoroughly before deploying
83
84
### ❌ DON'T
85
86
- Skip testing or validation
87
- Ignore error handling
88
- Hard-code configuration values
89

© AJ Geddes · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…