Detailed Component Design
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
- If we want to scale this, we could add a load balancer and that maps requests for servers. Maybe assign to server based on shortest queue
- For the database, if this is getting sufficiently large, we could use sharding to make it easier to retrieve data. We would probably want to shard by tinyurl so the system can route directly based on a GET request since that's what we're optimizing for
- We want to cache the most frequently requested urls across the whole system, not just the user level. You could even cache geographically, since we're using a CDN you can cache the most relevant URLs in say the EU on a CDN in the EU
- We can update the cache whenever a shortening service is used to update an existing URL by storing the IDs of cached objects and then quickly reading if the ID of the updated URL is contained in the cache, if so update the alias URL in the cache
- We can refresh the cache every 4-6 hours in case a specific website is starting to go viral. In times of mega virality, we can also create a workflow that automatically adds to cache if get requests go above X in a given hour (after accounting for rate limiters and bad actors)
- Given that we want high availability, we will also want redundancy. I'm assuming that the CDN and server is where we want the most redundancy. We can also add some redundancy on the databases
- ID generation and shortening service
- Quickly check for duplicates and use a hashing function to make sure default urls are not predictable
- We can use different random seeds to limit the odds that a duplicate shortened url is generated in times of high demand