PracHub
QuestionsPremiumLearningGuidesCheatsheetNEW
|Home/Coding & Algorithms/Shopify

Build a Local URL Shortener

Last updated: Apr 6, 2026

Quick Overview

This question evaluates a candidate's ability to design and implement a local URL shortener, exercising competencies in URL validation, hash-based encoding and collision handling, in-memory mapping with JSON persistence, deduplication, edge-case handling for long inputs, and comprehensive test coverage.

  • easy
  • Shopify
  • Coding & Algorithms
  • Software Engineer

Build a Local URL Shortener

Company: Shopify

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

Implement a local URL shortener that runs on a single machine. Design a small library or service with two core operations: - `shorten(long_url) -> short_code` or `short_url` - `resolve(short_code) -> original_url` Requirements: 1. Validate that the input is a well-formed URL and reject invalid input. 2. Generate a short code using a hash-based or similar encoding strategy. 3. Handle hash collisions correctly so that no original URL mapping is lost. 4. Store the mapping between short codes and original URLs in memory using a hash map. 5. Persist the in-memory mapping to a JSON file, and reload that file when the program starts again. 6. If the same original URL is shortened multiple times, return the same shortened result instead of creating duplicates. 7. Handle edge cases such as extremely long URLs. 8. Write tests for invalid input, collision handling, duplicate requests, and long URLs, with strong line and branch coverage. 9. Be prepared to discuss how memory usage grows with the number of stored URLs and what changes you would make if the data no longer fits comfortably on one machine. Assume this is a local-only implementation. Do not introduce external systems such as Redis or a database unless you can justify why they are necessary.

Quick Answer: This question evaluates a candidate's ability to design and implement a local URL shortener, exercising competencies in URL validation, hash-based encoding and collision handling, in-memory mapping with JSON persistence, deduplication, edge-case handling for long inputs, and comprehensive test coverage.

Related Interview Questions

  • Compute Jaccard Similarity for Lists - Shopify (medium)
  • Implement URL Shortening Codec - Shopify (medium)
  • Simulate a rover fleet - Shopify (medium)
  • Simulate robot moves on a grid - Shopify (medium)
  • Implement a Capacity-Bounded Cache - Shopify (medium)
Shopify logo
Shopify
Jan 24, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
5
0

Implement a local URL shortener that runs on a single machine.

Design a small library or service with two core operations:

  • shorten(long_url) -> short_code or short_url
  • resolve(short_code) -> original_url

Requirements:

  1. Validate that the input is a well-formed URL and reject invalid input.
  2. Generate a short code using a hash-based or similar encoding strategy.
  3. Handle hash collisions correctly so that no original URL mapping is lost.
  4. Store the mapping between short codes and original URLs in memory using a hash map.
  5. Persist the in-memory mapping to a JSON file, and reload that file when the program starts again.
  6. If the same original URL is shortened multiple times, return the same shortened result instead of creating duplicates.
  7. Handle edge cases such as extremely long URLs.
  8. Write tests for invalid input, collision handling, duplicate requests, and long URLs, with strong line and branch coverage.
  9. Be prepared to discuss how memory usage grows with the number of stored URLs and what changes you would make if the data no longer fits comfortably on one machine.

Assume this is a local-only implementation. Do not introduce external systems such as Redis or a database unless you can justify why they are necessary.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Shopify•More Software Engineer•Shopify Software Engineer•Shopify Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.