Skip to content

feat: add Redis adapter for distributed rate limiting and notification cache #32

Description

@deannos

Overview

Redis serves two roles:

  1. Rate limiting — replace per-process in-memory limiter with a shared Redis counter so limits work correctly across multiple server instances
  2. 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.goRedisRateLimit() 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions