APIprompt onlyIntermediate

API Performance Budget

A coding loop focused on optimizing API performance to ensure P95 latency stays under a defined target threshold. This loop iteratively runs load tests, analyzes bottlenecks, and implements optimizations until the goal is achieved or maximum iterations are reached.

← all loops
performancelatencyapiload-testingoptimizationk6

Goal

Keep API latency within target

How to Run

Run this loop in any supported coding agent environment to continuously optimize API endpoints based on real-time load testing feedback.

  1. 01

    Initialize Environment

    Ensure api-load.js script exists with proper k6 load test configuration targeting the API endpoints.

  2. 02

    Start Loop Execution

    Execute the loop by prompting the agent to begin performance optimization cycles using k6 load testing.

  3. 03

    Monitor Exit Condition

    Allow the agent to iterate up to 10 times, automatically checking if P95 latency meets the target after each optimization.

Workflow Steps

  1. 01

    Run load test

    if P95 latency >= target

  2. 02

    Analyze performance metrics and identify bottlenecks

    after step 1

  3. 03

    Implement performance optimizations

    after step 2

  4. 04

    Re-run load test

    after step 3

  5. 05

    Check P95 against target and decide exit or repeat

    if iterations < 10 and P95 >= target

  6. 06

    Exit loop successfully

    if P95 < target

  7. 07

    Exit loop after max iterations

    if iterations >= 10 and P95 still >= target

Kickoff Prompt

Start the "API Performance Budget" loop.

Goal: Keep API latency within target
Max iterations: 10
Between iterations run: k6 run api-load.js
Exit when: P95 latency below target


Optimize the API to meet the P95 latency target defined in the load test script. Run iterative optimizations until the target is achieved or 10 iterations are completed.

Self-pace this loop. After each iteration, run `k6 run api-load.js` and evaluate the output, and only continue if the exit condition is not met (P95 latency below target). Stop when the exit condition passes or 10 iterations are reached. Give a short status update each pass.

Guardrails

hardcoded
  • ·Do not modify database schemas or external services during optimization.
  • ·Optimize only using standard library features and documented best practices.
  • ·Ensure all changes are covered by existing or new unit/integration tests.
  • ·Maintain original API functionality and contract compliance.
  • ·Limit iterations to prevent infinite optimization loops.

Flow Diagram

rendering…

Related loops — API