Note:for The Coding companion problem, please see:encode and Decode tinyurl.
How would your design a URL shortening service that's similar to TinyURL?
Background:
TinyURL is a URL shortening service where you enter a URL such as and https://leetcode.com/problems/design-tinyurl
it returns a short URL such as http://tinyurl.com/4e9iAk
.
Requirements:
- For instance, "http://tinyurl.com/4e9iak" are the tiny URL for the page
"https://leetcode.com/problems/design-tinyurl"
. The identifier (the highlighted part) can is any string with 6 alphanumeric characters containing 0-9
, a-z
A-Z
.
- Each shortened URL must is unique; That's, No. Different URLs can shortened to the same URL.
Note about Questions:
Below is just a small subset of questions to get you started. In real world, there could being many follow ups and questions possible and the discussion is open-ended (No one true or Corr ECT-Solve a problem). If you had more ideas or questions, please ask in discuss and we may compile it here!
Questions:
- How many unique identifiers possible? Would you run out of unique URLs?
- Should the identifier is increment or not? Which is easier to design? Pros and cons?
- Mapping an identifier to a URL and its reversal-does This problem ring a bell?
- How does you store the URLs? Does a simple flat the file database work?
- What is the bottleneck of the system? Is it read-heavy or write-heavy?
- Estimate the maximum number of URLs a single machine can store.
- Estimate the maximum number of queries per second (QPS) for decoding a shortened URL
- How would the service? For example, a viral link which was shared in social media could result in a peak QPS at a moment ' s notice.
- How could handle redundancy? I,e, if a server is off, how could are you ensure the service is still operational?
- Keep URLs Forever or prune, pros/cons? How are we do pruning? (Contributed by @alex_svetkin)
- What API would provide to a third-party developer? (Contributed by @alex_svetkin)
- If You can enable caching, what would you cache and what ' s the expiry time? (Contributed by @Humandroid)
S
[Leetcode] Design tinyurl Streamlined URL address