POST /shorten
body: {
longUrl : "https://example.com/sdfsdfsdfsdf"
}
GET /shorten => to retrieve short code for long urls
POST /users
body: {
userid,username,email,password ...etc
}
GET /users/{userid} => to fetch information of user
GET /{short code} => redirection to long url destination
components includes
clients
api gateway
rate limiters
servers(shortening server and redirecting server)(microservice architecture)
load balancers
cache
database
the client first provides a long url and sends that url in request body to backend
the api gateway forwards the request to shortening service server. the server uses appropriate cryptographic algorithm(sha256 and base62) to generate a unique code
then the server will store the unique code in database as well as cache
the generated short code is returned back to the user
once the user sends request with the short code the request is forwarded to redirecting service server which fetches the corresponding long url and redirects the user to it
+microservice architecture is used so that the redirecting service can scale independently , it will help to handle the different read and write ratio