首页 > 代码库 > Design Tiny URL
Design Tiny URL
Design a system to take user-provided URLs and transform them to a shortened URLs that redirect back to original.
Questions:
1. How many URLs shall we keep?
2. Read > Write ?
Solution:
1. URL encoding:
URL --> (a...zA..Z0..9-_) 65^n URLs.
hash: md5 etc.
How to resolve collision?
2. Cache:
KEY-VALUE
LFU or LRU: LFU is better, Frequency
Multi Cache Servers
- Sharding: hash(URL) % N
- Standby: *n
ZooKeeper
3. Reliability:
- Replica: Cross region, master slave
- Recovery: master: checkpoints, slave: recreate, meta data
- Consistency
4. Rate limit
Block user when requests more than 10/min or 100/hour or 1000/day ...
one bucket every one minute
Memcache
key: 1400_op_username
value: counter
Design Tiny URL
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。