Back to Articles

Enterprise URL Shortening: Redis Edge Routing and Click Analytics

How to build a high-performance URL shortener with Redis edge routing for sub-12ms redirects, geo-location tracking, and Chart.js click analytics dashboards.

Enterprise URL Shortening: Redis Edge Routing and Click Analytics

URL shorteners must redirect in milliseconds. StatLink achieves sub-12ms redirects by resolving links at the network edge using Redis.


1. Edge Function Redirect

Next.js Middleware runs at the CDN edge, looking up the short code in Upstash Redis before the request reaches the origin server:

typescript
import { NextResponse } from 'next/server'; import { Redis } from '@upstash/redis'; const redis = Redis.fromEnv(); export async function middleware(request: NextRequest) { const code = request.nextUrl.pathname.slice(1); const destination = await redis.get(`link:${code}`); if (destination) return NextResponse.redirect(destination as string); return NextResponse.next(); }

2. Async Analytics Logging

Click metadata (IP, user agent, referrer, geo-location) is logged asynchronously to PostgreSQL so redirects are never delayed by analytics writes.


3. QR Code Generation

Each shortened link auto-generates a downloadable QR code using the qrcode library, ready for print campaigns.


Summary

Edge computing + Redis caching delivers URL redirects faster than traditional server-side approaches while capturing rich analytics data.