Skip to content

[SECURITY] Implement Request Deduplication and Cache Consistency for External Data Fetching #197

Description

@vraj826

Problem Statement

The dashboard aggregates data from multiple external services (GitHub, LeetCode, Codeforces, CodeChef). When multiple requests for the same profile arrive simultaneously, the application may trigger duplicate upstream API calls for identical data.

This can lead to:

  • Unnecessary API traffic
  • Faster exhaustion of third-party rate limits
  • Increased response latency
  • Inconsistent cache population behavior
  • Higher server resource usage during traffic spikes

While caching exists, there is currently no protection against concurrent cache misses causing duplicate fetches ("cache stampede" behavior).

Proposed Solution

Introduce lightweight request deduplication and cache consistency controls.

Request Deduplication

When multiple requests attempt to fetch the same resource simultaneously:

  • Reuse the first in-flight request
  • Return the same promise/result to subsequent callers
  • Prevent duplicate upstream requests

Cache Consistency

Improve cache handling by:

  • Centralizing cache key generation
  • Ensuring consistent cache behavior across services
  • Preventing stale partial responses from polluting cache entries

Service Integration

Apply deduplication to:

  • GitHub REST requests
  • GitHub GraphQL requests
  • LeetCode requests
  • Codeforces requests
  • CodeChef requests

Additional Context

Expected Benefits

  • Reduced API usage
  • Lower risk of rate limiting
  • Improved response times under load
  • Better cache efficiency
  • More predictable service behavior

Suggested Testing

  • Concurrent requests for the same profile
  • Cache hit vs cache miss behavior
  • Expired cache scenarios
  • Multiple simultaneous requests sharing the same fetch
  • Service fallback behavior with deduplication enabled

Likely Files

  • src/utils/cache.js
  • src/utils/http-client.js
  • external service modules
  • related tests

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions