List the key functional requirements for the system (Ask the AI for hints if stuck)...
User should be able to create new Shortened URLs
Redirect the shortened URLs to the original URLs
Users should be able to delete, update the shortened URLs
Retain the short N URLs for five years.
List the key non-functional requirements (performance, scalability, reliability, etc.)...
The latency for the URL shortener re direction should be pretty low.
the availability of the service URL service should be pretty high
The service should scale for two hundred million URLs per month.
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
200 Million URLs per month x 12 months x 5 = 200 M x 60 = 12000 M = 12000 x 10^6 = 12 x 10^9 which is 12 Billion URLs over 5 years.
Let's assume the size of the URL is five hundred bytes 500 bytes X 12 Billion = 6000 x 10^9 = 6x10^12 = 6 TB of storage.
considering 1:100 ratio for write to reads
200 Million x 100 = 20 Billion
Two hundred is a million per month. We have a different number of seconds in a month, which will give us the total queries per second, roughly it comes to eighty requests per second.
Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
post /shortenurl
request
{
data {
origianl URl:
user id:
}
}
response
{
shortenurl
}
I'll say a couple of post methods for updating and and a delete method to delete the Most of them will look similar where the request will have the original URL and the required shortened URL as well. And there is arrive and the response will be the shortened URL. For deleting it will be just delete.
Get /{short_code}
302 reponse
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
In this design we have a client which makes request is an ultra not to API gateway and URL shortener depends on the request type and does the following things for that it will look up in the cache and if the cache has the URL short not actually URL it will return that otherwise if it doesn't have it for any post update until it we have to do a crude operation for post we need to need to create the shortener and the short and URL will be added to a data store and also the cache so that it will be returned as a client so one somehow one of the things that we need to take deeper into here is always the short and the shortened key is generated the the the method I'm taking here is I'm using a sequencer this sequencer should not be exposed directly because people can guess what's next and they will try to claim some of the skys instead what should we do in is we should be encoding the sequencer with a base 58 the base 10 in the sequencer will be base 10 and the and the encoding will be in base 58. The reason we are taking base 58 is because base 64 will have some characters that are overlapping For example for zero and oh for I and L so these are some of the characters that are confusing instead we take base 58 the way we can we create a base 58 key is depends on using the modulus operation like we do your modulus of the sequencing number and that will give us a reminder and putting the reverse order and then converting to base 58 by mapping towards the base 58 characters and that will give us the short N Url for reversing this we need to to We need to multiply number two the bills to the power of fifty-eight one sum of all of that number will be the sequence number. Also we need to be mapping the unique kind of allocations. so we will have two databases or two sequencing databases where one of it is unused and another one is used. So whenever a sequence is being used, we will move from unused to the used database. For this we need to be generating all the unique ideas and the unused tables. One advantage with converting base 58 and coding is it will always when we convert base 58 to base 10 it will always point to the same exact sequence number.
Define the data model. Identify the main entities, their attributes, and relationships. Consider the choice of database type (SQL vs NoSQL) and justify your decision based on access patterns...
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.