Performance: Route handlers for webhooks
MEDIUM IMPACT
This affects server response time and client perceived latency when handling webhook requests in Next.js API routes.
export async function POST(req) { const body = await req.json(); // offload heavy work asynchronously setTimeout(() => { // process webhook data asynchronously }, 0); return new Response('Webhook received'); }
export async function POST(req) { const body = await req.json(); // heavy synchronous processing for (let i = 0; i < 1000000000; i++) {} return new Response('Webhook processed'); }
| Pattern | Server Blocking | Response Time | Client Impact | Verdict |
|---|---|---|---|---|
| Synchronous heavy processing in route handler | Blocks event loop | High (100+ ms) | High INP, slow webhook ack | [X] Bad |
| Asynchronous processing with immediate response | Non-blocking | Low (<10 ms) | Low INP, fast webhook ack | [OK] Good |