CDNrange B2009215674937range Ashard 2PRIMARYcopy 1copy 2slot 1qpjF8n6slot 2QODkgKcslot 31POST /urls2 body: long_url3GET /zn9edcu4 → 301 Location1TABLE urls2 code PK3 long_url4 created_at1w = 1e8 / 864002r = 10 * w3b = 1e8 * 365 * 100
Back: CDN edge, ID generator, primary database, read replicasMiddle: user, load balancer, app servers, cache · Front: API, data model, estimateEnvelopes: one request or reply, labelled, moving along its pathThe whole URL shortener on one table: the user, a CDN edge, a load balancer, three app servers, a cache, an ID generator, the primary database and two read replicas, with the API, the data model and the estimate on cards in front. A new link gets the next number (2009215674938), written in base 62 as zn9edcu, and is saved in the primary. Clicks on popular links are answered from the cache; a miss reads a replica and fills the cache. Replicas and a CDN carry the read load. The traffic figures are classroom assumptions (100 million new links a day, 10 reads per write, 100 bytes a link), not measurements of any real service. Their job is to show the scale: thousands of reads a second and terabytes a year.

The problem

  1. A URL shortener turns a long web address into a short one, like sho.rt/zn9edcu. Opening the short link sends you on to the long one. So the service has two jobs: make a short link, and follow one.

Writing a link

Reading at scale

Trade-offs

What happens

;; step 1/11 · goal
;; at: user
long   example.com/guides/brewing-coffee
short  sho.rt/zn9edcu

job 1  create: long URL → short code   (rare)
job 2  follow: short code → redirect   (very common)

design = choosing the parts, and how requests flow through them

The traffic figures are classroom assumptions (100 million new links a day, 10 reads per write, 100 bytes a link), not measurements of any real service. Their job is to show the scale: thousands of reads a second and terabytes a year. 301 is cacheable unless headers say otherwise; 302 is cached only when headers allow it (RFC 9110 and RFC 9111).