POST api/v1/shorten
request body: longUrl
response: shortenUrl
GET api/v1/shorten/{shortUrl}
response: return 302 + longUrl
We need an API Gateway, so it can helps us with following topics:
URL Redirection Service: GET API request will handled by this service, it will use read-through fetch the cache to see if the short url there, if not, it will query DB (NoSQL) and store the pair in the cache.
URL Generator Service: POST API request will handled by this service, it will forward the request to id generator service to generate an unique, short URL and store the
Id generator: is a bunch of server, we can assign an id to each machine, we can generate a shorturl based on machine id + sequence number and base62(a-z, A-Z, 0-9).
NoSQL: we choose to use NoSQL as we don't need ACID in this design and NoSQL is easy to do horizontal scaling.
Cache: LRU cache.
We need an API Gateway, so it can helps us with following topics:
URL Redirection Service: GET API request will handled by this service, it will use read-through fetch the cache to see if the short url there, if not, it will query DB (NoSQL) and store the pair in the cache.
URL Generator Service: POST API request will handled by this service, it will forward the request to id generator service to generate an unique, short URL and store the
Id generator: is a bunch of server, we can assign an id to each machine, we can generate a shorturl based on machine id + sequence number and base62(a-z, A-Z, 0-9).
NoSQL: we choose to use NoSQL as we don't need ACID in this design and NoSQL is easy to do horizontal scaling.
Cache: LRU cache.