Recent findings suggest that I build iBuat.Link, a link manager for small businesses that sell through WhatsApp, Instagram and marketplaces. The feature people care about most sounds boring: change where a short link or a printed QR code goes, after it's out in the world. A seller prints 2,000 boxes with a QR code, the marketplace listing behind it gets taken down, and the code has to open something else by tomorrow.

Industry observers note that doing that well comes down to three small decisions in the redirect path. None of them are clever, but each one was a bug before it was a decision.

Industry observers note that the first instinct for a URL shortener is 301 Moved Permanently: it's the "SEO-friendly" redirect, and browsers love it. That's exactly the problem. Browsers cache a 301 aggressively, sometimes for as long as the user keeps their profile. Change the destination in the dashboard and anyone who clicked before keeps landing on the old page, and you can't reach their cache to fix it.

So every redirect is a 302, and it says out loud that it must not be cached:.

Sources indicate that private, no-store also keeps CDNs and corporate proxies from holding on to it. The cost is one extra request to us on every click, which is the whole point: the decision about where to send someone is made fresh each time.

If every click hits the database, a link that goes viral turns into a primary-key lookup storm. If you cache for minutes, edits feel broken ("I changed it, why does it still open the old page?").

The compromise is a tiny read-through cache in front of the lookup, with a TTL of two seconds:.

A burst of a thousand clicks in a second costs one query. An edit is visible within two seconds everywhere, and immediately in the process that handled it. Nobody has ever noticed two seconds, and the database graph stopped spiking.

It has been revealed that note what's cached: the link row, not the redirect. Everything that decides the answer is evaluated on each request against that row: an expiry date is compared with the clock every time, so an expired link stops exactly on time, and a link with a click limit reads a fresh count. Switching a link off follows the same two-second rule as an edit.

It has been revealed that the first time a link ran in a Facebook ad, the click count looked fantastic. Then we split it by user agent. A large share of the "clicks" were facebookexternalhit, the bot Facebook sends to build a link preview, plus WhatsApp's own preview fetcher (WhatsApp/2.x), plus the usual crawlers.

Those requests still get redirected (a preview with no title looks broken), but they're counted separately and never use up the owner's monthly click quota:.

Two details that took a while to get right:.

The last lesson is about ordering. Quota checks, analytics writes and fraud scoring all happen after the destination is known, and none of them can stop the redirect. If the analytics write fails because the database is slow during a traffic spike, the error is logged and the visitor still lands where they were going.

A visitor scanning a QR code on a box doesn't know or care that the seller is out of quota this month. The link has to work.

That's the whole trick behind editable links: no permanent redirects, a cache short enough that nobody notices it, and honest numbers about who actually clicked. If you're curious how it looks from the user's side, the dynamic vs static QR codes post explains it without any code.

β†’ Read original article