A .NET Core URL shortening service with features like expiration, email notifications, and management.
Try it out: https://trimurl.sbs/
This repository contains the backend API that powers the live TrimURL service.
- URL shortening with custom expiration times
- Email notifications for expired URLs
- Renewal functionality
- Database cleanup and monitoring
- AWS SQS integration for background processing
- Redis caching
- Zookeeper for distributed coordination
git clone <your-repo-url>
cd ShortUrl-
Copy the environment template:
cp .env.example .env
-
Copy the settings templates:
cp ShortURL/appsettings.template.json ShortURL/appsettings.json cp ShortURL/appsettings.Development.template.json ShortURL/appsettings.Development.json
-
Edit
.envwith your actual credentials and configuration
You'll need to set up:
- MySQL Database - for data storage
- Redis - for caching
- Zookeeper - for distributed coordination
- AWS SQS - for background job processing
- Brevo Email Service - for email notifications
Edit your .env file with these required values:
| Variable | Description | Example |
|---|---|---|
DB_HOST |
MySQL host | localhost |
DB_PASSWORD |
MySQL password | your_password |
BREVO_EMAIL_KEY |
Brevo API key | xkeysib-... |
WEB_URL |
Your domain | https://yourdomain.com/ |
SQS_*_QUEUE |
AWS SQS queue URLs | See .env.example |
docker-compose up -dcd ShortURL
dotnet restore
dotnet runBase URL (Local Development): http://localhost:5000/
POST /url- Create short URLGET /url/{shortUrl}- Redirect to original URLGET /url/{shortUrl}/info- Get URL informationPATCH /url/{shortUrl}:renew- Extend URL expiration
# Create a short URL
curl -X POST https://trimurl.sbs/api/url \
-H "Content-Type: application/json" \
-H "X-User-Timezone: America/New_York" \
-d '{"url": "https://example.com", "emailAddress": "user@example.com"}'
# Get URL info
curl https://trimurl.sbs/api/url/abc123/info- .NET 8.0 or later
- MySQL
- Redis
- AWS account (for SQS)
- Brevo account (for emails)
dotnet ef database updatedotnet test- Set environment variables in your hosting platform
- Configure your database connection
- Set up AWS SQS queues
- Configure email service
- Deploy using your preferred method (Docker, Azure, AWS, etc.)
This codebase powers the live URL shortening service at https://trimurl.sbs/.
Detail Design Here
This service uses a custom Snowflake-based ID generator optimized for URL shortening:
- Worker ID Bits: 2 (supports 4 workers max)
- Sequence Bits: 2 (4 IDs per millisecond per worker)
- Timestamp: Unix milliseconds (remaining bits)
- Per Worker: 4,000 IDs per second
- Total System: 16,000 IDs per second (4 workers)
- 8-character Base62: ~218 trillion possible combinations
[Timestamp: 59 bits][Worker ID: 2 bits][Sequence: 2 bits]
Generated IDs are encoded using Base62 (0-9A-Za-z) to create short URLs:
- Character Set:
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz - Target Length: 8 characters
- Example: ID
123456789→8M0kX(Base62)
- Compact URLs: Base62 encoding produces short, readable URLs
- High Availability: Distributed worker IDs via Zookeeper
- No Collisions: Timestamp + Worker ID + Sequence ensures uniqueness
- Scalable: Can handle high-traffic URL shortening demands
- Time-ordered: IDs are roughly chronological for easier debugging
- Zookeeper: Manages worker ID assignment across multiple instances
- Worker Assignment: Each pod/instance gets a unique worker ID (0-3)
- Failover: If a worker goes down, its ID can be reclaimed by new instances
- Generate ID: Snowflake algorithm creates unique 64-bit ID
- Encode: ID converted to Base62 string (~8 characters)
- Store: Original URL mapped to short code in MySQL
- Cache: Frequently accessed URLs cached in Redis
- Serve: Short URL redirects to original URL