Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Response Caching for Currency and Institution Endpoints #381

Open
chibie opened this issue Jan 14, 2025 · 0 comments · May be fixed by #394
Open

Implement Response Caching for Currency and Institution Endpoints #381

chibie opened this issue Jan 14, 2025 · 0 comments · May be fixed by #394
Assignees
Labels
enhancement New feature or request

Comments

@chibie
Copy link
Contributor

chibie commented Jan 14, 2025

User Story
As an API consumer, I need faster response times for frequently accessed, relatively static data endpoints (currencies, institutions, and public key), so that the application performs more efficiently and reduces unnecessary load on our backend services.

Acceptance Criteria

  1. GIVEN a request is made to /currencies endpoint
    WHEN the cache is empty or expired
    THEN fetch from source and cache the response for 24 hours
    AND return the response

  2. GIVEN a request is made to /institutions/:currency_code
    WHEN the cache is empty or expired for that currency code
    THEN fetch from source and cache the response for 24 hours
    AND return the response

  3. GIVEN a request is made to /pubkey
    WHEN the cache is empty or expired
    THEN fetch from source and cache the response for 1 year
    AND return the response

  4. GIVEN a request is made to any of these endpoints
    WHEN valid cached data exists
    THEN return the cached response without hitting the backend

  5. GIVEN the application is starting up
    WHEN the server initializes
    THEN automatically fetch and cache all static data (currencies, institutions for supported currencies, pubkey)
    AND log the cache warming status for monitoring

Tech Details

  • Implement caching using Redis with the following keys:
api:currencies:list
api:institutions:{currency_code}
api:aggregator:pubkey
  • Implementation requirements:
    • Add Redis cache middleware for the specified routes
    • Implement cache key generation based on endpoint and parameters
    • Add cache headers in response (Cache-Control, ETag)
    • Add monitoring for cache hit/miss rates
    • Handle cache failures gracefully (fallback to direct response)

Notes/Assumptions

  • Redis is already available in the infrastructure
  • Cache durations are configurable via environment variables
  • Cache keys should include version prefix for future updates
  • Response includes appropriate cache headers
  • Implement stale-while-revalidate pattern for high availability

Open Questions

  • Should we implement batch cache invalidation?
@chibie chibie added the enhancement New feature or request label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants