A URL Shortener

In this chapter, we design a URL shortener for three different systems, and we apply what the course has covered so far to each design decision.

After reading this chapter, you should be able to:

  • Define URL shortener and short code, and name its two operations, shorten and follow
  • State each variant’s added functional requirements, quality attributes, and requirements for short codes
  • Estimate requests per second, the read-to-write ratio, and storage per year from daily numbers
  • Explain why following a link must be a REST endpoint, and choose between 301 and 302 redirects
  • Compare relational, document, and key-value databases for the links, and justify a choice
  • Use the hit ratio to decide which variants need a cache
  • Explain how invalidation and expiry stop a blocked link from redirecting
  • Decide which variants need replicas, for reads, for failover, or both
  • Classify following, creating, and turning off a link as CP or AP during a network partition
  • Explain why routing by a hash of the code fits the links better than a directory, and what it gives up
  • Compare ways to generate short codes, and choose one for each variant

Sections

  1. A URL Shortener
  2. Requirements
  3. Load Assumptions
  4. The API
  5. The Database
  6. Caching Links
  7. Replicas
  8. Sharding the Links
  9. Generating Short Codes
  10. Putting It Together