Requirements
List the key functional requirements for the system (Ask the AI for hints if stuck)...
用户能输入长链,能生成短链。相同长链尽可能对应相同的短链,相同的短链一定对应相同的长链。短链不能太长。用户访问短链时,我们找到对应的长链,并跳转到对应长链
List the key non-functional requirements (performance, scalability, reliability, etc.)...
生成100ms 延迟,访问 10ms,高可用,
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
延迟在 100ms 以内,qps 1m,每秒写入 100条,每天数据大小 10kb,每天新增 10gb 的内容?
Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
generatetheshortlink(long link)
getthelonglink(short link)
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
client access the load balancer, load balancer access the right server. server access the database.
Define the data model. Identify the main entities, their attributes, and relationships. Consider the choice of database type (SQL vs NoSQL) and justify your decision based on access patterns...
we could use the no sql database since there is no transactional requirement.
key is short url and value is long url.
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
in the server, once we get the url, we could sanitize the url. use the hash funciton to get the short url and save it to ddb and then return it to the server. 短链长度应该是固定的,所以我们只取 hash 结果的前几位,可以用 base64 加密?,同时检测该短链是不是已经有长链对应了,如果有就多取一位,或者自增一下。 当用户访问短链时,我们访问数据库得到对应的长链,返回给用户,带上跳转请求。如果不存在对应的长链就返回对应信息。为了缓解数据库压力,可以加上 server 端的 redis cache,同时加上读缓存和写缓存,