// Using the short URL
Request: GET /{short}
Response: HTTP redirect to long URL
Request: POST /create
Body: {long url}
Response:
Returns the short url. If already mapped for the given {long url}, it simply returns existing short url. Could increase latency on this method.
URLs are stored as a simple mapping from short -> long. A no-sql database will due (very fast lookup by key, ), using some function on the long URL to generate the keys, we'll call it hash().
There could be different approaches to implementing this function.
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
Let's talk about some different ways to generate the short urls. One way, would be to swap our DB for a relational database which typically come with auto-increment primary keys, and just use this integer as the url. So what's wrong with that?
We can generate the ID using a hashing function on the original long URL. To prevent all the keys from a single domain being close together creating hotspots, we may reverse the URL string (foobar.com.www instead of www.com.foobar). Hash collisions are rare if we use a sufficiently large key space, and can be detected using database atomic insert-if-not-exists features.