The API should have two endpoints:
Both of them accept a string of length
We need to run our algorithm on a server. We can scale up our server vertically, but this has a ceiling and also introduces a single point of failure. Assuming the API is popular, we might run into a DDoS attack, or our server might fail. Horizontal scaling is more resilient. Assuming there are not many repeated URLs, using a cache may not be appropriate. We can add a DB to store the long and short URLs, using a simple Cache strategy such as write-back, where we write directly to the DB and update the cache later. For the DB we can shard on a combination of top level domain and first character range of the domain. To make the configuration easier we can use a load balancer to balance the load between these DBs. Since DBs failing is not causing any issues to the end customers we prefer Availability over consistency. Probably replication strategy is an overkill in this case
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.