Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
post /v1/shortenUrl
body:{
'url': 'example.com'
}
bearerToken: {
'userId': {uuid},
'scope': 'adminScope',
}
get /v1/getRedirectUrl/{uniqueCode}
# post /v1/refreshCache/{shortUrl}
# post /v1/refreshCache
post /v1/invalidateCache/{shortUrl}
Client hits the shortened url, goes through api gateway, gateway directs flow to fetchOriginalUrl service, service fetches original url from cache, and directly from postgresql database if not present in cache.
Client calls post request to shorten url, goes through api gateway, gateway directs flow to createOriginalUrl service, service generates shortened url, repository layer calls the database to store the shortened url and original url. Unique urls are created by hashing the original endpoint.
But hashing won't let new redirect urls to have the same shortened url
We will use a simple noSql database to store shortUrl and redirectUrl along with admin userId so that we know who is allowed to modify entry
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.