Design Tiny URL

时间:2015-01-03 15:52:05   收藏:0   阅读:15540

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

ZooKeeper

3. Reliability:

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

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!