Functional Requirements:
tinyurl.com/myalias)Non-Functional Requirements:
Let’s assume:
Storage:
POST /api/shorten
Body: { longUrl: "https://...", customAlias?: "myalias", expireAt?: "2025-12-31" }
Response: { shortUrl: "https://tinyurl.com/abc123" }
GET /:shortCode
Redirects to the original long URL
GET /api/analytics/:shortCode
Response: { clicks: 12345 }
Schema (Relational / NoSQL hybrid example):
| FieldTypeNotes | ||
| short_code | String (PK) | Unique 6-8 char code |
| long_url | String | Original URL |
| created_at | Timestamp | Creation time |
| expire_at | Timestamp | Optional expiration |
| click_count | Integer | For analytics |
Indexes:
short_code → fast lookupexpire_at → periodic cleanupComponents:
Shorten Flow:
Redirect Flow:
Analytics Flow:
a) Short Code Generator
b) Cache Layer (Redis)
short_code → long_url mappingsexpire_atc) Analytics Service
DB failure: Use master-slave, replication, backups
Cache failure: Fallback to DB, rebuild cache on access
Hot key (popular short code): Use cache, sharded counters
Code collision: Check DB, retry generation
Network partition: Favor availability on reads, quorum writes for consistency
API abuse (spam): Add rate limits, CAPTCHA, user auth
Use CDN edge caching for global low-latency redirects
Add user accounts, link management dashboard
Support QR code generation
Add AB testing for link targeting
Use a distributed ID generator (e.g., Twitter Snowflake)
Cross-region replication for disaster recovery