Design URL Shortener
MetaTechnicalDifficulty: Medium
Share on
Ready to answer it out loud?
Run a mock interview on this exact question and get instant AI feedback.
Question Explain
Design a URL shortening service like TinyURL.
Requirements:
- Convert long URL to short URL
- Support custom short URLs
- Handle high traffic
- Analytics tracking
- URL expiration
Example: Long URL: https://www.example.com/very/long/path Short URL: http://tiny.url/abc123
Answer Example
URL Shortener System Design:
-
Architecture Components:
- Load Balancer
- Application Servers
- Database (Primary-Secondary)
- Cache Layer (Redis)
- Analytics Service
-
Core Services:
interface URLShortener {
shorten(longUrl: string): string;
redirect(shortUrl: string): string;
customize(longUrl: string, customPath: string): string;
}
class URLService implements URLShortener {
private readonly baseChars: string;
private readonly redis: Redis;
private readonly db: Database;
async shorten(longUrl: string): Promise<string> {
const id = await this.generateUniqueId();
const shortPath = this.encode(id);
await this.store(shortPath, longUrl);
return this.baseUrl + shortPath;
}
}
- Database Schema:
CREATE TABLE urls (
id BIGSERIAL PRIMARY KEY,
short_path VARCHAR(10) UNIQUE,
long_url TEXT NOT NULL,
user_id UUID,
created_at TIMESTAMP,
expires_at TIMESTAMP,
click_count INTEGER DEFAULT 0
);
-
Key Features:
- Base62 encoding
- Collision handling
- Rate limiting
- Analytics tracking
- Cache management
-
Scalability:
- Horizontal scaling
- Database sharding
- CDN integration
- Cache invalidation
Company Context (Meta):
- Focus on scalability
- Real-time analytics
- Global distribution
- Privacy considerations
Related Interview Questions
Knowledge of storage architectures and types
AmazonMedium
Merge Two Sorted ArraysGoogleEasy
Basic String ManipulationAdobe
Investment Portfolio OptimizationGoldman SachsMedium
Can you share an example of using innovative problem-solving skills to overcome a major work challenge?GoogleHard
How would you implement a custom authentication mechanism for a new AEM feature while adhering to AEM's security best practices?PwCHard
What strategies help you solve complex technical problems under pressure?eBayHard
Cybersecurity SolutionsMetaHard