SYSTEM DESIGN
🇬🇧UK Edition🇨🇦Canada Edition🌐Global Tech

System Design Interview: Scalable URL Shortener (TinyURL) Architecture

Marcus Thorne
Marcus Thorne
Enterprise Cloud Architect
Updated 03/09/20269 min read0 views

Key Requirements

1. Shortening: Given a long URL, return a 7-character Base62 short alias.
2. Redirection: Accessing short URL redirects with HTTP 302 Found.
3. Scale: 100 Million shortened URLs generated per day.

Base62 Encoding vs Key Generation Service (KGS)

Using a pre-generated Key Generation Service (KGS) guarantees zero collision without expensive database check-before-insert operations.

javascript
// Base62 Converter Function
const BASE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

function encodeBase62(num) {
  let sb = "";
  while (num > 0) {
    sb = BASE62[num % 62] + sb;
    num = Math.floor(num / 62);
  }
  return sb.padStart(7, '0');
}

console.log("ID 125000000000 encoded:", encodeBase62(125000000000));

Frequently Asked Questions (FAQ)

Q: Why HTTP 302 redirect instead of 301?

HTTP 302 directs browsers to check server on every click, allowing accurate analytics tracking; HTTP 301 is cached by browsers.

Marcus Thorne
Written by Marcus ThorneAdSense EEAT Verified

Enterprise Cloud Architect. Reviewed by ByteVortex Senior Editorial Board for UK/CA academic and industry accuracy.