How imokkkk/short-link-generator works
Main Components
• Client Interface / Web Layer:
• Represented by the "short-link-web" module.
• Contains the Application entry point, controllers (e.g., UrlController), static resources (HTML, CSS, JS), and REST endpoints to facilitate URL conversion.
• Core Service Layer:
• Found in the "short-link-core" module.
• Includes application configuration, aspect modules for rate limiting (RateLimiterAspect), background jobs (e.g., ShortURLReceiverJob, shortURLSendJob) and other business logic (e.g., UrlService and its implementation).
• Contains integration components with Redis, Kafka, and scheduling tasks for URL preloading.
• Data Access Layer:
• Located in the "short-link-dal" module.
• Responsible for interacting with the database (e.g., UrlMapper, SQL mappings in UrlMapper.xml, and the init.sql script).
• Common Utilities/Shared Library:
• The "short-link-common" module carries shared utilities and constants (e.g., CommonConstant, ShortUrlUtil), exception handling, response models, and helper classes (such as the BloomFilterUtil).
• Incoming HTTP requests are routed to the web layer (short-link-web) where a controller (UrlController) accepts a long URL conversion request.
• The web layer calls into the core service layer (UrlService/UrlServiceImpl) for business logic to generate or retrieve a short URL.
• The core layer uses the data access layer (short-link-dal) to persist or retrieve URL records from the database.
• The pre-generated URL pool mechanism (via LinkedBlockingQueue) is managed by a dedicated background thread that monitors queue size. When the URL pool drops below a threshold (e.g., 200 URLs), it triggers the reload from the database.
• Asynchronous operations using Kafka are used for multi-threaded, decoupled persistence when pre-generated URLs are saved.
• Redis is integrated to apply a Bloom filter for efficient and near-real-time duplicate checks.
• Additional configuration and resilience (via SpringCloud Config and Resilience4j) ensure dynamic updates and concurrency control.
Architectural Patterns and Design Principles
• Layered architecture to enforce separation of concerns: presentation (web), business logic (core), and persistence (dal).
• Modular design (using Maven multi-module structure) to separate concerns and encourage maintainability.
• Asynchronous data processing via message queues (Kafka) to decouple processes.
• Use of caching and filtering (Redis and Bloom filters) to improve performance and reduce collisions.
• Background task scheduling and monitoring for the URL pool (using a dedicated thread and queue mechanism).