Episode 2 — React Frontend Architecture NextJS / 2.20 — Building APIs with NextJS

2.20.d — Response Shape & Error Handling

In one sentence: Pick a small, consistent JSON contract for successes and failures, map exceptions and validation errors to the right HTTP status, and never leak stack traces to untrusted clients.

Navigation: ← Databases · → 2.20 Overview


1. Why a Standard Envelope Matters

Without conventions, every endpoint invents its own shape:

{ "users": [] }
{ "data": [] }
{ "result": "success", "payload": [] }

Frontend code becomes a mess of special cases. Pick one pattern for your app or organization.


2. Success Envelope (Example Convention)

{
  "data": { "id": "usr_01", "email": "ada@example.com" },
  "meta": { "requestId": "req_9f3a" }
}

Collections:

{
  "data": [{ "id": "1" }, { "id": "2" }],
  "meta": { "page": 1, "pageSize": 20, "total": 125 }
}

Optional: links for pagination cursors (next, prev) if you use cursor-based paging.


3. Error Envelope (Example Convention)

{
  "error": {
    "code": "VALIDATION_FAILED",
    "message": "One or more fields are invalid",
    "details": [
      { "path": "email", "message": "Invalid email format" }
    ]
  },
  "meta": { "requestId": "req_9f3a" }
}

Principles:

  • code — stable machine string (EMAIL_IN_USE, UNAUTHORIZED).
  • message — safe for humans; not a stack trace.
  • details — optional field-level errors for forms.

This is spiritually similar to RFC 7807 Problem Details — adopt that standard verbatim if your API is public and long-lived.


4. Status Code Map (Copy This Table to Interview Notes)

SituationStatusNotes
Malformed JSON body400Body not parseable
Schema / field validation failed400 or 422Pick one; document it; 422 = semantics understood but input invalid
Missing or bad authentication401Not logged in / bad token
Authenticated but not allowed403Logged in, wrong role or ownership
Resource missing404Unknown id
Conflict (duplicate unique key)409Duplicate email
Optimistic concurrency failure409Version mismatch
Rate limited429Include Retry-After when possible
Server bug / DB down500Generic message externally; details in logs

5. Mapping Zod Errors to HTTP

import { ZodError, ZodSchema } from 'zod';
import { NextResponse } from 'next/server';

export function validationErrorResponse(error: ZodError) {
  return NextResponse.json(
    {
      error: {
        code: 'VALIDATION_FAILED',
        message: 'Invalid input',
        details: error.issues.map((i) => ({
          path: i.path.join('.'),
          message: i.message,
        })),
      },
    },
    { status: 422 },
  );
}

export async function parseBody<T>(request: Request, schema: ZodSchema<T>) {
  let json: unknown;
  try {
    json = await request.json();
  } catch {
    return { ok: false as const, response: NextResponse.json({ error: { code: 'INVALID_JSON' } }, { status: 400 }) };
  }
  const parsed = schema.safeParse(json);
  if (!parsed.success) {
    return { ok: false as const, response: validationErrorResponse(parsed.error) };
  }
  return { ok: true as const, data: parsed.data };
}

6. try/catch Around Services

export async function POST(request: Request) {
  const parsed = await parseBody(request, CreateUserSchema);
  if (!parsed.ok) return parsed.response;

  try {
    const user = await createUserService(parsed.data);
    return NextResponse.json({ data: user }, { status: 201 });
  } catch (e) {
    // Replace with your ORM’s duplicate-key detection helper
    if (e instanceof UniqueConstraintError) {
      return NextResponse.json(
        { error: { code: 'EMAIL_IN_USE', message: 'Email already registered' } },
        { status: 409 },
      );
    }
    console.error(e); // + real logger with request id
    return NextResponse.json(
      { error: { code: 'INTERNAL_ERROR', message: 'Something went wrong' } },
      { status: 500 },
    );
  }
}

Custom error classes (optional) let you avoid string-matching:

export class AppError extends Error {
  constructor(
    public status: number,
    public code: string,
    message: string,
  ) {
    super(message);
  }
}

7. Headers That Improve Debugging (Safely)

  • X-Request-Id — propagate from middleware or generate per request; include in logs; optionally echo in JSON meta.
  • Cache-Control: no-store for sensitive GET JSON.

8. HEAD and Conditional GET (Mention in Senior Interviews)

For heavy resources, ETag + If-None-Match can yield 304 Not Modified. Next.js Route Handlers can set ETag on Response headers — implement when profiling shows benefit.


9. What Not to Return

BadWhy
Raw error.message from DB driverMay leak schema/table names
Full Sequelize/Prisma error objectsToo much internal detail
Stack tracesAttackers learn file paths and versions

10. One “Senior” Sound Bite

“I keep Route Handlers thin: Zod-parse, authenticate, call services, map domain errors to typed HTTP codes with a stable JSON error shape, and log the real failure with a request id for support — the client never sees stack traces.”


Back to: 2.20 Overview · Next curriculum: 2.21 — Server Actions


Part 2 — Deep Encyclopedia (Responses & errors)

How to use this section: Read sequentially or jump by drill number. Each block has a scenario, a prompt (what an interviewer might ask), a model answer, and often a code sketch.

E001 — API drill 1: Idempotency-Key header for POST /api/payments.

Scenario: Idempotency-Key header for POST /api/payments. (variation 1: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #1.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #1, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E002 — API drill 2: Content-Type negotiation JSON vs msgpack.

Scenario: Content-Type negotiation JSON vs msgpack. (variation 2: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #2.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #2, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E003 — API drill 3: Binary upload > 4.5MB on serverless

Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 3: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #3.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #3, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E004 — API drill 4: HMAC webhook verification constant-time compare.

Scenario: HMAC webhook verification constant-time compare. (variation 4: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #4.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #4, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E005 — API drill 5: Rate limit by API key in Redis sliding window.

Scenario: Rate limit by API key in Redis sliding window. (variation 5: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #5.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #5, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E006 — API drill 6: OpenAPI generation from Zod schemas.

Scenario: OpenAPI generation from Zod schemas. (variation 6: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #6.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #6, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E007 — API drill 7: Versioned URL /api/v2 with sunset headers.

Scenario: Versioned URL /api/v2 with sunset headers. (variation 7: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #7.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #7, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E008 — API drill 8: HEAD request to check existence without body cost.

Scenario: HEAD request to check existence without body cost. (variation 8: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #8.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #8, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E009 — API drill 9: Conditional GET with ETag round trip.

Scenario: Conditional GET with ETag round trip. (variation 9: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #9.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #9, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E010 — API drill 10: CORS credentialed requests with wildcard mistake.

Scenario: CORS credentialed requests with wildcard mistake. (variation 10: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #10.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #10, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E011 — API drill 11: Idempotency-Key header for POST /api/payments.

Scenario: Idempotency-Key header for POST /api/payments. (variation 11: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #11.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #11, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E012 — API drill 12: Content-Type negotiation JSON vs msgpack.

Scenario: Content-Type negotiation JSON vs msgpack. (variation 12: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #12.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #12, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E013 — API drill 13: Binary upload > 4.5MB on serverless

Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 13: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #13.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #13, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E014 — API drill 14: HMAC webhook verification constant-time compare.

Scenario: HMAC webhook verification constant-time compare. (variation 14: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #14.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #14, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E015 — API drill 15: Rate limit by API key in Redis sliding window.

Scenario: Rate limit by API key in Redis sliding window. (variation 15: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #15.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #15, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E016 — API drill 16: OpenAPI generation from Zod schemas.

Scenario: OpenAPI generation from Zod schemas. (variation 16: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #16.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #16, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E017 — API drill 17: Versioned URL /api/v2 with sunset headers.

Scenario: Versioned URL /api/v2 with sunset headers. (variation 17: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #17.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #17, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E018 — API drill 18: HEAD request to check existence without body cost.

Scenario: HEAD request to check existence without body cost. (variation 18: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #18.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #18, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E019 — API drill 19: Conditional GET with ETag round trip.

Scenario: Conditional GET with ETag round trip. (variation 19: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #19.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #19, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E020 — API drill 20: CORS credentialed requests with wildcard mistake.

Scenario: CORS credentialed requests with wildcard mistake. (variation 20: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #20.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #20, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E021 — API drill 21: Idempotency-Key header for POST /api/payments.

Scenario: Idempotency-Key header for POST /api/payments. (variation 21: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #21.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #21, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E022 — API drill 22: Content-Type negotiation JSON vs msgpack.

Scenario: Content-Type negotiation JSON vs msgpack. (variation 22: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #22.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #22, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E023 — API drill 23: Binary upload > 4.5MB on serverless

Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 23: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #23.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #23, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E024 — API drill 24: HMAC webhook verification constant-time compare.

Scenario: HMAC webhook verification constant-time compare. (variation 24: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #24.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #24, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E025 — API drill 25: Rate limit by API key in Redis sliding window.

Scenario: Rate limit by API key in Redis sliding window. (variation 25: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #25.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #25, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E026 — API drill 26: OpenAPI generation from Zod schemas.

Scenario: OpenAPI generation from Zod schemas. (variation 26: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #26.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #26, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E027 — API drill 27: Versioned URL /api/v2 with sunset headers.

Scenario: Versioned URL /api/v2 with sunset headers. (variation 27: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #27.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #27, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E028 — API drill 28: HEAD request to check existence without body cost.

Scenario: HEAD request to check existence without body cost. (variation 28: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #28.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #28, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E029 — API drill 29: Conditional GET with ETag round trip.

Scenario: Conditional GET with ETag round trip. (variation 29: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #29.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #29, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E030 — API drill 30: CORS credentialed requests with wildcard mistake.

Scenario: CORS credentialed requests with wildcard mistake. (variation 30: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #30.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #30, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E031 — API drill 31: Idempotency-Key header for POST /api/payments.

Scenario: Idempotency-Key header for POST /api/payments. (variation 31: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #31.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #31, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E032 — API drill 32: Content-Type negotiation JSON vs msgpack.

Scenario: Content-Type negotiation JSON vs msgpack. (variation 32: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #32.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #32, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E033 — API drill 33: Binary upload > 4.5MB on serverless

Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 33: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #33.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #33, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E034 — API drill 34: HMAC webhook verification constant-time compare.

Scenario: HMAC webhook verification constant-time compare. (variation 34: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #34.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #34, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E035 — API drill 35: Rate limit by API key in Redis sliding window.

Scenario: Rate limit by API key in Redis sliding window. (variation 35: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #35.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #35, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E036 — API drill 36: OpenAPI generation from Zod schemas.

Scenario: OpenAPI generation from Zod schemas. (variation 36: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #36.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #36, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E037 — API drill 37: Versioned URL /api/v2 with sunset headers.

Scenario: Versioned URL /api/v2 with sunset headers. (variation 37: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #37.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #37, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E038 — API drill 38: HEAD request to check existence without body cost.

Scenario: HEAD request to check existence without body cost. (variation 38: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #38.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #38, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E039 — API drill 39: Conditional GET with ETag round trip.

Scenario: Conditional GET with ETag round trip. (variation 39: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #39.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #39, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E040 — API drill 40: CORS credentialed requests with wildcard mistake.

Scenario: CORS credentialed requests with wildcard mistake. (variation 40: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #40.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #40, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E041 — API drill 41: Idempotency-Key header for POST /api/payments.

Scenario: Idempotency-Key header for POST /api/payments. (variation 41: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #41.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #41, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E042 — API drill 42: Content-Type negotiation JSON vs msgpack.

Scenario: Content-Type negotiation JSON vs msgpack. (variation 42: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #42.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #42, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E043 — API drill 43: Binary upload > 4.5MB on serverless

Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 43: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #43.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #43, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E044 — API drill 44: HMAC webhook verification constant-time compare.

Scenario: HMAC webhook verification constant-time compare. (variation 44: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #44.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #44, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E045 — API drill 45: Rate limit by API key in Redis sliding window.

Scenario: Rate limit by API key in Redis sliding window. (variation 45: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #45.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #45, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E046 — API drill 46: OpenAPI generation from Zod schemas.

Scenario: OpenAPI generation from Zod schemas. (variation 46: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #46.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #46, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E047 — API drill 47: Versioned URL /api/v2 with sunset headers.

Scenario: Versioned URL /api/v2 with sunset headers. (variation 47: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #47.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #47, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E048 — API drill 48: HEAD request to check existence without body cost.

Scenario: HEAD request to check existence without body cost. (variation 48: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #48.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #48, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E049 — API drill 49: Conditional GET with ETag round trip.

Scenario: Conditional GET with ETag round trip. (variation 49: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #49.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #49, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E050 — API drill 50: CORS credentialed requests with wildcard mistake.

Scenario: CORS credentialed requests with wildcard mistake. (variation 50: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #50.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #50, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E051 — API drill 51: Idempotency-Key header for POST /api/payments.

Scenario: Idempotency-Key header for POST /api/payments. (variation 51: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #51.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #51, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E052 — API drill 52: Content-Type negotiation JSON vs msgpack.

Scenario: Content-Type negotiation JSON vs msgpack. (variation 52: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #52.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #52, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E053 — API drill 53: Binary upload > 4.5MB on serverless

Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 53: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #53.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #53, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E054 — API drill 54: HMAC webhook verification constant-time compare.

Scenario: HMAC webhook verification constant-time compare. (variation 54: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #54.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #54, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E055 — API drill 55: Rate limit by API key in Redis sliding window.

Scenario: Rate limit by API key in Redis sliding window. (variation 55: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #55.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #55, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E056 — API drill 56: OpenAPI generation from Zod schemas.

Scenario: OpenAPI generation from Zod schemas. (variation 56: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #56.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #56, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E057 — API drill 57: Versioned URL /api/v2 with sunset headers.

Scenario: Versioned URL /api/v2 with sunset headers. (variation 57: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #57.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #57, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E058 — API drill 58: HEAD request to check existence without body cost.

Scenario: HEAD request to check existence without body cost. (variation 58: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #58.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #58, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E059 — API drill 59: Conditional GET with ETag round trip.

Scenario: Conditional GET with ETag round trip. (variation 59: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #59.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #59, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E060 — API drill 60: CORS credentialed requests with wildcard mistake.

Scenario: CORS credentialed requests with wildcard mistake. (variation 60: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #60.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #60, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E061 — API drill 61: Idempotency-Key header for POST /api/payments.

Scenario: Idempotency-Key header for POST /api/payments. (variation 61: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #61.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #61, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E062 — API drill 62: Content-Type negotiation JSON vs msgpack.

Scenario: Content-Type negotiation JSON vs msgpack. (variation 62: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #62.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #62, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E063 — API drill 63: Binary upload > 4.5MB on serverless

Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 63: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #63.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #63, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E064 — API drill 64: HMAC webhook verification constant-time compare.

Scenario: HMAC webhook verification constant-time compare. (variation 64: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #64.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #64, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E065 — API drill 65: Rate limit by API key in Redis sliding window.

Scenario: Rate limit by API key in Redis sliding window. (variation 65: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #65.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #65, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E066 — API drill 66: OpenAPI generation from Zod schemas.

Scenario: OpenAPI generation from Zod schemas. (variation 66: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #66.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #66, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E067 — API drill 67: Versioned URL /api/v2 with sunset headers.

Scenario: Versioned URL /api/v2 with sunset headers. (variation 67: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #67.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #67, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E068 — API drill 68: HEAD request to check existence without body cost.

Scenario: HEAD request to check existence without body cost. (variation 68: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #68.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #68, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E069 — API drill 69: Conditional GET with ETag round trip.

Scenario: Conditional GET with ETag round trip. (variation 69: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #69.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #69, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E070 — API drill 70: CORS credentialed requests with wildcard mistake.

Scenario: CORS credentialed requests with wildcard mistake. (variation 70: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #70.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #70, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E071 — API drill 71: Idempotency-Key header for POST /api/payments.

Scenario: Idempotency-Key header for POST /api/payments. (variation 71: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #71.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #71, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E072 — API drill 72: Content-Type negotiation JSON vs msgpack.

Scenario: Content-Type negotiation JSON vs msgpack. (variation 72: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #72.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #72, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E073 — API drill 73: Binary upload > 4.5MB on serverless

Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 73: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #73.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #73, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E074 — API drill 74: HMAC webhook verification constant-time compare.

Scenario: HMAC webhook verification constant-time compare. (variation 74: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #74.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #74, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E075 — API drill 75: Rate limit by API key in Redis sliding window.

Scenario: Rate limit by API key in Redis sliding window. (variation 75: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #75.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #75, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E076 — API drill 76: OpenAPI generation from Zod schemas.

Scenario: OpenAPI generation from Zod schemas. (variation 76: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #76.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #76, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E077 — API drill 77: Versioned URL /api/v2 with sunset headers.

Scenario: Versioned URL /api/v2 with sunset headers. (variation 77: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #77.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #77, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E078 — API drill 78: HEAD request to check existence without body cost.

Scenario: HEAD request to check existence without body cost. (variation 78: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #78.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #78, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E079 — API drill 79: Conditional GET with ETag round trip.

Scenario: Conditional GET with ETag round trip. (variation 79: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #79.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #79, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E080 — API drill 80: CORS credentialed requests with wildcard mistake.

Scenario: CORS credentialed requests with wildcard mistake. (variation 80: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #80.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #80, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E081 — API drill 81: Idempotency-Key header for POST /api/payments.

Scenario: Idempotency-Key header for POST /api/payments. (variation 81: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #81.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #81, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E082 — API drill 82: Content-Type negotiation JSON vs msgpack.

Scenario: Content-Type negotiation JSON vs msgpack. (variation 82: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #82.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #82, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E083 — API drill 83: Binary upload > 4.5MB on serverless

Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 83: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #83.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #83, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E084 — API drill 84: HMAC webhook verification constant-time compare.

Scenario: HMAC webhook verification constant-time compare. (variation 84: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #84.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #84, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E085 — API drill 85: Rate limit by API key in Redis sliding window.

Scenario: Rate limit by API key in Redis sliding window. (variation 85: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #85.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #85, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E086 — API drill 86: OpenAPI generation from Zod schemas.

Scenario: OpenAPI generation from Zod schemas. (variation 86: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #86.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #86, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E087 — API drill 87: Versioned URL /api/v2 with sunset headers.

Scenario: Versioned URL /api/v2 with sunset headers. (variation 87: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #87.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #87, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E088 — API drill 88: HEAD request to check existence without body cost.

Scenario: HEAD request to check existence without body cost. (variation 88: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #88.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #88, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E089 — API drill 89: Conditional GET with ETag round trip.

Scenario: Conditional GET with ETag round trip. (variation 89: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #89.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #89, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E090 — API drill 90: CORS credentialed requests with wildcard mistake.

Scenario: CORS credentialed requests with wildcard mistake. (variation 90: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #90.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #90, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E091 — API drill 91: Idempotency-Key header for POST /api/payments.

Scenario: Idempotency-Key header for POST /api/payments. (variation 91: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #91.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #91, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E092 — API drill 92: Content-Type negotiation JSON vs msgpack.

Scenario: Content-Type negotiation JSON vs msgpack. (variation 92: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #92.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #92, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E093 — API drill 93: Binary upload > 4.5MB on serverless

Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 93: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #93.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #93, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E094 — API drill 94: HMAC webhook verification constant-time compare.

Scenario: HMAC webhook verification constant-time compare. (variation 94: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #94.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #94, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E095 — API drill 95: Rate limit by API key in Redis sliding window.

Scenario: Rate limit by API key in Redis sliding window. (variation 95: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #95.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #95, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E096 — API drill 96: OpenAPI generation from Zod schemas.

Scenario: OpenAPI generation from Zod schemas. (variation 96: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #96.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #96, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E097 — API drill 97: Versioned URL /api/v2 with sunset headers.

Scenario: Versioned URL /api/v2 with sunset headers. (variation 97: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #97.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #97, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E098 — API drill 98: HEAD request to check existence without body cost.

Scenario: HEAD request to check existence without body cost. (variation 98: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #98.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #98, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E099 — API drill 99: Conditional GET with ETag round trip.

Scenario: Conditional GET with ETag round trip. (variation 99: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #99.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #99, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E100 — API drill 100: CORS credentialed requests with wildcard mistake.

Scenario: CORS credentialed requests with wildcard mistake. (variation 100: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #100.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #100, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E101 — API drill 101: Idempotency-Key header for POST /api/payments.

Scenario: Idempotency-Key header for POST /api/payments. (variation 101: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #101.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #101, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E102 — API drill 102: Content-Type negotiation JSON vs msgpack.

Scenario: Content-Type negotiation JSON vs msgpack. (variation 102: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #102.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #102, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E103 — API drill 103: Binary upload > 4.5MB on serverless

Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 103: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #103.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #103, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E104 — API drill 104: HMAC webhook verification constant-time compare.

Scenario: HMAC webhook verification constant-time compare. (variation 104: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #104.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #104, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E105 — API drill 105: Rate limit by API key in Redis sliding window.

Scenario: Rate limit by API key in Redis sliding window. (variation 105: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #105.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #105, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E106 — API drill 106: OpenAPI generation from Zod schemas.

Scenario: OpenAPI generation from Zod schemas. (variation 106: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #106.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #106, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E107 — API drill 107: Versioned URL /api/v2 with sunset headers.

Scenario: Versioned URL /api/v2 with sunset headers. (variation 107: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #107.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #107, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E108 — API drill 108: HEAD request to check existence without body cost.

Scenario: HEAD request to check existence without body cost. (variation 108: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #108.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #108, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E109 — API drill 109: Conditional GET with ETag round trip.

Scenario: Conditional GET with ETag round trip. (variation 109: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #109.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #109, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}

E110 — API drill 110: CORS credentialed requests with wildcard mistake.

Scenario: CORS credentialed requests with wildcard mistake. (variation 110: consider deployment on a serverless platform with regional databases.)

Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #110.

Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #110, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.

import { NextResponse } from 'next/server';

export async function POST(req: Request) {
  const idem = req.headers.get('idempotency-key');
  // store idem -> response mapping in Redis with TTL
  return NextResponse.json({ ok: true });
}