ArchSketch

Architecture gallery › URL shortener

URL shortener architecture (bit.ly style)

A scalable URL shortener design - unique ID generation, a read-heavy redirect path with caching, and click analytics via an event stream.

Open and edit this diagramStart from a blank canvas

URL shortener architecture (bit.ly style) diagram
A common reference design for interviews and real systems. Drawn with ArchSketch.

How it works

A URL shortener looks trivial but is a classic system design exercise because it is extremely read-heavy. Creating a short link is rare; following one happens constantly, and must be fast.

The design separates the two paths. The write path generates a unique short code and stores the mapping. The read path serves redirects from a cache in front of a key-value store, and records each click asynchronously so analytics never slows a redirect down.

Step by step

  1. Creating a link calls the shortener API, which asks the ID generator for a unique code and stores code to URL in the database.
  2. Following a link hits the CDN or load balancer, then the redirect service, which checks the cache first and the database on a miss.
  3. The redirect service responds with an HTTP 301/302 and emits a click event to a stream.
  4. A stream consumer aggregates clicks into the analytics warehouse.

The YAML behind this diagram

Every diagram here is plain text. Paste it into ArchSketch (menu → Diagram from YAML) to edit it, or keep it in your repo next to the code.

nodes:
  - { id: user, kind: user, label: User }
  - { id: cdn, kind: cdn, label: CDN / edge }
  - { id: lb, kind: lb, label: Load balancer }
  - { id: api, kind: service, label: Shortener API }
  - { id: idgen, kind: service, label: ID generator }
  - { id: redirect, kind: service, label: Redirect service }
  - { id: cache, kind: cache, label: Redis cache }
  - { id: db, kind: nosql, label: Link store }
  - { id: clicks, kind: stream, label: Click events }
  - { id: dw, kind: warehouse, label: Analytics }
links:
  - user -> cdn : GET /abc123
  - cdn -> lb
  - lb -> redirect
  - redirect -> cache
  - cache -> db : on miss
  - redirect -> clicks
  - clicks -> dw
  - lb -> api : create link
  - api -> idgen
  - api -> db : store mapping

Use it in your README

Commit your own arch.yaml and embed the always-up-to-date picture:

![Architecture](https://cloudforge.in/render?src=OWNER/REPO/arch.yaml)

YAML format reference