Skip to content

Instantly share code, notes, and snippets.

@neufeldtech
Created August 20, 2024 00:10
Show Gist options
  • Save neufeldtech/ac5e8785eb27eaa9fde4b3d0fe0c9727 to your computer and use it in GitHub Desktop.
Save neufeldtech/ac5e8785eb27eaa9fde4b3d0fe0c9727 to your computer and use it in GitHub Desktop.

Interview Brief: URL Shortener Implementation

Objective:

The goal of this pair programming interview is to build a functional URL shortener within 75 minutes. The focus should be on implementing core features that meet the main functional requirements. Scalability and database design concerns should be secondary and only briefly discussed if time permits.

Functional Requirements:

  1. Short Link Generation:

    • Given a URL, the service should generate a shorter and unique alias (short link).
    • The short link should be easy to copy and paste into applications.
  2. Redirection:

    • When users access a short link, the service should redirect them to the original URL.
  3. Custom Short Links:

    • Users should have the option to pick a custom short link for their URL.
  4. Expiration:

    • Links should expire after a default timespan.
    • Users should be able to specify the expiration time.

Non-Functional Requirements:

  1. Availability:

    • The system should be highly available to ensure URL redirections do not fail.
  2. Latency:

    • URL redirection should happen in real-time with minimal latency.
  3. Security:

    • Shortened links should not be guessable or predictable.

Extended Requirements (Optional):

  1. Analytics:

    • Track how many times a redirection happened.
  2. API Accessibility:

    • The service should be accessible through REST APIs by other services.

Implementation Steps:

  1. Basic Setup:

    • Set up a basic web server (e.g., using Flask for Python or Express for Node.js).
    • Create endpoints for creating and redirecting URLs.
  2. Short Link Generation:

    • Implement a function to generate a unique short link (e.g., using base62 encoding).
    • Store the mapping between the original URL and the short link in an in-memory data structure (e.g., a dictionary).
  3. Redirection:

    • Implement a function to handle redirection from the short link to the original URL.
    • Ensure the redirection is handled with minimal latency.
  4. Custom Short Links:

    • Allow users to specify a custom alias for their short link.
    • Ensure the custom alias is unique and not already taken.
  5. Expiration:

    • Implement a mechanism to handle link expiration.
    • Allow users to specify an expiration time for their short links.
  6. Testing:

    • Write basic tests to ensure the core functionality works as expected.
    • Test edge cases such as duplicate URLs, custom aliases, and expired links.

Optional Discussion Points (if time permits):

  1. Scalability:

    • Briefly discuss how the system could be scaled (e.g., using a NoSQL database like DynamoDB or Cassandra).
  2. Database Design:

    • Outline a basic schema for storing URL mappings and user data.
  3. Concurrency and Fault Tolerance:

    • Discuss potential issues with concurrency and how to handle them.
    • Consider fault tolerance and how to ensure high availability.

Conclusion:

The primary goal is to have a working URL shortener by the end of the session. Focus on implementing the main functional requirements first. If time allows, touch on scalability and database design, but these are not the main focus of this interview.

Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment