Skip to content

Latest commit

 

History

History
58 lines (39 loc) · 1.88 KB

program.md

File metadata and controls

58 lines (39 loc) · 1.88 KB

AutoResearch: API Latency Optimization

Objective

Minimize average API response time (p50 latency) for the core endpoints under simulated load.

Target metric: avg_latency_ms (lower is better) Run command: npm run bench Time budget: 3 minutes per experiment

Editable Files

Only these files may be modified during experiments:

  • src/routes/api.js — Route handlers, query logic, response formatting
  • src/middleware/cache.js — Caching layer, TTL settings, cache key strategy
  • src/db/queries.js — Database queries, indexes, joins, projections

Locked Files (Do NOT Modify)

  • src/bench/ — Benchmark harness (the measurement tool)
  • src/models/ — Database schemas
  • package.json — Dependencies are locked

Evaluation

After each run, determine success by:

  1. The bench script outputs a JSON summary: { "avg_ms": N, "p95_ms": N, "p99_ms": N }
  2. Extract avg_ms as the target metric
  3. Also track p95 — if p95 regresses by >50ms while avg improves, discard

Minimum improvement threshold: 5ms average latency reduction Simplicity rule: Micro-optimizations under 2ms that add complexity are NOT worth it.

Constraints

  • Do NOT change API response shapes (breaking change)
  • Do NOT add new dependencies
  • Do NOT remove existing middleware (may be needed for auth/logging)
  • Cache TTLs must not exceed 5 minutes (data freshness requirement)

Strategy

What to Try (in rough priority order)

  1. Add database query indexes for frequently filtered fields
  2. Implement response caching for read-heavy endpoints
  3. Reduce N+1 queries with eager loading / joins
  4. Limit SELECT projections (don't fetch unused fields)
  5. Connection pooling tuning
  6. Response compression (gzip/brotli)

What to Avoid

  • Caching write endpoints (stale data risk)
  • Denormalizing the database schema (locked)
  • Adding Redis or external cache (no new deps)