How moband/minyurl works
Project Type and Purpose
• MinyUrl is a containerized, microservice‐style URL shortener service.
• It exposes a REST API, internally structured in layers (Controller → Service → Repository), uses Redis for caching, MongoDB for durable storage, and NGINX for load‐balancing.
Top‐Level System Components
a. HTTP Clients – consumer of the API (e.g., curl, browser, other microservices)
b. NGINX Load Balancer – routes incoming HTTP(S) to the MinyUrlService containers
c. MinyUrlService – Spring Boot application packaged in Docker
• Controller Layer (ShortUrlController)
• Service Layer (ShortUrlServiceImpl, WorkerStatusServiceImpl, etc.)
• Repository Layer (Spring Data MongoDB repositories)
• Cross‐cutting Aspects (LoggingAspect, Retry, DuplicateKeyExceptionAspect)
• Utility modules (Base58 encoder, ResponseUtil, GlobalConstants)
• Configuration (CacheConfig, AspectsConfig)
d. Redis Cache – stores recently accessed short→long mappings and/or counters
e. MongoDB – stores persistent documents: ShortUrl, WorkerStatus, PartitionStatus, embedded Stats
Interactions and Data Flows
• “Shortify” Request:
1. Client → NGINX → one of MinyUrlService instances
2. Controller receives JSON NewLinkDto → invokes Service
3. Service checks for key conflicts (via DuplicateKeyAspect), generates Base58 code, persists ShortUrl document in MongoDB, optionally primes Redis cache
4. Controller returns JSON BaseResponse with the short code
• “Resolve” Request:
1. Client → NGINX → MinyUrlService
2. Controller maps path variable (KEY) → Service
3. Service queries Redis cache (CacheConfig).
• Hit: return URL, increment in‐memory counter or Stats.
• Miss: fetch from Mongo, update cache, update stats in Mongo, return URL
4. NGINX or application performs HTTP redirect to the long URL
• “Stats” Request:
1. Client → NGINX → MinyUrlService
2. Controller returns aggregated MonthlyVisitsReport and embedded BrowserStats, OsStats, DateStat from Mongo
Architectural Patterns & Principles
• Layered Architecture (Controller → Service → Repository)
• Aspect‐Oriented Programming for cross‐cutting concerns (logging, retry, exception handling)
• Cache‐Aside pattern (Redis sits alongside MongoDB)
• Dockerized microservice with externalized configuration (application.yml)
• Horizontal scalability (multiple MinyUrlService containers behind NGINX LB)