big-tech-db-craft
Universal database architecture and performance standard adapted from Big Tech for lean systems. Codifies the 4-phase Expand/Contract zero-downtime migration…
от hemanth17r★ 33 звезды на GitHub
Установить big-tech-db-craft в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Big-Tech Database Craft & Performance Standard
1. The Core Philosophy: The 5 Laws of Data Systems
A high-performance database layer obeys 5 mechanical laws regardless of scale:
- Never break active code during a schema change (Zero-downtime Expand/Contract).
- Never query fields you aren't rendering (Projection restraint).
- Never let pagination degrade as tables grow (Keyset over Offset).
- Never let foreign keys or multi-column queries trigger full table scans (Defensive indexing).
- Never mutate related state outside atomic boundaries (Transactions & Idempotency).
2. Law 1: The Expand/Contract (Parallel Run) Migration Pattern
Synchronous migrations that rename columns, change data types, or add non-null constraints will lock tables or break running application instances.
The 4-Phase Zero-Downtime Lifecycle:
[1. EXPAND] ──────────► [2. DUAL-WRITE] ────────► [3. BACKFILL] ────────► [4. CONTRACT]
Add nullable column. Write to both cols; Sync historical rows Drop old column
App keeps running. read from old. and switch reads. from database.
- Phase 1 (Expand): Add the new column as
NULLABLE(or with a safe default). Running servers continue operating on the old column without interruption:ALTER TABLE users ADD COLUMN full_name TEXT; - Phase 2 (Dual-Write): Deploy an application update that writes to both
nameandfull_name, but continues reading fromname. - Phase 3 (Backfill & Switch Read):
- Run background backfill:
UPDATE users SET full_name = name WHERE full_name IS NULL; - Once synced, deploy code switching application reads exclusively to
full_name.
- Run background backfill:
- Phase 4 (Contract): Verify zero code references
name, then drop the legacy column:ALTER TABLE users DROP COLUMN name;
3. Law 2: Query Projection Restraint & Zero $N+1$ Loops
Treating the database like an unconstrained storage bucket causes memory pressure and network saturation.
A. Strict Column Projections (Ban SELECT *)
- ❌ Amateur:
SELECT * FROM bounties WHERE sector_id = $1;(Pulls massive JSONB metadata, descriptions, and audit logs over the wire). - ✅ Big-Tech Standard: Explicitly project only the fields needed for the active view:
SELECT id, title, reward_amount, status, created_at FROM bounties WHERE sector_id = $1;
B. Eliminate $N+1$ Query Loops
- ❌ Amateur: Querying parent items, then running a separate database call inside a loop for each child item.
- ✅ Big-Tech Standard: Use single batched queries with
IN (...), relationalJOIN, or array containment (ANY):const userIds = users.map(u => u.id); const profiles = await db.query( 'SELECT user_id, display_name, avatar_url FROM profiles WHERE user_id = ANY($1)', [userIds] );
4. Law 3: Keyset (Cursor) Pagination Over Offset Scans
OFFSET 10000 LIMIT 20 forces the database engine into an $O(N)$ table scan, walking through 10,000 dead rows before returning 20.
The Keyset Standard ($O(1)$)
Seek directly to the last-seen record using a composite index on (created_at, id):
SELECT id, title, reward_amount, created_at
FROM bounties
WHERE (created_at, id) < ($1, $2)
ORDER BY created_at DESC, id DESC
LIMIT 20;
- Performance: Directly jumps to the index pointer in $O(\log N)$ and scans exactly 20 rows. Query response time stays identical at 100 rows or 10,000,000 rows.
5. Law 4: Defensive Indexing Physics
A. The Foreign Key Index Mandate
Every foreign key column (user_id, organization_id, bounty_id) must have an explicit B-tree index. Unindexed foreign keys cause table locks during deletes and catastrophic table scans during joins.
B. Composite Index Order: "Equality Before Range"
When a query filters by multiple columns, place equality columns first and range/sort columns second:
$$\text{Index Declaration Order: } (\text{Equality Column}, \text{Range / Sort Column})$$
- Query:
WHERE account_id = $1 AND created_at >= $2 ORDER BY created_at DESC - ❌ Ineffective:
CREATE INDEX idx ON transactions(created_at, account_id); - ✅ Effective:
CREATE INDEX idx ON transactions(account_id, created_at DESC);
6. Law 5: Atomic Transactions & Idempotency
A. Atomic Mutation Scope
Wrap multi-table state changes inside explicit transaction blocks so failures automatically roll back:
BEGIN;
UPDATE balances SET amount = amount - 100 WHERE account_id = 'A';
UPDATE balances SET amount = amount + 100 WHERE account_id = 'B';
INSERT INTO transfer_logs (from_id, to_id, amount) VALUES ('A', 'B', 100);
COMMIT;
B. Idempotent Upserts (ON CONFLICT)
Avoid SELECT-then-INSERT race conditions. Use atomic native upserts:
INSERT INTO user_preferences (user_id, theme, notifications)
VALUES ($1, $2, $3)
ON CONFLICT (user_id)
DO UPDATE SET
theme =
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл big-tech-db-craft?
Universal database architecture and performance standard adapted from Big Tech for lean systems. Codifies the 4-phase Expand/Contract zero-downtime migration lifecycle, query projection restraint, keyset cursor pagination over offset scans, defensive indexing (equality before range), and atomic transaction boundaries. Trigger when designing schemas, writing migrations, optimizing queries, creating indexes, building database models, or when the task involves "create a table", "add a column", "new migration", "schema change", "alter table", "database index", or "query optimization".
Как установить скилл big-tech-db-craft?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл big-tech-db-craft запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…