Back to Work
Anushanga - High-Performance URL Shortener Microservice
Production-Grade URL Shortening Service
GitHub Repository: SamvetaOrg/anushanga
Tech Stack
- Backend: Go 1.25
- Database: MongoDB
- Caching: Redis
- Containerization: Docker
- Cloud Ready: AWS-Ready Architecture
Project Overview
Engineered a production-grade URL shortening microservice using Go with clean architecture principles. The service features distributed ID generation, high-performance caching, comprehensive analytics, and is architected for horizontal scalability with AWS deployment readiness.
Key Technical Achievements
Distributed ID Generation
- Custom Snowflake Algorithm: Implemented 64-bit distributed ID generator
- 41-bit Timestamp: Millisecond precision for time-based ordering
- 10-bit Machine ID: Supports up to 1,024 unique nodes
- 12-bit Sequence: Generates 4,096 IDs per millisecond per node
- Base62 Encoding: Collision-free short codes with URL-safe characters
- Guaranteed Uniqueness: No collisions across distributed instances
High-Performance Caching
- Redis-backed LRU Cache: Intelligent caching with automatic eviction
- Read-through Pattern: Automatic cache population on cache miss
- 80%+ Query Reduction: Dramatically reduced database load
- Sub-millisecond Response: ~0.5ms average response time (vs 5-15ms without cache)
- 10-30x Faster: Significant performance improvement over direct database queries
Asynchronous Processing
- Asynq Task Queue: Built robust background job processing system
- Worker Pools: 5 concurrent workers for parallel task execution
- 1000-job Queue Capacity: High-throughput task buffering
- Email Delivery: Asynchronous email notifications
- Click Synchronization: Batched click data persistence from Redis to MongoDB
- 50-250x Higher Throughput: 10,000+ clicks/second processing capability
Comprehensive Analytics
- Real-time Click Tracking: Redis counters for instant click recording
- Unique Visitor Detection: IP-based and cookie-based visitor tracking
- Device Detection: Automatic device type identification (mobile, tablet, desktop)
- Browser Detection: User agent parsing for browser analytics
- Geographic Data: IP-based location tracking
- Aggregated Metrics: Time-series analytics with daily/weekly/monthly views
Advanced Features
- JWT Authentication: Secure token-based user authentication
- Password-protected URLs: Optional password protection for sensitive links
- QR Code Generation: Dynamic QR code creation with customization options
- Custom Short Codes: User-defined vanity URLs
- Link Expiration: Time-based URL expiration
- Rate Limiting: Token-bucket algorithm for API protection
Technical Highlights
Architecture & Design
- Clean Architecture: Separation of concerns with clear layer boundaries
- Dependency Injection: Loose coupling and testability
- Interface-driven Design: Easy mocking and testing
- Repository Pattern: Abstracted data access layer
- Service Layer: Business logic encapsulation
Performance Optimizations
- Connection Pooling: Efficient database and Redis connection management
- Batch Operations: Grouped database writes for improved throughput
- Index Optimization: Strategic MongoDB indexes for fast queries
- Memory Efficiency: Careful memory allocation and garbage collection tuning
- Goroutine Management: Controlled concurrency to prevent resource exhaustion
Scalability Features
- Stateless API Design: No server-side session state for easy horizontal scaling
- Distributed ID Generation: Unique IDs across multiple instances
- Redis Cluster Support: Ready for distributed caching
- MongoDB Sharding: Prepared for data partitioning
- Load Balancer Ready: Health checks and graceful shutdown
AWS Deployment Architecture
- ECS Fargate: Serverless container deployment
- DocumentDB: MongoDB-compatible managed database
- ElastiCache: Managed Redis for caching and queues
- Application Load Balancer: Traffic distribution with health checks
- Auto-scaling: Metrics-based horizontal scaling
- CloudWatch: Monitoring and logging integration
Performance Metrics
Response Times
- Cache Hit: ~0.5ms average response time
- Cache Miss: ~5-15ms with database query
- 10-30x Improvement: Compared to non-cached operations
Throughput
- 10,000+ clicks/second: High-volume click tracking
- 50-250x Higher Throughput: Compared to synchronous processing
- 4,096 IDs/ms per node: Massive ID generation capacity
Scalability
- Horizontal Scaling: Add instances without code changes
- Multi-region Ready: Distributed deployment support
- High Availability: Redundancy and failover capabilities
Security Features
- JWT Authentication: Secure API access with token validation
- Password Protection: Bcrypt hashing for protected URLs
- Rate Limiting: Prevent abuse and DDoS attacks
- Input Validation: Comprehensive request validation
- SQL Injection Prevention: Parameterized queries
- XSS Protection: Output sanitization
Monitoring & Observability
- Structured Logging: JSON logs for easy parsing
- Metrics Collection: Prometheus-compatible metrics
- Health Endpoints: Liveness and readiness probes
- Distributed Tracing: Request tracing across services
- Error Tracking: Comprehensive error logging and alerting
Development Practices
- Go 1.25: Latest Go features and performance improvements
- Unit Testing: Comprehensive test coverage
- Integration Testing: End-to-end API testing
- Docker Multi-stage Builds: Optimized container images
- CI/CD Ready: Automated testing and deployment pipelines
- Code Documentation: Clear comments and API documentation
Key Innovations
- Custom Snowflake Implementation: Tailored for URL shortening use case
- Hybrid Caching Strategy: Redis + MongoDB for optimal performance
- Asynchronous Analytics: Non-blocking click tracking at scale
- Production-ready Architecture: Battle-tested patterns and practices
This project demonstrates deep expertise in building high-performance, scalable microservices with Go, featuring advanced distributed systems concepts, performance optimization, and production-ready architecture.