Back to cookbook

AI Prompt to Write a Load Testing Plan for a REST API Endpoint

0 views Published

Make this prompt yours

Share

This prompt has ChatGPT, Claude, or Gemini draft a concrete load testing plan for a REST API endpoint before you run a single test. It's for backend engineers and SREs who need to validate an endpoint can handle expected traffic, usually ahead of a product launch, a marketing push, or a seasonal spike, without spending a day figuring out what to even measure.

Rather than a generic "test your API under load" answer, the prompt forces specifics: what traffic shape to simulate (steady-state versus a spike), which metrics actually indicate trouble (p95/p99 latency, error rate, saturation of a downstream dependency) versus which are vanity numbers, and what the pass/fail thresholds are before the test starts. It also asks the model to call out which parts of the system, like a database connection pool or a rate limiter, are most likely to be the real bottleneck rather than the endpoint's own code.

If the endpoint you're testing also calls out to internal services through tool-based integrations, running the resulting plan through Prompt Optimizer in Coding mode can help tighten the technical constraints before you hand it to a model to generate the actual test scripts.

Prompt template

Make this prompt yours

prompt-template
313 tokens
You are a performance engineer designing a load test for a production API endpoint. Context: - Endpoint: [METHOD AND PATH, e.g. POST /api/v1/orders] - Expected traffic: [REQUESTS PER SECOND AT PEAK, e.g. 150 rps average, 600 rps peak] - Downstream dependencies: [LIST, e.g. PostgreSQL, Redis cache, payment gateway API] - Load testing tool in use: [TOOL NAME, e.g. k6, Locust, JMeter] - Current known constraints: [e.g. database connection pool size, rate limiter config] Write a load testing plan with the following requirements: 1. Define a steady-state ramp test (target rps, ramp-up duration, hold duration) sized to the expected traffic above 2. Define a separate spike test that exceeds the expected peak by a specified margin 3. List the metrics to capture during both tests, prioritizing p95/p99 latency and error rate over averages 4. Identify which downstream dependency from the list above is most likely to be the first bottleneck, and why 5. Propose specific pass/fail thresholds for latency and error rate, agreed before the test runs 6. Note any test environment differences from production that could invalidate the results Output format: - A short test plan summary (one paragraph) - The steady-state and spike test parameters as a table - The metrics and thresholds as a table - A short risk note on the likely first bottleneck and the environment caveat

Want it sharper? Optimize this prompt with Prompt Optimizer, check it with the Prompt Debugger or shorten it with the Token Optimizer.

Example input

example-input
84 tokens
Endpoint: POST /api/v1/orders Expected traffic: 150 rps average, 600 rps peak during a planned sale Downstream dependencies: PostgreSQL (orders table), Redis cache for inventory counts, Stripe payment API Load testing tool in use: k6 Current known constraints: database connection pool capped at 100 connections Write the load testing plan described in the system instructions using these details.

When to use it

  • You're preparing an endpoint for a known traffic event, such as a product launch, sale, or marketing campaign
  • A new feature adds a heavier query or external call to an existing endpoint and you need to confirm it still holds up under current load
  • You've had an incident where an endpoint degraded under load and want a repeatable test to confirm a fix actually worked
  • You need documented, agreed-upon pass/fail thresholds before a stakeholder will sign off on a launch date

Best practices

  • Give the model your actual expected traffic numbers (requests per second, peak-to-average ratio) instead of asking it to "test under high load," since the plan should be sized to reality, not guesswork
  • Name every downstream dependency the endpoint touches (database, cache, third-party API) so the model can flag which one is likely to saturate first
  • Ask for both a steady-state ramp test and a spike test, since many endpoints that handle sustained load fail differently under a sudden burst
  • Set pass/fail thresholds (like p99 latency under 500ms, error rate under 0.1%) before the test runs, not after you see the results and decide what looks acceptable

Common mistakes

  • Only testing the happy path at the target load, without also testing what happens as load exceeds capacity, which is often when the real failure mode shows up
  • Measuring only average latency, which hides the p95/p99 tail latency that actually affects a meaningful share of real users
  • Running the load test against a staging environment with a different (usually smaller) database or cache than production, producing numbers that don't transfer
  • Treating the load test as a one-time gate before launch instead of a repeatable script that reruns after every change to the endpoint or its dependencies

FAQs

What metrics actually matter for an API load test?

p95 and p99 latency and the error rate under load matter far more than average latency, since the average hides the slower requests that real users actually notice. Resource saturation on a specific dependency, like a database connection pool, is often the real early-warning signal.

What's the difference between a steady-state load test and a spike test?

A steady-state test holds a constant target rps for an extended period to confirm sustained capacity, while a spike test applies a sudden burst well above the expected peak to see how the system behaves when load arrives faster than it can absorb it, which is a different failure mode.

Why does my load test pass in staging but the system still struggles in production?

This usually means the staging environment's dependencies, like the database or cache, are smaller or configured differently than production, so the test never actually exercised the bottleneck that exists at production scale.

What tool can help me refine this prompt for a specific API or framework?

Prompt Optimizer — its Coding mode is built for tightening technical prompts like this one before you hand them to a model to generate the actual test scripts.

Found this prompt useful? Share it.

Share

More in Engineering

Engineering

AI Prompt to Write a Feature Flag Rollout and Cleanup Plan

A feature flag rollout plan lays out how a new capability ships behind a flag, moves through stages of exposure, and eventually gets removed…

You are a senior platform engineer helping plan a feature flag rollout.

Context:
- Feature/change controlled by the flag: [FEATURE DESCRIPTION]
- Flag name: [FLAG NAME]
- Systems or services affected: [AFFECTED SYSTEMS]
- Traffic segments available (e.g. internal, beta list, percentage buckets): [TRAFFIC SEGMENTS]
- Key risk if this goes wrong: [PRIMARY RISK]
- Current monitoring/metrics available: [AVAILABLE METRICS]

Task:
1. Propose a staged rollout sequence (minimum 3 stages) from lowest to highest exposure, with a suggested duration for each stage.
2. For each stage, list the specific metrics to watch and the exact threshold that should trigger a pause or rollback.
3. Define who should approve advancing to the next stage.
4. Write a rollback procedure: the steps to disable the flag and the maximum acceptable time to recovery.
5. Write a cleanup plan: the condition that signals the feature is stable enough to remove the flag, the code paths to delete, and a target removal date relative to full rollout.

Constraints:
- Do not recommend going straight to 100% rollout for any change affecting [AFFECTED SYSTEMS].
- Keep each stage's exit criteria measurable, not subjective.
- Flag any step that depends on information not provided above.

Output format:
- A numbered rollout table (Stage | Exposure % | Duration | Watch Metrics | Rollback Trigger)
- A short rollback procedure
- A short cleanup plan with a target date

Make this prompt yours

Engineering

AI Prompt to Diagnose and Fix Slow Database Queries

This AI prompt helps you diagnose and fix slow database queries by walking through the execution plan, indexing, and query structure instead…

You are a senior database engineer specializing in query performance tuning.

Context:
- Database engine and version: [e.g., PostgreSQL 15, MySQL 8]
- The slow query: [PASTE THE SQL QUERY]
- Execution plan output: [PASTE EXPLAIN / EXPLAIN ANALYZE OUTPUT]
- Relevant table schemas, including existing indexes: [PASTE SCHEMA]
- Approximate row counts for each table involved: [ROW COUNTS]
- How slow it currently runs vs. your target: [CURRENT TIME] vs [TARGET TIME]

Instructions:
1. Identify the most likely cause(s) of the slowness from the execution plan, ranked by probable impact.
2. For each cause, explain in plain language what's happening (for example, "full table scan because no index covers this WHERE clause").
3. Propose the smallest change that would fix the top cause first, before any structural changes.
4. Provide the rewritten query or the exact index definition (CREATE INDEX statement) to test.
5. Note any trade-off the fix introduces, such as added write overhead from a new index.

Constraints:
- Do not suggest denormalizing the schema unless indexing and query rewrites are insufficient.
- Keep the explanation grounded in the specific execution plan provided, not generic query-optimization advice.

Output format:
Return the answer as: Likely Causes (ranked), Recommended Fix, SQL/Index to Test, Trade-offs.

Make this prompt yours

Engineering

AI Prompt to Design a Caching Strategy for a High-Traffic API Endpoint

This prompt asks ChatGPT, Claude, or Gemini to design a caching strategy for a high traffic API endpoint , covering where to cache (client,…

ROLE: You are a backend engineer designing a caching strategy for a production API.

CONTEXT:
- Endpoint: [DESCRIBE THE ENDPOINT, e.g. "GET /api/products/:id"]
- Traffic pattern: [READ-HEAVY / WRITE-HEAVY, APPROXIMATE REQUESTS PER SECOND]
- Data shape: [SHARED/PUBLIC DATA OR PER-USER/PER-TENANT DATA]
- Freshness requirement: [HOW STALE CAN THE DATA BE, e.g. "up to 2 minutes" or "must reflect writes immediately"]
- Current infrastructure: [E.G. "Redis available", "CDN in front of API", "no caching layer yet"]

TASK:
1. Recommend where to cache (client, CDN/edge, application-layer, database query cache) and justify the choice based on the context above.
2. Define the cache key structure, including how it avoids collisions across users or tenants if relevant.
3. Specify the TTL and, separately, the invalidation triggers (e.g. invalidate on write, pub/sub cache bust).
4. Call out at least two failure modes specific to this design (e.g. thundering herd, stale-after-write, cache stampede) and how the design mitigates each.
5. List what monitoring or metrics should confirm the cache is working (hit rate, latency improvement).

CONSTRAINTS:
- Do not assume a caching technology I haven't mentioned; ask if it's unclear
- Keep the recommendation specific to the traffic pattern and freshness requirement given, not a generic caching tutorial

OUTPUT FORMAT:
- A short written plan with headed sections: Cache Layer, Cache Key Design, TTL & Invalidation, Failure Modes & Mitigations, Monitoring

REQUEST:
[DESCRIBE YOUR SPECIFIC ENDPOINT AND SITUATION HERE]

Make this prompt yours