
How I Built Sub-50ms QR Code Redirects with nextjs, performance, Cloudflare Workers
Most QR code services run redirects through their main application server. Here's why that's a terrible idea, and how I solved it with Cloudflare Workers for OwnQR . The Problem When someone scans a dynamic QR code, three things happen: The phone opens a URL (like oq.link/abc123 ) The server looks up where abc123 should redirect to The user gets sent to the destination If you run this through a Next.js/Vercel app, you're looking at: Cold starts : 500ms+ on serverless Single region : User in Tokyo, server in Virginia = 200ms latency Database query : Another 50-100ms That's 750ms+ before the user sees anything. For a QR code scan (which people expect to be instant), that feels broken. The Solution: Edge Redirects I moved the redirect logic to a Cloudflare Worker. The entire lookup + redirect happens at the nearest edge node: export default { async fetch ( request : Request , env : Env , ctx : ExecutionContext ) { const url = new URL ( request . url ) const match = url . pathname . match
Continue reading on Dev.to
Opens in a new tab
