URL shortener
Сокращатель ссылок
A web service that gives an existing URL a shorter address. When someone opens the short link, the service redirects them to the original destination.
Also known as: TinyURL
What it does
A URL shortener gives you a new address on its own domain, with a short code in the path. That code is a lookup key, not a compressed version of the destination. The long address, including any query parameters, stays in storage. TinyURL is one example of a service that does this.
From creation to redirect
A client sends the destination to an endpoint such as POST /links. The service checks that the input is a valid URL with an allowed scheme, such as https or http, assigns a code, and saves the mapping. The code can serve as the primary key, so the service can retrieve the destination without scanning the table.
When someone opens the link, the browser requests a path such as GET /b9Qw3. The service looks up the code and, if the mapping is active, sends a redirect. For an unknown code it typically returns 404 Not Found. The browser follows the redirect and contacts the destination directly; the shortener does not serve the destination page.
Example redirect
HTTP/1.1 302 Found
Location: https://events.example/schedule?track=backend&day=2
Cache-Control: no-store
Location tells the browser where to go. A 302 marks the redirect as temporary; the no-store directive tells caches not to store this response. A permanent 301 can be cached, so a repeat visit may skip the shortener altogether. That can reduce traffic to the service, but it also makes destination changes harder to propagate and limits what the service can count.
Uses and pitfalls
Short links are handy in text messages, on printed signs, and in QR codes. They can also help measure interest in a campaign, but redirect requests aren't the same as human clicks: chat previews, bots, and repeat visits can all inflate the count. Don't use a short code as a substitute for access control. And if the shortener loses its domain or its stored mappings, previously shared links can break even though the destination site is still online.
What comes up in system design interviews
Start by asking how often links are created and opened, whether they expire, and whether users can edit them. Then walk through the write and read paths separately. On writes, one option is to encode a unique numeric ID in Base62. Another is to generate a random code, enforce uniqueness in the database, and retry on a collision. A separate check before insertion isn't enough: two requests can both see the same code as available. On reads, cache popular mappings if database lookups become a bottleneck. Explain how you would evict stale entries after an edit or deletion and record click events without making the browser wait for analytics processing.