Backend API and Database Implementation
Build backend APIs, schemas, authentication, and safe migrations with concrete code, concurrency safeguards, and focused tests.
Before & after
Same prompt, same agent — the only difference is the skill.
A 4-second endpoint usually points to a database issue. Here are the common culprits: - **N+1 queries**: Loading related records in a loop instead of a single join - **Missing indexes**: Check if your WHERE and JOIN columns are indexed - **Over-fetching**: Selecting columns you don't need - **No pagination**: Returning thousands of rows at once - **Synchronous external calls**: Blocking on third-party APIs I'd start by adding query logging to see how many queries the endpoint fires and how long each takes. Running EXPLAIN ANALYZE on the slow ones will show whether indexes are being used. Can you share the endpoint code?
Measure before changing anything — four seconds has one dominant cause and
guessing costs more than instrumenting.
STEP 1 — WHERE THE TIME GOES
Log query count + duration for one request. Three shapes, three fixes:
Many fast queries (50+ under 5ms) → N+1
One slow query (3s+) → missing index or bad plan
Few queries, still slow → it's not the DB. External call
or serialization.
STEP 2 — IF IT'S THE QUERY
EXPLAIN (ANALYZE, BUFFERS) SELECT ...
Read it in this order:
Seq Scan on a big table → missing index
rows= estimate far off actual → stale stats, run ANALYZE
Nested Loop over many rows → planner chose wrong, usually stats
high shared read= vs hit= → not cached, may be an I/O problem
Index for the actual predicate, composite in the order the query
filters:
CREATE INDEX CONCURRENTLY idx_orders_user_created
ON orders (user_id, created_at DESC);
CONCURRENTLY matters — a plain CREATE INDEX takes a write lock and
turns your slow endpoint into a down endpoint.
STEP 3 — IF IT'S N+1
Eager-load the relation. In an ORM that's one include; hand-rolled,
it's one IN query plus a map. Confirm the query count actually
dropped rather than assuming.
STEP 4 — IF IT'S NOT THE DB
External call → move it off the request path or set an aggressive
timeout with a fallback. A 4s p50 usually means a 30s p99 and no
timeout at all.
Serialization → check payload size before optimizing anything. 2MB of
JSON is 2 seconds regardless of how fast the query was.
Paste EXPLAIN output and I'll read the plan.About this skill
Your endpoint works until requests overlap, the query slows down, or a deployment changes the schema underneath running code. This skill turns backend requests into concrete implementations with explicit authorization, database invariants, and deployment steps.
What it does
- Designs REST contracts with bounded pagination, predictable errors, and retry-safe writes.
- Implements authentication and resource-level authorization without trusting client-supplied ownership fields.
- Diagnoses PostgreSQL queries from execution plans before proposing indexes or infrastructure changes.
- Handles concurrent writes with constraints, conditional updates, transactions, and idempotency records.
- Plans database changes that remain compatible while old and new application versions overlap.
- Evaluates service boundaries, message delivery, and failure handling when microservices are justified.
What you get
Working code or an implementation-ready patch, with the API contract, schema changes, focused tests, and rollout steps needed for the requested scope. Reviews identify concrete failure cases and corrections; performance recommendations distinguish measured results from hypotheses.
Best for
Developers building or maintaining database-backed services, particularly Node.js APIs and PostgreSQL applications, who need help moving from a plausible design to behavior that holds under concurrent requests and deployment changes.
SKILL.md preview
---
name: backend-api-and-database-implementation
description: Designs and implements backend APIs, database changes, authentication, and service integrations by tracing authorization, data invariants, concurrent requests, and deployment compatibility through working code. Use when the user says "build a REST API", "my endpoint keeps creating duplicates", "this PostgreSQL query is slow", "implement authentication", "review this backend code", "make this migration safe", "split this into microservices", or "load test this API".
---
# Backend API and Database Implementation
… (sign up to view the full skill)More development skills
View all Development skills →Production Go: Concurrency, Services & Profiling
Production Go code with leak-free goroutines, context-correct services, wrapped errors, and pprof-driven performance fixes.
Backend Feature Build Plan
Builds one backend feature through gates: confirmed requirements, one-screen design, small tested slices, and a deploy/rollback handoff.
Consistent, Safe Application Logging
Adds structured, correlated logs with useful severity, safe fields, bounded volume, and targeted verification.
Reliable WebSocket Messaging and Scaling
Build WebSocket and Socket.IO systems with authorized rooms, reconnect recovery, bounded queues, and multi-node presence.