Scale estimate - 1B short url created and 100M DAU
// Create short url
Request - {
longUrl,
expiration?,
alias?
}
Response - {
shortUrl
}
// Redirect to long url using short url
Response - HTTP 302 redirection to long url
When the system receives request to create short url, it first hits API gateway, api gateway implements rate limitation to prevent attacks and keep system usage fair. The request is then routed to Load balancer which routes request to the write server and writer server is where we would have logic to generate short urls and ensure its uniqueness, we will use a global counter with base62 encoding for that, to be discussed in detailed in deep dive section. It would then save the long url, short url and expirationg and any alias used to the database.
Subsequently, when a read request comes in, it follows the same path to Load balancer, which then is recieved by the read server. Read server first checks cache if cache hit then ti will return response to redirect user to long url, if cache miss then it goes to DB to fetch the data. We will use Redis and LRU cache for low latecny and higher read throghput.
We will first talk about URL uniqueness first as this is the most critical part of the system.
Second we need to ensure is high read throghput, our sytem is read heavy so our system should be handle it efficiently