create a short link with random string for url
create a short link with custom string for url
contains expire time
create with sign in
List non-functional requirements for the system...
high availability
low latency
consistency
Estimate the scale of the system you are going to design...
use 6 hex string for short url
assume most link will be 100 characters long.
assume there will be 10000 active user creation per day, 100000 active url creation per day and 100 million views per day
so the esimation will be
storage = 100 * 100000 / 1024 / 1024 * 30 * 12 =3433 gb per year
6 * 100000 / 1024 / 1024 * 30 * 12 = 200 gb per year.
100 million view per day is about
100 * 1,000,000 / 24 / 60 / 60 = 1000 query per second.
Define what APIs are expected from the system...
/api/url/create post:{url, expireTime (optional), shortUrl (optional)}
/api/url/update post:{id, url, expireTime}
/api/url/{shortUrl} get
/api/user/signup post:{userInfo}
/api/user/login post:{userInfo}
URL Schema:
id, url, shortUrl, expireTime, createTime, uerId
User Schema:
id,
userName,
password
profile schema:
id,
....
userid
web client for user experience.
user create server,
auth server
url redirect server
database for user profile
database for url schema
user creation server can be down with leader follower because the write is fairely low and it offer a good consistency.
for redirect server, because it is write heavy, we can cache top popular links or use cdn to delivery those popular result, it will help us reduce latency in the mean time it will also save our budge because we only put top 20% of result in cdn. Cache is a good option because some link are always very popular. We don't always need to use a lot of number servers to handle the peak senario and our server is less likely to encounter such issue. so having a message queue to prevent such peak load is good enough.