难度: easy
设计一个类似于TinyURL的短链接服务系统。该服务能生成简短的别名,用来重定向到原始的、更长的URL。著名的类似服务包括bit.ly、ow.ly和short.io。
难度: easy
estimated QPS = 100000000 / 24 / 60 / 60 = 1157
assuming each user generate 10 urls per day
QPS: 10 * 1157 = 11570
peak QPS estimation: 11570 * 2 = 23140
If we use alphanumeric, in total there are 26+26+10 = 62 characters for a single length
The total tiny url per day is 10 * 100 M = 1 T => 10^9
Assuming we keep the tiny url in our DB for 50 years
Then the total URL would be:
10^9 * 50 * 365 = 1.8 ^ 13
So the max length of tiny url could be: 62 ^ X > 1.8 ^ 13
X = 8
We can make the tiny url length as 8
url table
flowchart TD A[client] <--> B[Load balancer] <--> C[API Gateway] <--> D[Tiny URL service] <--> E[(URL DB)] D[Tiny URL service] <--> F[URL Cache]
URL generation
Tiny URL redirection
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?
得分: 10