Generate new URL:

  • Brute force hash won’t work because we want to keep the URL short
  • hash of (snowflake id + salt) - need to do base conversion, e.g., from decimal to 62-based
    • Similarly, we can pre-generate short URL by hash of incremental id, and assign to the incoming long URL request
  • MurmurHash
  • Brute force pick 7 random chars may cause multiple rerolls when it is close to full
  • Limit it to 255 varchars. Note 62^7 is 300 bil already space.

Need to persist:

  • past long -> short mappings for look up
  • past short mapping for conflict check.
  • We can also solve it by a unique index on the short url
  • Bloomfilter to detect obviously new ones - 1B set consumes about 125M

The server can return either 301 (perm redir) or 302 (temp redir). The difference is that if the client will cache the redirectly result

Handling edits and deletes