feat: implement horizontal scaling optimizations for authz service
- Add /health and /ready endpoints for load balancer health checks - Replace in-memory JWT token cache with Redis for multi-replica support - Reduce DB connection pool from 100 to 25 connections per replica - Add distributed rate limiting (100 req/min + 20 burst) using Redis - Implement circuit breakers for DB and Redis to prevent cascading failures This enables the service to scale horizontally with multiple replicas behind a load balancer without exhausting database connections or maintaining separate token caches per instance.
This commit is contained in:
+9
-1
@@ -10,8 +10,16 @@ import (
|
||||
)
|
||||
|
||||
func SetupRoutes(router *mux.Router, db *sql.DB) {
|
||||
// Health check endpoints (no auth required)
|
||||
router.HandleFunc("/health", handlers.HealthHandler).Methods("GET")
|
||||
router.HandleFunc("/ready", handlers.ReadyHandler).Methods("GET")
|
||||
|
||||
// Rate limit configuration
|
||||
rateLimitConfig := middleware.DefaultRateLimitConfig()
|
||||
rateLimiter := middleware.RateLimiterMiddleware(rateLimitConfig)
|
||||
|
||||
authRoutes := router.PathPrefix("/v1/auth").Subrouter()
|
||||
authRoutes.HandleFunc("/check", middleware.JWTAuth(handlers.AuthorizeHandler)).Methods("POST")
|
||||
authRoutes.HandleFunc("/check", rateLimiter(middleware.JWTAuth(handlers.AuthorizeHandler))).Methods("POST")
|
||||
|
||||
router.PathPrefix("/swagger/").Handler(httpSwagger.WrapHandler)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user