← All articles

Developer guides · 4 min read

URL Shortener System Design and the Limits of a Long URL

Follow a printed menu link through storage, caching and a redirect. See how URL length limits apply to each request and what to test before printing.

By The 302.sh team ·

  1. On the sign
    go.cafe.example/menu
  2. In storage
    Look up the hostname and the slug menu.
  3. In the browser
    Follow the redirect to this week's menu.
A café can keep the same menu link on its signs while changing the destination stored for that link.

A URL shortener stores a destination under a small, stable key. When someone opens the short URL, the service looks up that key and returns a redirect. Those two requests have different requirements. A café might edit its menu link once a week while hundreds of visitors open the address already printed on its tables.

What should the service store when a link is created?

For the café example, store a row with an owner, a hostname, a slug and the complete destination. Add a unique constraint on the hostname and slug together. Two cafés with different domains can then both use /menu. Two owners sharing the same hostname cannot both claim that address.

Six positions drawn from a case-sensitive alphabet of 62 letters and digits give 62⁶ possible codes, about 56.8 billion. Collisions can occur well before the space fills. For a generated slug, attempt the insert and generate another code if the unique constraint rejects it. For a slug chosen by a person, report that the name is taken and let them pick another. An earlier availability check can be out of date by the time the owner presses Save.

What happens when someone scans the menu?

  1. The browser requests https://go.cafe.example/menu. The redirect service reads the row for that host and slug and checks whether it is active.
  2. For an editable menu, the service can return 302 Found with a Location header pointing to the current destination. Pick a cache policy that reflects how quickly a menu edit must take effect.
  3. The browser follows the destination in a second request. A recorded redirect can tell the café that someone followed the link. Confirm a completed order using the ordering system.

If you cache the mapping at the edge, decide what a visitor may see immediately after an edit or deletion. For example, Cloudflare documents that cached Workers KV reads in another location can take time to reflect a write. Test a menu change from a second location before promising instant updates. See how Workers KV propagates changes and our guide to choosing a redirect status.

What is the maximum length of a URL?

HTTP defines no universal maximum URL length. RFC 9110 recommends support for URIs of at least 8,000 octets in protocol elements. That figure is a baseline for interoperability. The redirect service, proxy and destination can each impose a different limit. An HTTP 414 URI Too Long response means that server declined the request because the target was too long. See RFC 9110 §4.1 and the definition of 414.

Measure the encoded path and query in bytes when checking a request-target limit. A single space written as %20 takes three ASCII bytes. A fragment such as #desserts stays in the browser when it requests the menu, so it can matter to the reader even though it adds no bytes to the server's request target.

A short link solves a printing or message-length problem. The second request still has to fit the menu server's limit. If that server returns 414, shorten the destination itself, for example by saving filter selections under an ID. If the original URL already opens correctly, preserve its query and fragment when saving it and test both the final page and the section the visitor sees.

Three checks before putting the address on a sign

To use a managed service for this workflow, see the worked 302.sh API example. It creates one link, reads back its destination and explains how to handle a retry.

Keep reading