Skip to content

[Performance] Replace polling-based exchange rate with Redis-cached shared store #326

Description

@kelly-musk

Problem

app/api/exchange-rate/route.ts calls CoinGecko on every request (with a 20s Next.js revalidation). CoinGecko's free tier has strict rate limits (30 calls/min). Under moderate traffic, these limits will be exceeded.

app/api/rates/route.ts uses an in-process module-level cache that resets on cold start and is not shared across serverless function instances.

Fix

Use Upstash Redis (already configured in middleware) as a shared cache:

const cached = await redis.get('exchange-rates')
if (cached) return Response.json(JSON.parse(cached))
const fresh = await fetchFromCoinGecko()
await redis.setex('exchange-rates', 60, JSON.stringify(fresh))
return Response.json(fresh)

Impact

Medium — CoinGecko rate limits will cause exchange rate failures under load.

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programapiAPI route handlersinfrastructureHosting, CI/CD, deploymentperformancePerformance and optimization

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions