How minhthong1410/realtime_ranking works
Main Components
a. Entry Point/Command:
• Cmd/ directory and its main.go file, which serves as the starting point of the service.
• Top-level main.go as another starting entry if applicable.
b. API Layer:
• Internal/app/api package which includes the API entry points (router, error handling, etc.).
• Clearly denote the API routes and endpoints that will serve requests.
c. Handlers:
• Internal/handler package, particularly the components like ranking.go and error.go, which process business logic and implement real-time ranking.
d. Middleware:
• Pkg/middleware package - error_handler.go, log.go, and recovery.go. These are responsible for handling cross-cutting concerns such as error recovery, logging, and consistent error responses.
e. Utilities:
• Pkg/httputil for JSON handling and building standard HTTP responses.
• Pkg/logutil to centralize logging functionalities.
f. Data Layer / External Service:
• Pkg/redis as the component managing connectivity with Redis – a key element for real-time ranking where fast access and in-memory operations are likely critical.
Relationships and Interactions
• Client requests (HTTP) enter the system through the API layer.
• The API router directs the requests to the appropriate handlers (for ranking or error management).
• Handlers perform the business logic, including interacting with the Redis client from pkg/redis to update/read real-time ranking data.
• Middleware intercepts each request, providing logging, error handling, and recovery from any runtime exceptions.
• Utility packages (httputil and logutil) support the flow by managing HTTP responses and logs respectively.
Architectural Patterns and Design Principles
• The project follows a modular microservice design, separating concerns between command entry, API management, business logic (handlers), and cross-cutting middleware/utilities.
• There is a clear separation between the application layer (internal/app/api) and the utility/helper functions (pkg) ensuring reusability and maintainability.
• Using Redis for real-time ranking emphasizes a design optimized for fast, in-memory data operations and responsiveness.
Technologies and Frameworks
• Go as the primary programming language.
• Redis for data storage and retrieval pertinent to ranking logic, as indicated by pkg/redis.
• Standard Go packages for HTTP server functionalities, enhanced and structured by custom middleware implementations.