Skip to content

Commit a3dc5f9

Browse files
author
liwentian
committed
fd
1 parent 54ce056 commit a3dc5f9

File tree

9 files changed

+71
-49
lines changed

9 files changed

+71
-49
lines changed

.DS_Store

0 Bytes
Binary file not shown.

ToDo.md

Lines changed: 0 additions & 20 deletions
This file was deleted.

app/src/main/java/com/inuker/leetcode/MainActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
import android.app.Activity;
44
import android.os.Bundle;
55

6+
import java.util.concurrent.DelayQueue;
7+
68
public class MainActivity extends Activity {
79

10+
private DelayQueue
11+
812
@Override
913
protected void onCreate(Bundle savedInstanceState) {
1014
super.onCreate(savedInstanceState);

discuss.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

skyline1.png

-12.8 KB
Binary file not shown.

skyline2.png

-16.1 KB
Binary file not shown.

solution/src/main/java/com/inuker/solution/DesignTinyURL.java

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.inuker.solution.system;
2+
3+
/**
4+
* Created by liwentian on 2017/10/17.
5+
*/
6+
7+
public class DesignTinyURL {
8+
9+
/**
10+
* 这题和#535. Encode and Decode TinyURL类似,不过这题更偏向于系统设计
11+
*
12+
* 1. How many unique identifiers possible? Will you run out of unique URLs?
13+
* 如果按6个字符计算,一共有62**6种可能,大概三百多亿,越到后面碰撞越来越多,可以通过增加字符数来解决
14+
*
15+
* 2. Should the identifier be increment or not? Which is easier to design? Pros and cons?
16+
* 不能,那样容易被破解,比如爬虫直接按ID递增的顺序一个个抓即可。
17+
*
18+
* 3. Mapping an identifier to an URL and its reversal - Does this problem ring a bell to you?
19+
*
20+
* 4. How do you store the URLs? Does a simple flat file database work?
21+
* 采用分布式,负载均衡随机分发到一台机器,KV数据库,以短网址为key,长网址为value
22+
*
23+
* 5. What is the bottleneck of the system? Is it read-heavy or write-heavy?
24+
* 读显然比写多,比如用户在微博分享了一个资源,以短链接的形式。很多用户访问这个链接,则读远大于写。
25+
*
26+
*
27+
* 6. Estimate the maximum number of URLs a single machine can store.
28+
*
29+
* 7. Estimate the maximum number of queries per second (QPS) for decoding a shortened URL in a single machine.
30+
*
31+
* 8. How would you scale the service? For example, a viral link which is shared in social media could result in a peak QPS at a moment's notice.
32+
*
33+
* 9. How could you handle redundancy? i,e, if a server is down, how could you ensure the service is still operational?
34+
* 一致性哈希,虚拟节点
35+
*
36+
*
37+
* 10. Keep URLs forever or prune, pros/cons? How we do pruning?
38+
*
39+
* 11. What API would you provide to a third-party developer?
40+
* encode, decode
41+
*
42+
* 12. If you can enable caching, what would you cache and what's the expiry time?
43+
* KV db, key为short url,value为long url
44+
*
45+
*
46+
* 13, 如何防攻击?假如有人大量发相同的url耗光
47+
* 限制IP;一台KV服务器做缓存,key为long url,value为短url,如果缓存中有直接返回,cache是LRU的
48+
*
49+
*
50+
*/
51+
52+
53+
/**
54+
* 可参考https://segmentfault.com/a/1190000006140476
55+
*/
56+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.inuker.solution.system;
2+
3+
/**
4+
* Created by liwentian on 2017/10/17.
5+
*/
6+
7+
public class Info {
8+
/**
9+
* 可参考https://www.gitbook.com/@soulmachine
10+
*/
11+
}

0 commit comments

Comments
 (0)