Requirement: Design a system to take user-provided URL and transform them to a shortened URL that redirect back to original.
How to evaluation a system design?
- Bad: no sense of requirement
- Pool: limited knowledge
- Good: reasonable solution, explain clearly
- Great: well thoughtful, tradeoff
There are several points that can be considered before design a Tiny URL solution.
- How to map a short URL to the original long URL? how to encode long URL to the short key (MD5 or Base64)? If MD5, truncate the rest, long leave 5 characters. How to avoid conflicts?
- How to save the key – value mapping? RMDB or NoSQL?
- Consider Memcache, and combined with a NoSQL DB (CouchBase, MongoDB).
- How to support multiple DB servers to scale the performance for future queries?
– sharding: hash(URL)%Server_no = server_id
– to achieve high availability, consider standby
– how to replicate the data across server (cross region, master/slave, master/master)
– how to recover from crush (master need a checkpoint, slave needs recreate)
– how to guarantee data consistency - How to coordinate multiple clusters? ZooKeeper is one option
- How to limit single user send spam queries?
good
Wonderful article! That is the type of info that are meant to be shared around the net.