Case study · Stack

How Dub serves fast redirects and click analytics on a serverless stack

Dub is an open source platform for short links and link attribution, used by teams like Twilio, Vercel and Raycast. Its stack is built almost entirely from managed services: Next.js on Vercel for the app and redirects, Redis to cache links, MySQL on PlanetScale for core data and Tinybird for click analytics.
Copy this stackdub.co Open source link management and attribution · United States · founded 2022

Language

  • TypeScriptgithub.com

    Main language across the monorepo.

Full-stack framework

  • Next.jsdub.co

    Runs the dashboard, the API routes and the link redirects through Middleware.

Hosting

  • Verceltinybird.co

    Hosts and deploys the app, with redirect logic running at the edge.

    Why: Edge Functions run redirects very close to users, which made a link shortener a natural fit.

Database

  • PlanetScaledub.co

    MySQL database that stores users and link data.

Login

  • NextAuth.jsgithub.com

    Handles user sign-in, with a Prisma adapter.

  • BoxyHQ SAML Jacksongithub.com

    Adds SAML single sign-on for enterprise customers.

Payments

Email

Styling and UI kit

ORM

  • Prismagithub.com

    ORM for the MySQL database, with the PlanetScale adapter.

Data fetching

  • Upstash Redisupstash.com

    Caches every link's metadata so redirects never touch MySQL.

    Why: Steven Tey says the JS SDK took minutes to set up and credits it for sub-200 ms redirects.

  • Upstash QStashdub.co

    Runs background jobs like imports, exports, webhooks, payouts and crons.

Testing

  • Vitestgithub.com

    Unit and integration tests, alongside Playwright.

AI model

  • Vercel AI SDKgithub.com

    AI features in the app, with Anthropic as the model provider.

Analytics

  • Tinybirdtinybird.co

    Stores click events and serves the analytics queries as API endpoints.

    Why: They wanted ClickHouse performance without running a cluster, after Redis Sorted Sets got too slow.

Error monitoring

How they built it

Born as an edge demo

Founder Steven Tey said one reason he built Dub was to show what Edge Functions can do: they run server-side logic like redirects very close to the user, and a link shortener is the perfect use case.

The code is public on GitHub under an open core model. Most of it is open source, and a smaller part in the /ee folder has a commercial license.

Sources:tinybird.co github.com

Redirects that skip the database

Redirects run in Next.js Middleware. To handle heavy traffic, Dub caches every link's metadata in Redis the moment the link is created, so a redirect never has to hit the MySQL database.

MySQL, hosted on PlanetScale, holds users and link data. Steven Tey credits Upstash Redis for redirect times under 200 ms.

Sources:dub.co upstash.com

From Redis to Tinybird for analytics

Click data first lived in Redis Sorted Sets. It was hard to filter by location or referrer, and some queries took more than 5 seconds as customers' links passed hundreds of thousands of clicks.

The team liked ClickHouse's speed but not the work of running a cluster, so they moved to Tinybird, a managed ClickHouse. The app sends each click to Tinybird's Events API and reads SQL queries published as endpoints. Steven Tey says analytics got about 100x faster, and the same click data now feeds usage-based billing.

Sources:tinybird.co tinybird.co

Background jobs and AI

Long-running work like imports, exports, webhooks and partner payouts goes through Upstash QStash, which calls Dub's own cron routes.

The web app's package.json also pulls in the Vercel AI SDK with the Anthropic provider, Axiom for logging, and Vitest and Playwright for tests.

Sources:dub.co github.com

Also detected on their website

Found on the homepage with the open Wappalyzer rules (HTML, scripts and headers). It shows what runs in the browser, not the whole backend.

  • HSTS
  • React
  • Webpack