Skip to content

Implement Redis Caching and Multi-layer Rate Limiting #8

Description

@anuja12mishra

Feature Request: Redis Caching & Rate Limiting for Blogic Backend

📌 Background

Currently, the Blogic backend interacts directly with MongoDB for every request.
There is no protection against high-frequency automated requests (DoS/DDoS) or abuse of the AI generation feature.

🎯 Goals

  • Improve response times for blog posts and comments using Redis caching.
  • Secure the API with global and AI-specific rate limiting.
  • Reduce database load and infrastructure costs.

🛠 Proposed Features

1. Redis Caching System

  • Cache all blogs and single blog details.
  • Cache comments for each blog post.
  • Implement automated cache invalidation on create, update, and delete operations to ensure data consistency.

2. Multi-layer Rate Limiting

  • Global API Limiter: Prevent DoS/DDoS attacks with a reasonable per-IP limit.
  • AI-Specific Limiter: Restrict high-cost Gemini AI calls (e.g., 5 requests per hour).

✅ Implementation Checklist

  • Set up Redis connection and configuration in the backend.
  • Create middleware for apiLimiter and aiLimiter using express-rate-limit.
  • Create a reusable cacheMiddleware for GET requests.
  • Integrate caching into Blog and Comment routes.
  • Add cache-clearing logic to Blog and Comment controllers.

📈 Expected Impact

  • Faster page loads for the frontend.
  • Decreased Mongoose/MongoDB resource consumption.
  • Enhanced security and cost control for AI features.

🔒 Priority

High – This feature directly impacts performance, scalability, and security.

🧩 Labels

enhancement backend performance security redis rate-limiting

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions