Skip to content

implement_redis_kafka_rate_limit#287

Closed
VaibhavA123 wants to merge 1 commit into
komalharshita:mainfrom
VaibhavA123:Implemen_High-Performance_Event_Driven_architecture
Closed

implement_redis_kafka_rate_limit#287
VaibhavA123 wants to merge 1 commit into
komalharshita:mainfrom
VaibhavA123:Implemen_High-Performance_Event_Driven_architecture

Conversation

@VaibhavA123

Copy link
Copy Markdown

Integration tests run locally against open infrastructure containers:

  • Redis sliding-window pipeline transactions executed cleanly.
  • Kafka producer successfully dispatched messages under 3ms.
  • Background worker correctly trimmed user history lengths down to exactly 20 elements using ZSET logic.
<!--
  Pull Request Template — DevPath
  --------------------------------
  Delete sections that do not apply.
  Every section marked [required] must be completed before review begins.
  PRs with empty required sections will be returned without review.
-->

## Summary [required]

This PR introduces a high-performance Event-Driven Architecture (EDA) to resolve critical latency bottlenecks and database stress caused by handling high-frequency user interactions (like activity logging and real-time metric tracking) inside the core application thread. By integrating Redis for a sliding-window rate limiter and a low-latency recommendation engine cache alongside Apache Kafka for asynchronous stream ingestion, the system decouples heavy tracking operations from the HTTP request-response cycle. This ensures sub-millisecond read capabilities for user suggestions while shielding backend infrastructure from API abuse and DDoS vectors.

## Related Issue [required]

Closes # [Insert your Issue Number here, e.g., #12]

## Type of Change [required]

- [ ] Bug fix — resolves a broken behaviour
- [x] Feature — adds new functionality
- [ ] Data — adds new projects to `data/projects.json`
- [ ] Documentation — updates docs, README, or code comments only
- [ ] Style — CSS or visual changes only, no logic change
- [ ] Refactor — restructures code without changing behaviour
- [ ] Test — adds or updates tests

## What Was Changed [required]

| File | Change made |
|------|-------------|
| `utils/redis_client.py` | Created a thread-safe Redis connection pool wrapper for Flask middleware and routes. |
| `utils/kafka_producer.py` | Configured a global, lazy-initialized Kafka Producer utility to dispatch interaction event payloads asynchronously. |
| `app.py` | Attached a `before_request` hook applying a Redis-backed Sliding Window Counter rate limiter on all `/api` routes. |
| `routes/main_routes.py` | Created `/api/suggestions` endpoints: `POST` routes handle immediate "fire-and-forget" event pushes to Kafka, while `GET` routes fetch cached history profiles. |
| `worker/package.json` | Set up configuration metadata and package metrics for the isolated background engine context. |
| `worker/kafka_consumer.py` | Created a standalone Python background stream process to consume Kafka logs, compute analytics, and update capped Redis Sorted Sets (`ZSET`). |

## How to Test This PR [required]

1. Clone this branch: `git checkout feat/event-driven-architecture`
2. Spin up your local infrastructure components (Redis on port `6379`, Kafka on port `9092`):
   ```bash
   docker-compose up -d

@vercel

vercel Bot commented May 18, 2026

Copy link
Copy Markdown

@VaibhavA123 is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:invalid This doesn't seem right gssoc-2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants