System design cheatsheets

Review common interview systems quickly.

Each cheatsheet is structured around requirements, architecture, storage, caching, events, bottlenecks, tradeoffs, failure modes, and talking points.

URL Shortener

Convert long URLs into short aliases and redirect users quickly.

Functional Requirements

  • Create short URL
  • Redirect short URL
  • Optional custom alias and expiration
  • Basic analytics

Non-Functional Requirements

  • Very low redirect latency
  • High read availability
  • Unique aliases
  • Abuse prevention

Core Entities

  • ShortUrl
  • User
  • ClickEvent

API Sketch

  • POST /urls { longUrl, customAlias? }
  • GET /{alias}
  • GET /urls/{id}/stats

High-Level Architecture

  • API service creates aliases
  • Redirect service reads alias mapping
  • Analytics events are written asynchronously

Database Choices

  • Key-value store for alias to URL
  • SQL or NoSQL metadata table
  • Object store not needed for core path

Caching Strategy

  • Cache hot aliases in Redis or edge cache
  • Use TTLs for expired links

Queues / Events

  • Publish click events to analytics pipeline

Scaling Bottlenecks

  • Hot viral links
  • Alias generation collisions
  • Analytics write volume

Tradeoffs

  • Random aliases are simple; sequential ids are compact but easier to enumerate
  • Synchronous analytics increases redirect latency

Failure Modes

  • Cache outage falls back to database
  • Expired or missing alias returns 404
  • Queue lag delays analytics

Interview Talking Points

  • Keep redirect path minimal
  • Separate analytics from redirect
  • Discuss collision handling