very fast translation between shorten link to real.
one to one unique values. no duplicates.
maximum availability.
avoid harmful links shorting.
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
create path - recieves target long endpoint - validate the url is ok and legit. generates shorthen url that does not exists in db and locks the redis from generate it again.
travel to path - the endpoint user enters with shorten endpoint. recall the full endpoint and redirect
postgres - hold the data about users, links, or any metadata.
each shorten link will hold in its row the full link, created by... and the last free shorten link before next link by alphabetic. - connected list.
the will be a view - can be splited of links where the last free is not current.
redis- will hold key value of shorten link, full link.
redirecter service - read only from redis for speed. get the request with shorten url, logs for data and keeps for statistic, and redirects to full url.
Register link service - verify its reliable. and exists. if the long url exist - return shorten. using the user asked for, timestamp, and full url its choosing a random existing shorten where its next alphabetic is not tight. choose a random short string between chosen to last free and try create it as new row in postgres - if success - let the user know its new shorten and update the connected list.. if fail because of duplicate do it again. if fail more than x times alert administrators.
update redis
a cron will validate the all urls are still legit and free them if not - and update connected list. and update redis
a external users and payment service.
for fututre - partition in postgres by first letter
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...
directer service - read only from redis for speed. get the request with shorten url, logs for data and keeps for statistic, and redirects to full url.
Register link service - verify its reliable. and exists. if the long url exist - return shorten. using the user asked for, timestamp, and full url its choosing a random existing shorten where its next alphabetic is not tight. choose a random short string between chosen to last free and try create it as new row in postgres - if success - let the user know its new shorten and update the connected list.. if fail because of duplicate do it again. if fail more than x times alert administrators.
update redis