Debugging & Incident Analysis
Target: Claude 3.7, Cursor, Windsurf, ChatGPT

API Performance Regression & N+1 Query Debugger

Identify slow database queries, serialization bottlenecks, and memory churn in sluggish API endpoints.

PerformanceSQLNode.jsJavaBackendAPM

Interactive Prompt Playground

Customize Template Fields
Live replacement
{{ENDPOINT_CODE}}
{{P99_LATENCY}}
{{QUERY_COUNT}}
{{APM_TRACE}}
Rendered Prompt (Ready to paste)1752 characters
You are a Performance Engineering Lead and APM specialist.

Diagnose and optimize this slow API endpoint:

API Endpoint Code:
```
async function getOrganizationProjects(orgId) {
  const org = await db.organizations.findById(orgId);
  const projects = await db.projects.find({ orgId: org.id });
  
  const result = [];
  for (const project of projects) {
    const tasks = await db.tasks.find({ projectId: project.id });
    const members = await db.members.find({ projectId: project.id });
    result.push({ ...project, taskCount: tasks.length, memberCount: members.length });
  }
  return result;
}
```

Performance Profile / Tracing Data:
- P99 Latency: 2,400ms under 50 req/sec load
- Database Query Count: 1 + 2N (approx 120 SQL queries per request)
- APM Trace / Query Log:
```
SELECT * FROM organizations WHERE id = 'org_123'; (4ms)
SELECT * FROM projects WHERE org_id = 'org_123'; (12ms)
SELECT * FROM tasks WHERE project_id = 'prj_1'; (18ms)
SELECT * FROM members WHERE project_id = 'prj_1'; (15ms)
-- ... repeated 60 times for each project
```

Analyze the bottleneck systematically:
1. **Bottleneck Decomposition**:
   - Identify whether the bottleneck is I/O-bound (database queries, network calls), CPU-bound (serialization, loops), or memory-bound.
   - Point out exact N+1 queries, unbatched API calls, or redundant data transfers.
2. **Query & Data Access Optimization**:
   - Provide optimized SQL joins, batch queries (`IN (...)`), or eager load configurations to reduce query count from O(N) to O(1).
3. **Caching & Asynchronous Strategies**:
   - Suggest caching layers (Redis, in-memory memoization) with cache invalidation policies.
4. **Refactored Code**:
   - Provide the fully optimized, high-throughput endpoint implementation.

How to Use This Prompt

  1. Paste your slow endpoint code and APM trace data.
  2. Specify your latency numbers and query counts.
  3. Get a high-performance batch-loaded refactor with benchmark estimates.

Engineering Tips & Best Practices

  • Use SQL aggregation functions (COUNT, JSON_AGG) to perform computations directly in the database engine.

What This Prompt Inspects

Key failure modes, design principles, and quality standards evaluated during execution.

N+1 Elimination

Replaces iterative database queries with single aggregated GROUP BY joins.

Payload Trimming

Selects only required columns rather than pulling heavy blob/json fields into memory.

Connection Pool Sizing

Analyzes DB connection pressure during peak traffic.

SprintKit Workflow Integrations

Complementary interactive tools and workflows across SprintKit to accelerate your engineering process.

Related Prompts

Explore related developer prompts in this workflow domain.

All Prompts

Database Schema & Relational Indexing Strategy

Design production PostgreSQL schemas with composite indexes, foreign key strategies, and partitioning.

PostgreSQLSQLDatabaseIndexing+1
4 variablesCustomize prompt

Production Exception & Stack Trace Root-Cause Analyzer

Analyze production stack traces, error logs, and surrounding code using hypothesis-driven debugging.

DebuggingObservabilityLogsIncidents+1
4 variablesCustomize prompt

Spring Boot REST Service & JPA Code Review

Deep code review for Spring Boot services examining transaction boundaries, JPA N+1 queries, concurrency, and validation.

JavaSpring BootJPAHibernate+2
4 variablesCustomize prompt