Overview
Redis serves two roles:
- Rate limiting — replace per-process in-memory limiter with a shared Redis counter so limits work correctly across multiple server instances
- Notification cache — cache recent notifications per user to skip DB reads on hot list endpoints
Motivation
The current in-memory rate limiter resets on every instance restart and does not share state across replicas. Under horizontal scaling, each replica has its own limit — a client can exceed the intended rate by hitting different instances.
Work Items
Rate Limiting
middleware/redis_rate_limit.go — RedisRateLimit() using go-redis/redis_rate
- Replace
ipRateLimiter middleware in router/router.go
Notification Cache
storage/redis/notification_cache.go — read-through/write-through cache wrapping NotificationRepository
- Cache invalidation on
MarkRead, DeleteNotification, SendNotification
Config additions
REDIS_ADDR=redis:6379
REDIS_PASSWORD=
REDIS_DB=0
REDIS_CACHE_TTL=60s
Wire-up
rdb := redis.NewClient(&redis.Options{Addr: cfg.RedisAddr})
notifRepo := sqlite.NewNotificationRepo(database)
cachedRepo := rediscache.NewNotificationCache(notifRepo, rdb, cfg.RedisCacheTTL)
// pass cachedRepo to NotificationService
Depends on
#20 (repository interfaces), #21 (service layer)
Ref: docs/enhancementv1.md — Future Integration: Redis
Overview
Redis serves two roles:
Motivation
The current in-memory rate limiter resets on every instance restart and does not share state across replicas. Under horizontal scaling, each replica has its own limit — a client can exceed the intended rate by hitting different instances.
Work Items
Rate Limiting
middleware/redis_rate_limit.go—RedisRateLimit()usinggo-redis/redis_rateipRateLimitermiddleware inrouter/router.goNotification Cache
storage/redis/notification_cache.go— read-through/write-through cache wrappingNotificationRepositoryMarkRead,DeleteNotification,SendNotificationConfig additions
Wire-up
Depends on
#20 (repository interfaces), #21 (service layer)
Ref: docs/enhancementv1.md — Future Integration: Redis