backend-db-discipline
Backend and database performance discipline. Prevents N+1 queries, unbounded tables, missing indexes, and resource leaks.
- License 许可
- MIT
- 最近更新
- 2026-10-29
- Stars
- ★ 3
- Forks
- 0
01 前言 Front Matter
- name
- backend-db-discipline
- description
- Backend and database performance discipline. Prevents N+1 queries, unbounded tables, missing indexes, and resource leaks.
03 SKILL.md 正文
Backend & Database Performance Discipline
Fast and robust backends come from disciplined data access patterns, not afterthought optimizations. Enforce these backend and database guardrails across all API and persistence layers.
1. Anti N+1 Query Elimination
- FORBIDDEN: Executing database queries inside loops or mapping over arrays (e.g.
items.map(async item => await db.user.find(...))). - Always use:
- Relation eager loading (
include,select_related,prefetch_related). - Batching /
DataLoaderpatterns for GraphQL or distributed resolvers. - SQL
JOINs orWHERE id IN (...)queries to fetch related entities in a single round-trip.
- Relation eager loading (
2. Unbounded Query Prevention (Pagination by Default)
- FORBIDDEN: Fetching full tables without limits (e.g.,
SELECT * FROM ordersor unbounded.findMany()). - Any collection endpoint or query that can grow over time must implement pagination (cursor-based preferred, or offset with a hard limit like
limit = min(req.limit, 100)). - Select only the specific fields needed by the view or consumer; avoid returning massive columns (like raw JSON blobs or text bodies) when only an ID or summary is needed.
3. Indexing & Schema Guardrails
- Ensure every column queried in
WHERE,ORDER BY,GROUP BY, orJOIN ONhas a supporting index. - Foreign key columns must always be indexed to prevent table scans during cascading operations and joins.
- Create explicit migration files whenever adding or modifying database tables, columns, or indexes.
4. Transactional Integrity & Idempotency
- Multi-step write operations that depend on each other must be wrapped in atomic transactions (e.g.,
db.$transaction,BEGIN...COMMIT). - Roll back immediately on error; never leave the database in a partially-updated state.
- Critical operations (payment processing, order creation, state transitions) must support idempotency (e.g., idempotency keys or unique constraint handling).
5. Connection & Resource Lifecycle Management
- Always release or close database connections, file handles, streams, and network sockets in
finallyblocks, context managers (with), or automated resource scopes. - Prevent connection pool exhaustion by keeping transaction durations as short as possible. Do not perform slow network calls or heavy CPU work inside an open database transaction.
04 同仓库更多 Skills
writing-shape
Writing, exploit: shape raw material into an article, paragraph by paragraph.
writing-fragments
Writing, explore: mine raw fragments, no structure yet.
writing-for-agents
Writing documents for agents. Use when creating or editing skills, or modifying AGENTS.md or CLAUDE.md.
writing-beats
Writing, exploit; assemble raw material into a journey of beats, grounding each term before a beat leans on it.
wizard
Generate an interactive bash wizard that walks a human through steps only they can perform. Use when provisioning infrastructure, setting up credentials or CI secrets, walking an unfamiliar third-party dashboard, or running a one-off migration or cutover. Don't invoke this for steps the agent can perform itself.
wayfinder
Plan a huge chunk of work (more than one agent session can hold) as a shared map of decision tickets on your issue tracker, and resolve them one at a time until the way to the destination is clear.