I am thinking of two services-
User can
How big should the shortened URL be?
If we only consider a-z and A-Z and 0-9, we can do a BASE 62 conversion
We need to evaluate the capabilities of our service on various dimensions.
Do we have any other requirements?
Are we storing analytics for the url.
We are thinking 2k requests per second. Let's design for peak load of 2500-3000 requests per seconds.
This will retrieve the original URL and redirect to it. Reponse code 301 and for collecting analytics we shoud use 302
We need a rate limiter to prevent DDOS attacks etc and a load balancer to handle increase in traffic
HTTP 404 for expired links and invalid links
we can use a key value database enforcing a hashmap.
we can take a hybrid approach and use potgres sql for relational data and reporting and mongodb for high write thoroghput
If you look at the diagram, we can have a cache like redis or memcache to spped up reads
Proposed schema
original_url
shortened_url
created_time
expiry_time
we can use a timeseries database influxdb or TimeScaleDB for storing analytics data
We can include a UUID generator for which we can use snowflake IDs for each URL and apply a BASE 62 conversion on it and store it in database.
This handles collissions.
for analytics reports, we need to denormalize the data and store it in precomputed aggregated tables for faster reads
this is a read heavy system and so we need to have sharding and read replicas in place for availability
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?