Skip to content

πŸ—„οΈ Implement Caching Layer for Gas QueriesΒ #67

@mijinummi

Description

@mijinummi

πŸ“Œ Overview

Frequent gas queries can overload RPC nodes, leading to higher latency and potential rate-limiting issues. Caching responses improves performance, reduces backend load, and ensures consistent data delivery.

This task introduces a caching layer for gas queries using Redis to optimize GasGuard API responsiveness and reliability.


🎯 Objective

Build a system that:

  • Caches gas query results to reduce repeated RPC calls
  • Provides configurable cache expiration per endpoint or chain
  • Maintains data accuracy while improving response times
  • Lowers API latency and backend resource usage

πŸ›  Scope of Work

1️⃣ Caching Implementation

  • Integrate Redis as caching backend
  • Cache gas query results:
    • Base fee, priority fee, max fee
    • Chain-specific metrics
    • Volatility or analytics data if frequently requested
  • Support configurable TTL (time-to-live) per query type
  • Implement cache invalidation for outdated data

2️⃣ API Integration

  • Intercept gas query endpoints to:

    • Check cache before making RPC call
    • Serve cached data if available
    • Update cache when RPC response is retrieved
  • Example pseudo-flow:
    Client -> API Endpoint -> Redis Cache? -> Return Cached / Fetch from RPC -> Store in Cache -> Return Response


3️⃣ Metrics & Monitoring

  • Track cache hit/miss rates for each endpoint
  • Optional integration with Prometheus for cache performance monitoring
  • Log cache failures or Redis connection issues for diagnostics

4️⃣ Security & Access

  • Redis access secured via authentication
  • Cache only non-sensitive public data (gas queries)
  • Logging for operational transparency

🧰 Suggested Tech Stack

Core

  • TypeScript
  • Node.js
  • Redis (in-memory caching)
  • ioredis or node-redis library
  • Express / Fastify / NestJS

Optional Enhancements

  • Prometheus metrics for cache efficiency
  • Redis cluster for high availability and scalability
  • Jest (unit testing)

🧠 Implementation Expectations

  • Clear separation between:
    • RPC query layer
    • Redis caching layer
    • API response layer
  • Efficient cache lookup and invalidation logic
  • Unit tests covering:
    • Cache hit/miss behavior
    • TTL expiration
    • RPC fallback when cache unavailable
    • Multi-chain and multi-endpoint queries

πŸ“Š Deliverables

  • Redis caching layer integrated with gas query endpoints
  • Configurable TTL and cache invalidation logic
  • Metrics and logging for cache performance
  • Documentation explaining:
    • Cache usage
    • TTL configuration
    • Operational monitoring
  • Unit tests (minimum 70% coverage)
  • Updated README

🏷 Difficulty Level

Intermediate

Ideal for contributors with:

  • Backend TypeScript experience
  • Knowledge of caching strategies and Redis
  • Understanding of multi-chain gas query patterns
  • Performance optimization mindset

πŸ•’ Estimated Time

24hrs (part-time contributor)


βœ… Acceptance Criteria

  • Gas queries return cached data when available
  • RPC calls reduced due to effective caching
  • Configurable TTL implemented
  • Metrics and logging operational
  • Documentation updated
  • All tests passing

🎯 Expected Outcome

GasGuard achieves lower latency and reduced RPC load, ensuring faster responses and more reliable gas data delivery for clients and dApps.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Nest.jsStellar WaveIssues in the Stellar wave programbackendNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions