How it works
A shortener has two core actions: accept a long URL and return a short link, then resolve that link to the original destination. Agree on allowed schemes (the part before the colon, such as https), link lifetime, whether a destination can change, custom aliases, and whether click analytics matters. These choices affect storage, redirects, and abuse controls. X’s t.co, for instance, wraps links so it can screen them and count clicks, which a private bookmark tool does not need.
Suppose the service creates 30 million links each day and each is opened 25 times. Average creation traffic is about 350 writes per second; redirects average about 8,700 reads per second. If the busiest hour runs at three times the average, plan for about 26,000 redirects per second. Five years yields about 55 billion mappings, where a mapping is one stored record pairing a short key with its destination. At 120 bytes of destination text each, that is about 6.6 TB of raw URL text, before identifiers, indexes, metadata, replicas, and overhead. These figures are an example, not a measurement of any real service.
The same arithmetic can talk you out of complexity. An internal company tool creating 500 links a day reaches under two million mappings in ten years, which fits comfortably in one Postgres instance. Sharding (splitting data across databases) and a dedicated key service would only add operational cost there.
A team says “make links as short as possible” but also wants five years of retention. What do you clarify first?
Clarify the expected number of mappings, allowed alphabet, whether links expire or change, and whether aliases are user-selected. These set the key-space and storage requirements; “short” alone cannot determine a safe length.
Use this as a guide for self review; written answers are not graded.Keep in mind
- Define the link contract before choosing a key algorithm.
- Keep units, time horizon, peak factor, and storage overhead visible.