Design Questions
- The length of shorten url and allowed characters
- Traffic volumn
- Can shorten url be deleted or updated
Data model
Store long url and the shorten url as an entry in Database with a unique ID.
- Option1: use the hash value of long url as the shorten url, resolve the hash value collision issue
Pros: unique ID generator is not required, the shorten url length could be fixed - Option2: use the base64 to convert the unique ID to shorten url
Pros: no hash value collision issue, decouple the shorten url from long url
Critical User Journey
- Url Shortening: send long url to server → check DB if long url exists → return shorten url if found → otherwise create an unique ID, generate shorten url, save entry into the DB → return shorten url
- Url redirection: send shorten url to server → check cache if shorten url exists → if not found, check DB for the entry → return long url with 301/302 http code status → request is redirected to long url
Follow-up questions
- Rate limiting
- Scaling up servers and database
- Support Data analysis CUJ