Episode 2 — React Frontend Architecture NextJS / 2.20 — Building APIs with NextJS
2.20.c — Connecting APIs to Databases
In one sentence: Route Handlers are thin HTTP adapters — they parse and authorize the request, call a service that uses your ORM or driver, and map results to HTTP; database connection strategy must match serverless vs long-lived deployment.
Navigation: ← HTTP Methods · Next → Responses & Errors
1. Layering: Never Let route.ts Become a 400-Line God File
HTTP (route.ts)
↓ validate input (Zod)
↓ authn / authz (session, API key)
↓
Service (services/users.ts) ← business rules
↓
Repository / ORM (db/users.ts)
↓
Database
Why: Same service functions can be reused from Server Actions, Route Handlers, cron scripts, and tests without duplicating SQL.
2. Environment Variables
// Never commit secrets
const uri = process.env.DATABASE_URL;
if (!uri) {
throw new Error('DATABASE_URL is not set');
}
- Use
.env.localfor development (gitignored). - In production, inject via Vercel/hosting dashboard or your orchestrator.
Route Handlers can read process.env — values without NEXT_PUBLIC_ stay server-only.
3. Node vs Edge Runtime (Interview Landmine)
Route Handlers default to Node.js in typical App Router setups. You can opt into Edge:
export const runtime = 'edge';
Edge constraints (high level):
- No full TCP to arbitrary databases from some platforms — Prisma and others may need Data Proxy / serverless driver / HTTP-based DB access.
- No Node-only APIs (
fsfor local disk, some native modules).
Practical interview answer: “I default database Route Handlers to Node unless I have a clear edge + supported driver story. I verify ORM compatibility before moving DB access to edge.”
4. Serverless Connection Pattern (Conceptual)
Serverless functions can spin up many concurrent instances. Naively opening one new DB connection per request exhausts the database.
Patterns:
| Stack | Approach |
|---|---|
| Prisma | Use Prisma’s Data Proxy / connection pooling product, or deploy with a pooler (PgBouncer) URL |
| MongoDB + Mongoose | Cached global client in development; serverless-friendly connect helpers that reuse globalThis in dev; production MongoDB Atlas + pooling |
Postgres pg | Pooler endpoint, small max per instance, avoid storing huge pools in global unless you understand your host |
Anti-pattern:
// Bad: new connection every request at high QPS
export async function GET() {
const client = new SomeDriver.Client();
await client.connect();
// ...
}
Better: Centralize connection acquisition in lib/db.ts with reuse semantics documented for your hosting provider.
5. Example Shape: Mongoose-Style (Familiar from Episode 3)
// lib/db.ts (illustrative — tune to your provider’s official recipe)
import mongoose from 'mongoose';
const MONGODB_URI = process.env.MONGODB_URI!;
export async function dbConnect() {
if (mongoose.connection.readyState >= 1) return;
await mongoose.connect(MONGODB_URI);
}
// app/api/users/route.ts
import { NextResponse } from 'next/server';
import { dbConnect } from '@/lib/db';
import { User } from '@/models/User';
export async function GET() {
await dbConnect();
const users = await User.find().limit(20).lean();
return NextResponse.json({ data: users });
}
Interview point: .lean() for read-only JSON responses avoids Mongoose document overhead.
6. Example Shape: Prisma-Style
import { NextResponse } from 'next/server';
import { prisma } from '@/lib/prisma';
export async function GET() {
const users = await prisma.user.findMany({ take: 20 });
return NextResponse.json({ data: users });
}
Prisma client is usually singleton-exported from lib/prisma.ts per their Next.js documentation pattern.
7. Transactions
For multi-step writes (debit + credit, order + inventory):
Either:
- ORM transaction API (prisma.$transaction, session.withTransaction in Mongo)
Or:
- Single stored procedure / SQL transaction (if you own the schema)
Expose one POST that runs the transaction in the service layer — do not split across two public endpoints if both halves must succeed or fail together.
8. Timeouts and Slow Queries
- Set statement timeouts at the DB when possible.
- Return 504 Gateway Timeout only if your platform maps that way; often you return 500 with a generic message and log the real reason.
9. Checklist Before Shipping DB-Backed APIs
-
DATABASE_URL/MONGODB_URIvalidated at startup or first request with clear failure. - Pooling / serverless driver matches deployment (Vercel, Docker, etc.).
- No secrets in client bundles (
NEXT_PUBLIC_*not used for DB strings). - Indexes exist for common filters (
emailunique, foreign keys). - Errors from DB mapped to safe HTTP responses (2.20.d).
Next: 2.20.d — Response Shape & Error Handling
Part 2 — Deep Encyclopedia (Databases & APIs)
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 });
}