Build a URL Shortener

Real-World Projects Medium 100 points

Create a URL shortening service like bit.ly with analytics and custom domains.

Success Rate
0.0%
1 attempts

Problem Statement

Build a complete URL shortening service that includes:

1. **URL Shortening**: Convert long URLs into short, shareable links
2. **Custom Aliases**: Allow users to create custom short URLs
3. **Analytics**: Track clicks, referrers, and geographic data
4. **Expiration**: Support URL expiration dates
5. **API**: RESTful API for programmatic access

**Requirements:**
- Handle invalid URLs gracefully
- Prevent duplicate short URLs
- Implement rate limiting
- Store analytics data
- Support bulk URL creation

**Technical Specifications:**
- Use a database to store URLs and analytics
- Implement proper error handling
- Add input validation and sanitization
- Include unit tests
- Document your API endpoints

Examples

Input:

POST /api/shorten
{"url": "https://www.example.com/very/long/url", "custom_alias": "mylink"}

Output:

{"short_url": "https://short.ly/mylink", "original_url": "https://www.example.com/very/long/url", "clicks": 0}

Explanation:

API should return the shortened URL with metadata

Quick Actions

Challenge Statistics

Total Attempts 1
Success Rate 0.0%
Difficulty Medium
Points Reward 100

Supported Languages

Python Javascript Java Go

Tags

#web-development #api #database #analytics #real-world

Community Discussion

L
lisa_garcia 1 month ago Solution

Solution approach

Here's how I solved this challenge: 1. First, I analyzed the problem 2. Then I implemented the solution 3. Finally, I optimized it Hope this helps!

2 1
M
mike_wilson 1 month ago Solution

Optimization tips

You can optimize this solution by using a hash map instead of nested loops. This reduces time complexity from O(n²) to O(n).

3 2
A
admin 1 month ago Solution

Optimization tips

You can optimize this solution by using a hash map instead of nested loops. This reduces time complexity from O(n²) to O(n).

2 2
J
jane_smith 1 month ago

Edge case question

What happens when the input is empty? Should we handle this case?

5 0