Skip to solution
hardSystem Design

How would you design a URL shortener like TinyURL?

513 views
01

Understand the problem

Outline a URL shortener design.

url-shortener
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Designing a URL Shortener (like TinyURL or Bitly) — Beginner-Friendly Guide

Target Audience: Junior & Senior Software Engineers preparing for System Design Interviews — no prior system design knowledge assumed. Difficulty: Easy to Medium

How to read this doc: Every concept is explained in plain langua

Solution ready — 2 min read

Classified // press E to declassify

04

Read the code

Base62 encode/decode for short-code generation
Run Playground
const ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
const BASE = ALPHABET.length;

function encodeBase62(num) {
  if (num === 0) return ALPHABET[0];
  let chars = [];
  while (num > 0) {
    const remainder = num % BASE;
    chars.push(ALPHABET[remainder]);
    num = Math.floor(num / BASE);
  }
  return chars.reverse().join('');
}

function decodeBase62(code) {
  let num = 0;
  for (const char of code) {
    num = num * BASE + ALPHABET.indexOf(char);
  }
  return num;
}

const ids = [1, 125, 125100524, 999999999];
for (const id of ids) {
  const code = encodeBase62(id);
  const back = decodeBase62(code);
  console.log(`${id} -> ${code} -> ${back}`);
}
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 71 of 99 decoded in the System Design track. One more won't hurt.

Back to track