big-tech-db-resilience
Universal database concurrency, production lock safety, and operational resilience standard.
Skill by hemanth17r
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/hemanth17r-big-tech-db-resilience
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: backend, writing
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md and code. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/big-tech-db-resilience
What's inside
- Skill name
big-tech-db-resilience- Description
- Universal database concurrency, production lock safety, and operational resilience standard. Codifies lock timeouts (preventing queue stalls during DDL), safe two-phase constraint validation (NOT VALID / VALIDATE), concurrent index building, race condition defenses (atomic guarded updates & optimistic concurrency control), partial index sizing, and runaway query circuit breakers (statement_timeout). Trigger when handling concurrent transactions, preventing race conditions, managing database locks, adding table constraints, or scaling under high write load.
- License
- MIT
- Instructions
- 142 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# Big-Tech Database Concurrency, Locks & Resilience Standard
## 1. The Core Philosophy: Real-World Production Traffic Physics
Databases do not fail on single queries; they fail under **concurrency, lock contention, and resource starvation**:
* An unconstrained DDL migration queues behind an analytics query, blocking all subsequent application reads and taking down production.
* Two users click "Claim" at the same millisecond, and naive code allows both to succeed (the double-spend bug).
* A slow table scan hangs for 40 seconds, exhausting connection pool workers and starving web traffic.
True engineering resilience means designing every transaction, lock, and schema change so it **fails gracefully, executes non-blockingly, and maintains absolute data integrity**.
---
## 2. Safe Production DDL: Lock Timeouts & Concurrent Indexing
In PostgreSQL and MySQL, schema modifications (`ALTER TABLE`) request an `Access Exclusive Lock`. If any query is currently reading that table, the migration waits in line—and **every subsequent application query queues behind it**, freezing the site.
### A. The Lock Timeout Mandate
Always prepend DDL migrations with a strict lock timeout:
```sql
-- Abort if lock cannot be acquired within 2 seconds
SET lock_timeout = '2s';
ALTER TABLE bounties ADD COLUMN sector_code VARCHAR(16);
```
* **Why**: If traffic is heavy, the migration fails fast and rolls back, leaving production running normally. The deploy pipeline can safely retry off-peak.
### B. Concurrent Index Building (Zero Write Locks)
Standard `CREATE INDEX` blocks all write operations until indexing finishes. In production, always build indexes concurrently:
```sql
-- Builds the index in background without locking table writes
CREATE INDEX CONCURRENTLY idx_bounties_sector ON bounties (sector_id);
```
---
## 3. Two-Phase Safe Constraint Validation (`NOT VALID`)
Adding a Foreign Key or `CHECK` constraint on a large table scans every existing row while holding an exclusive lock.
### The 2-Phase Non-Blocking Standard:
```sql
-- Step 1: Enforce on NEW writes only (Instant metadata lock, zero scan)
ALTER TABLE bounties
ADD CONSTRAINT fk_bounty_claimer
FOREIGN KEY (claimer_id) REFERENCES profiles(id)
NOT VALID;
-- Step 2: Validate HISTORICAL rows concurrently (Takes only ShareUpdateExclusiveLock, zero write lock)
ALTER TABLE bounties VALIDATE CONSTRAINT fk_bounty_claimer;
```
---
## 4. Race Condition Defenses (Double-Claim / Double-Spend)
Amateur code performs a read (`SELECT`), checks business logic in application memory (`if status === 'OPEN'`), and issues an update (`UPDATE`). Under concurrent traffic, multiple workers read the same state and execute the mutation simultaneously.
### Strategy A: Atomic Guarded Updates (Preferred)
Incorporate the state precondition directly into the SQL `WHERE` clause:
```sql
-- Atomically transitions state ONLY if precondition is still satisfied
UPDATE bounties
SET status = 'CLAIMED',
claimer_id = $1,
updated_at = NOW()
WHERE id = $2
AND status = 'OPEN'; -- Atomic lock guard
```
* Check the mutation result (`rowCount` / `affectedRows`). If `0`, another transaction won the race; return a clean conflict error immediately.
### Strategy B: Optimistic Concurrency Control (OCC with Versioning)
For complex domain models where state updates happen across multiple steps, maintain a monotonic `version` integer:
```sql
UPDATE wallets
SET balance = balance - $1,
version = version + 1,
updated_at = NOW()
WHERE id = $2
AND version = $expected_version
AND balance >= $1;
```
### Strategy C: Pessimistic Locking for Queues (`SKIP LOCKED`)
When workers claim tasks from a shared table, prevent worker collision without blocking concurrent throughput:
```sql
SELECT id, payload
FROM background_jobs
WHERE status = 'PENDING'
ORDER BY priority DESC, created_at ASC
LIMIT 1
FOR UPDATE SKIP LOCKED; -- Skips rows currently locked by other workers
```
---
## 5. Advanced Index Physics: Partial & Expression Indexes
### A. Partial Indexes (The 80% RAM Saver)
Never index inactive, soft-deleted, or terminal state rows if queries only search for active data:
```sql
-- Indexes ONLY active, non-deleted bounties
CREATE INDEX CONCURRENTLY idx_bounties_active_sector
ON bounties (sector_id, created_at DESC)
WHERE status = 'OPEN' AND deleted_at IS NULL;
```
* **Impact**: The index is 5× to 10× smaller, fits entirely in RAM cache, and accelerates search dramatically.
### B. Expression Indexes
If searching on transformed strings, standard B-trees will not trigger. Use functional expression indexes:
```sql
CREATE INDEX CONCURRENTLY idx_users_lower_email
ON users (LOWER(email));
```
---
## 6. Runaway Query Circuit Breakers (`statement_timeout`)From hemanth17r/ahr-workflow, MIT.
More from hemanth17r/ahr-workflow
- 0.645score
grounded-founder-outreach
hemanth17r
Generates personalized, grounded, high-conviction founder outreach messages and application notes across all platforms (Wellfound, Y Combinator Work at a…
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
idea-reality-check
hemanth17r
Conducts a ruthless prior-art investigation, package shortcut check, and competitive reality check on technical tools, packages, or architectural proposals…
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
adversarial-mechanism-design
hemanth17r
Universal mechanism design, reverse game theory, incentive engineering, and adversarial bad-actor defense standard for ANY product, platform, or marketplace.
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
big-tech-db-craft
hemanth17r
Universal database architecture and performance standard adapted from Big Tech for lean systems.
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
big-tech-product-ux
hemanth17r
Universal product design, cognitive psychology, microcopy economy, and UX architecture standard (Apple, Google, Stripe level).
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
big-tech-ui-craft
hemanth17r
Universal cognitive psychology and craftsmanship standard for high-conviction UI (Apple, Google, Linear, Stripe level).
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
blackbox-logic-flow-audit
hemanth17r
Universal programmatic black-box logic, wiring, and state flow verification standard across ANY software project.
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
autonomous-division-of-labor
hemanth17r
Enforces maximum agent ownership and strict division of labor for setups, installations, and multi-device workflows.
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
feynman-intuitive-explainer
hemanth17r
Translates complex technical jargon, engineering architecture, and mathematical concepts into crystal-clear, intuitive real-world analogies (The Feynman…
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
fluid-tactile-motion
hemanth17r
Universal spring motion physics, tactile micro-interactions, and optimistic UI architecture standard (Apple iOS, Linear, LinkedIn level).
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
ground-up-engineering-protocol
hemanth17r
Universal architectural standard for autonomous coding agents to build any software system from scratch.
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
interpretive-ui-craft
hemanth17r
Universal standard for self-explanatory, interpretive interfaces (Apple, Google App Launcher, Linear level).
SkillAFreshness: A★ 22Claude Code +9
Signals
- Stars
- 22
- Forks
- 4
- Open issues
- 0
- Last commit (this folder)
- Oct 19, 2026 (9 days ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/hemanth17r/ahr-workflow
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
Same skill elsewhere
Copies of this SKILL.md published by others; search shows only one of them.
More from hemanth17r
- 0.645score
adversarial-mechanism-design
hemanth17r
Universal mechanism design, reverse game theory, incentive engineering, and adversarial bad-actor defense standard for ANY product, platform, or marketplace.
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
big-tech-ui-craft
hemanth17r
Universal cognitive psychology and craftsmanship standard for high-conviction UI (Apple, Google, Linear, Stripe level).
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
autonomous-division-of-labor
hemanth17r
Enforces maximum agent ownership and strict division of labor for setups, installations, and multi-device workflows.
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
big-tech-db-craft
hemanth17r
Universal database architecture and performance standard adapted from Big Tech for lean systems.
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
big-tech-product-ux
hemanth17r
Universal product design, cognitive psychology, microcopy economy, and UX architecture standard (Apple, Google, Stripe level).
SkillAFreshness: A★ 22Claude Code +9 - 0.645score
blackbox-logic-flow-audit
hemanth17r
Universal programmatic black-box logic, wiring, and state flow verification standard across ANY software project.
SkillAFreshness: A★ 22Claude Code +9
Cite this page
big-tech-db-resilience skill. Agent Mart. https://agentmart.dev/skills/hemanth17r-big-tech-db-resilience (last updated 2026-10-24)