Skip to content

Dub: redirects at the edge

An open-source link platform: every click is a redirect that must be fast everywhere, and an analytics event that must never slow it down.

The idea

A short link does two jobs on every click: send the visitor on, and remember that they came. Dub is unusual because its redirect path is open source, so you can read the real answer instead of guessing at it.

The redirect runs in middleware at the edge, near the visitor. It looks the link up in Redis and goes to the database only on a miss, filling the cache afterwards. Recording the click is deferred until the response has gone out, so a slow analytics store costs the visitor nothing. And when Redis itself is failing over, the code skips click tracking rather than risk a slow redirect. A missing click is cheaper than a slow page.

Click analytics began in Redis sorted sets, which could count but could not filter by country, referrer or device without slow queries. They moved to a column store built for that kind of question. It is the same split the URL shortener investigation arrives at: the redirect path owns latency, the analytics path owns flexibility, and neither waits for the other.

Read the originals

Written by the engineers who built it.

  • Upgrading short link analytics by 100x with Steven Tey

    Steven Tey · Post, May 2023

    An interview on Tinybird's blog about why click data outgrew Redis sorted sets once people wanted to filter and group it, and what replaced them.

  • Dub's link redirect middleware

    Steven Tey and Dub contributors · Code, Sep 2022

    The code that serves every Dub short link. Look for the Redis lookup with a database fallback, the click recorded after the response is sent, and what happens when Redis is failing over.

Practise it

Make the decisions yourself, then compare.