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 generate an unique, short URL and store the
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.
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.