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
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。