Design URL Shortener
Web ServiceEasy
Design a URL shortening service like TinyURL. This service will provide shortened URLs for any given long URL, making it easier to share and use.
Requirements
- Users should be able to enter a long URL and get a shortened URL.
- Clicking the shortened URL should redirect to the original URL.
- URLs should expire after a default timespan if not used.
- Users should optionally be able to pick a custom short URL.
- The service should track analytics like click counts, source referrers, etc.
Constraints
- The system should be highly available and scalable.
- URL redirections should happen in real-time with minimal latency.
- Shortened URLs should not be predictable.
- The service should handle millions of URLs.
Example Scenarios
A user submits a long URL: https://www.example.com/very/long/path/to/resource?param1=value1¶m2=value2
Key Considerations:
- How will you generate a unique short code?
- Where will you store the mapping between short and long URLs?
- How will you handle collisions if they occur?
- What happens if the service is restarted?
A user accesses a shortened URL that has expired.
Key Considerations:
- What HTTP status code should be returned?
- Should users see a custom error page?
- Should the system allow reactivation of expired URLs?
Your Solution
Submission Guidelines
- • Include a high-level architecture diagram
- • Define system components and their interactions
- • Address scaling and reliability concerns
- • Explain trade-offs in your design decisions
- • Consider failure scenarios and how to handle them