Urgent.News

What's breaking now, across thousands of outlets.

Tech

How to Accelerate Next.js App Router API Routes by 10x

Next.js App Router brought powerful server-side capabilities with React Server Components (RSC) and standard Route Handlers ( app/api/route.ts ). However, in production deployments on Vercel or AWS Lambda, Next.js API Route Handlers frequently suffer from serverless execution overhead : Cold starts adding 150ms–400ms to initial invocations. Node.js runtime parsing and ORM database connection…

The Next.js App Router introduced server-side capabilities with React Server Components and standard Route Handlers. However, in production deployments on Vercel or AWS Lambda, API Route Handlers often experience significant serverless execution overhead. This includes cold starts, Node.js runtime parsing, and database connection latency. High costs and performance issues arise under heavy traffic.

To address this, the guide recommends edge-caching Next.js Route Handlers, bypassing Node.js runtime overhead on read requests, and achieving sub-15ms API response times. The bottleneck is standard Route Handlers, which execute on every single HTTP request, leading to high invocation bills.

The solution involves configuring Route Handlers to return Cache-Control headers and routing the API domain through an edge proxy (ApexCache). When an admin updates a product or a new order completes, trigger a background tag purge using Next.js Server Actions. This approach reduces production latency, warms up edge proxy caches, and slashes serverless function invocations by over 95%.

Production latency and cost comparisons show a significant improvement when using the Next.js Serverless Direct with Edge Proxy setup. API latency drops from 240ms to 11ms in the 50th percentile, while P99 latency improves dramatically. Serverless function invocations are reduced by 95.8%, and database connection pressure is minimal. The monthly Vercel or Cloud bills are slashed by over 75%.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

How to Test Receipt Templates — Custom-Domain Transactional Email API Ownership

A beginner comparing MailerSend with Amazon SES or another simple transactional email API should not pick the cheapest option for welcome emails until custom-domain authentication and suppression-list…

  • Custom-domain authentication required for transactional email APIs
  • Receipt templates must include order reference, payment state, amount, and support path
  • Testing focuses on final customer artifact and state transitions

Client API Key — Design (Lite) ออกแบบ API key service to service ให้เบาและยังถูกต้อง

ออกแบบ API key สำหรับการเรียกกัน service to service ให้เบาและยังถูกต้อง วันหนึ่งจะมีอีกทีมมาขอเรียก service ของคุณ และคุณต้องรู้ให้ได้ว่าใครเป็นคนยิงเข้ามา ตัวเลือกที่คนส่วนใหญ่หยิบมีสองขั้ว…

  • Lightweight API key service designed for service-to-service communication
  • Six columns and ten functions in the CREATE TABLE statement
  • Keys revoked using timestamps, not stored directly in the database

More from Saturday 29 August →