DEV Community

Cover image for Design a short url for system design interview
Daniel Lee
Daniel Lee

Posted on

Design a short url for system design interview

This article is a personal note from "System Design Interview - An Insider's Guide by Alex Xu". It's intended as a memory refresher for system design interview in hurry.

hash funciton

  • to generate a shorter URL, use a hash function to map between short URLs and long URLs. For example, hash functions like CRC, MD5 and SHA-1 are used.

hash value

  • to generate short URLs of length "n", find the value that meets "back-of-the-envelope" estimation. For example, a system is identified to support 365 million unique URLS, then given the system generates using [0-9,a-z,A-Z], "n" has to be 62^n >= 365 M (roughly 7).

hash collision

  • to generate unique short URLs, two approaches can be taken:
    1. *Base 62 conversion *- converts the same number between its different number presentations
    2. Hash the first "n" number of characters and append it to the rest to generate a short URL. If the length of the result still exceeds "n", repeat the process.
      • As this can be time-consuming, "bloom filter" can be used to improve performance. Bloom Filter is a space-efficient probablistic technique to test if an element in a number of a set.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay