Katkat

Design a URL shortening service

OpenAISoftware Engineer · Onsite

Last updated

This problem tests your ability to design a distributed, high-scale URL shortening service, focusing on data modeling, collision-resistant ID generation, and performance optimization via caching.

Design a URL Shortening Service

Design a system similar to Bitly that converts long URLs into short, unique aliases (e.g., https://bit.ly/xyz123).

Requirements

  • Functional:
    • Users should be able to input a long URL and get a unique short URL.
    • When a user visits the short URL, they should be redirected to the original long URL.
    • Short URLs should be short, ideally 7 characters long.
  • Non-Functional:
    • High availability: The system must remain functional even if individual components fail.
    • Low latency: Redirects must be fast (aim for > Creations).
  • URLs will be stored permanently (no automatic expiration unless specified).
  • You do not need to implement user accounts or analytics for this initial version.

Deliverables

  1. High-level architecture diagram (described in text).
  2. Database schema design and choice of storage technology.
  3. Strategy for generating unique, short identifiers at scale.
  4. Techniques to handle traffic spikes and caching strategies.

Hints

Hint 1

Consider the trade-offs between using a sequential counter versus a hash function (like MD5 or SHA-256) for generating short IDs.

Hint 2

Think about how to prevent the database from becoming a bottleneck during high-volume read traffic.

Hint 3

Discuss how you would handle data partitioning (sharding) once the dataset exceeds the capacity of a single database instance.

Follow-up questions

  • How would you handle potential ID collisions if you chose a hashing strategy instead of a global counter?
  • How would you modify the system to support URL expiration (e.g., delete links after 6 months of inactivity)?
  • If the service becomes global, how would you design for low-latency redirects for users in different continents?