Course Content
Data Structures & Algorithms
Full Stack Web Development
Understanding and playing with DOM (Document Object Model)
0/2
MERN project
0/2
Low Level System Design
LLD Topics
High Level System Design
Fast-Track to Full Spectrum Software Engineering
1. What is TinyURL?

TinyURL is a URL shortening service that converts long URLs into short, easy-to-share links. When users enter a short URL, the system redirects them to the original long URL.



2. What are the key functional requirements of TinyURL?

Shorten a URL – Convert a long URL into a short one.
Redirect to Long URL – Retrieve and redirect users when they visit a short URL.
Custom Short URLs (Optional) – Allow users to create custom aliases.
Expiration Feature (Optional) – Set an expiration time for URLs.
Analytics (Optional) – Track the number of visits, location, and referrers.


3. What are the key non-functional requirements?

Scalability – Handle millions of URL requests efficiently.
High Availability – Ensure the service is always up and running.
Low Latency – Short URL resolution should be fast (<10ms).
Security – Prevent spam, abuse, and unauthorized URL generation.


4. How does TinyURL generate a short URL?

Base62 Encoding – Converts a unique database ID into a short alphanumeric string (e.g., XyZ123).
Hashing (MD5/SHA-256) – Hashes the long URL to generate a unique identifier.
Random String Generation – Generates a random 6-10 character identifier and checks for uniqueness.



5. How does TinyURL handle collisions when generating a short URL?


If a randomly generated string already exists, the system retries with a new string.
Hashing with a timestamp or salt ensures uniqueness.
Incremental ID + Base62 Encoding guarantees unique short URLs.



6. How does the system store URL mappings?


The system stores short URLs in a database with the following schema:

short_id long_url created_at expires_at (optional)
XyZ123 https://example.com/abc 2025-03-01 2025-06-01


7. What database should be used for TinyURL?


SQL (MySQL/PostgreSQL) – For relational data and indexing.
NoSQL (DynamoDB, Cassandra, MongoDB) – For high scalability and distributed storage.
Redis/Memcached – Used for caching frequently accessed URLs.



8. How does TinyURL handle redirections?


User enters a short URL (e.g., https://tinyurl.com/XyZ123).
The system looks up XyZ123 in the database or cache.
If found, it returns a 302 redirect to the long URL.
The user is taken to the original website.



9. How can TinyURL scale to handle millions of requests?


Load Balancers distribute traffic across multiple servers.
Database Sharding splits data across multiple databases.
Caching (Redis/Memcached) stores frequently accessed URLs to reduce DB queries.
CDN (Cloudflare, AWS CloudFront) speeds up global access.



10. What are the key security concerns in TinyURL?


Rate Limiting – Prevents spam and automated abuse.
Blacklist Malicious URLs – Avoids shortening phishing/malware links.
User Authentication – Ensures only authorized users create custom URLs.
SSL/TLS Encryption – Secures communication between clients and the server.



11. How does TinyURL handle expired URLs?


The system stores an expiry date for each URL.
When a short URL is accessed, the system checks if it is expired.
If expired, it returns a 404 Not Found or a custom error page.



12. What are some advanced features that can be added to TinyURL?


Analytics Dashboard – Track visits, locations, and referrers.
Custom Short URLs – Users can choose their own short links.
Bulk URL Shortening – Allow users to shorten multiple URLs at once.
QR Code Generation – Generate QR codes for short URLs.
API Access – Provide developers with an API to create short links programmatically.



13. What APIs are needed for TinyURL?

 

Shorten URL API
 
POST /shorten
{
"long_url": "https://example.com/page",
"custom_alias": "myLink" (optional),
"expiry_date": "2025-01-01T00:00:00Z" (optional)
}

 

Response:
 
{
"short_url": "https://tinyurl.com/myLink"
}

 

Redirect API
 
GET /XyZ123

Response:

  • 302 Redirect to the long URL.


Analytics API (Optional)

GET /analytics/XyZ123

Response:
 
{
"clicks": 500,
"geo_distribution": { "USA": 60%, "India": 25%, "Others": 15% },
"top_referrers": ["google.com", "facebook.com"]
}


14. What are the storage requirements for TinyURL?
 
  • 50M new URLs/month600M URLs/year
  • Each short URL requires 7 bytes (Base62 encoding).
  • Estimated Storage: ~ 10-20TB for 5 years.


15. What are some alternatives to TinyURL?


Bit.ly – URL shortening with analytics.
Google Firebase Dynamic Links – Smart URL shortening.
Rebrandly – Custom branded short links.
Ow.ly – Integrated with Hootsuite for social media tracking.



16. How can TinyURL ensure high availability?


Database Replication – Use read replicas to distribute queries.
Failover Strategy – Deploy multiple servers across regions.
CDN Caching – Store short URLs in global edge locations.
Auto-Scaling – Automatically adjust capacity based on traffic.



17. What happens if the database fails?


Use a replicated database (Master-Slave).
Implement automatic failover to a backup DB.
Cache URLs in Redis/Memcached to reduce DB dependency.



18. How to prevent brute force attacks on short URLs?


Rate limiting to restrict excessive requests.
IP-based throttling to block suspicious activity.
Hash-based URL generation to prevent predictable short URLs.



19. How does TinyURL handle duplicate URLs?


Store a hash of the long URL and check before creating a new short URL.
If the URL already exists, return the existing short link instead of creating a new one.



20. What are some challenges in designing TinyURL?


Handling Billions of Requests – Scaling efficiently.
Database Growth – Managing massive URL mappings.
URL Expiry & Cleanup – Deleting old, unused URLs.
Security & Abuse Prevention – Blocking malicious URLs.

0% Complete
WhatsApp Icon

Hi Instagram Fam!
Get a FREE Cheat Sheet on System Design.

Hi LinkedIn Fam!
Get a FREE Cheat Sheet on System Design

Loved Our YouTube Videos? Get a FREE Cheat Sheet on System Design.