Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 

Repository files navigation

URLDN — System Design: URL Shortener

A modern system design case study for building a scalable URL shortening service like Bitly or TinyURL.

This project focuses on designing a high-performance distributed system capable of handling millions of redirects, analytics events, and URL generations at scale.


Overview

URLDN demonstrates the architecture and engineering decisions behind a production-grade URL shortener.

The system supports:

  • URL shortening
  • Fast redirection
  • Analytics tracking
  • Distributed scalability
  • High availability
  • Caching strategies
  • Database scaling

Problem Statement

Design a URL shortening service that:

  • Converts long URLs into short links
  • Redirects users efficiently
  • Handles massive traffic
  • Supports analytics
  • Maintains high availability

Example:

Input:
https://www.example.com/blog/how-to-build-distributed-systems

Output:
https://urldn.com/AbX91qK

Functional Requirements

URL Shortening

Generate short URLs from long URLs.


URL Redirecting

Redirect users instantly to the original URL.


Analytics

Track:

  • Click count
  • Country
  • Device
  • Browser
  • Referrer
  • Timestamp

Custom Aliases

Example:

https://urldn.com/github

Non-Functional Requirements

  • High scalability
  • High availability
  • Fault tolerance
  • Low latency redirects
  • Horizontal scaling
  • Reliability

Traffic Estimation

Write Traffic

100 million URLs/day
≈ 1157 writes/sec

Read Traffic

Assuming read/write ratio = 10:1

≈ 11,570 reads/sec

High-Level Architecture

Clients
   ↓
CDN / Cloudflare
   ↓
Load Balancer
   ↓
API Servers
   ↓
Redis Cache
   ↓
PostgreSQL
   ↓
Analytics Queue
   ↓
ClickHouse

API Design

Create Short URL

POST /api/v1/urls

Request:

{
  "longUrl": "https://github.com/lahcenassmira"
}

Response:

{
  "shortUrl": "https://urldn.com/AbX91qK"
}

Redirect URL

GET /:shortCode

Response:

301 Redirect
Location: https://github.com/lahcenassmira

URL Redirect Flow

Client Request
      ↓
Load Balancer
      ↓
Redis Cache Lookup
      ↓
Database Fallback
      ↓
301 / 302 Redirect

Database Design

URL Table

Column Type
id BIGINT
short_code VARCHAR
long_url TEXT
created_at TIMESTAMP

Analytics Table

Column Type
id BIGINT
short_code VARCHAR
country VARCHAR
browser VARCHAR
clicked_at TIMESTAMP

Hash Generation

Base62 Encoding

Characters used:

0-9
a-z
A-Z

Total:

62 characters

Base62 Example

ID: 12581231
↓
Base62: 4Fz91
↓
https://urldn.com/4Fz91

URL Creation Flow

1. User submits URL
2. Validate URL
3. Generate unique ID
4. Convert ID → Base62
5. Store in database
6. Cache in Redis
7. Return short URL

Caching Strategy

Redis stores:

shortCode → longURL

Example:

AbX91qK → https://github.com/lahcenassmira

Benefits:

  • Faster redirects
  • Reduced database load
  • Improved latency

Scaling Strategy

Stateless API Servers

Easy horizontal scaling behind load balancers.


Database Replication

Use read replicas for scaling reads.


Queue-Based Analytics

Process analytics asynchronously to keep redirects fast.


Security Considerations

  • Rate limiting
  • Spam protection
  • DDoS mitigation
  • URL validation
  • Bot detection

Tech Stack

Layer Technology
Backend Node.js + Express
Database PostgreSQL
Cache Redis
Analytics ClickHouse
Queue Kafka / RabbitMQ
Infrastructure Docker
CDN Cloudflare

Future Improvements

  • Smart redirects
  • Geo-routing
  • AI analytics
  • QR code generation
  • Edge redirects
  • Link expiration
  • Custom domains

Conclusion

URLDN demonstrates the design of a scalable distributed URL shortener capable of handling millions of requests efficiently.

This project explores:

  • Distributed systems
  • Database scaling
  • Caching
  • System reliability
  • API design
  • High-performance architectures

Built for educational and system design learning purposes.

About

A scalable system design implementation of a URL shortening service like Bitly , urldn , tinyurl, featuring Base62 encoding, Redis caching, distributed ID generation, and analytics pipeline for high-traffic redirect systems.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors