Skip to content

Conversation

@chibokaxavier
Copy link

@chibokaxavier chibokaxavier commented Jan 30, 2026

Overview
This PR implements a resilient Exchange Rate Service designed to fetch, aggregate, and cache crypto-to-fiat rates. The system utilizes a multi-source strategy (Coinbase, Binance, and CoinGecko) to ensure high availability and data accuracy.

🛠️ Key Features
Multi-Source Aggregation: Fetches data from Coinbase and Binance, using a Weighted Average algorithm to calculate the final rate.

Resilience & Fallbacks: CoinGecko acts as a secondary fallback if primary sources fail.

An API Fallback Chain ensures that a single provider outage doesn't break the service.

Data Quality: Includes Outlier Detection to filter out "flash crash" or "bad data" spikes and a Confidence Scoring system for each rate.

Performance & Caching: * Implemented Redis caching for sub-millisecond lookups.

Integrated Staleness Detection to ensure users never receive expired data.

Infrastructure: * Cron Job: Automated updates every 60 seconds.

Persistence: Historical rate storage for auditing and trend analysis.

📊 Rate Calculation Logic
The service doesn't just pick a number; it follows this flow:

Fetch from all active providers.

Filter out outliers (values that deviate significantly from the median).

Calculate a weighted average based on source reliability.

Apply Spread for business logic.

Cache the result in Redis.

🧪 Testing & Verification
Unit Tests: All API responses are mocked to test edge cases and network timeouts.

Manual Verification: * Verified Cron logs for 60-second intervals.

Simulated API failures by blocking provider endpoints to confirm fallback to CoinGecko.

Checked Redis keys to confirm TTL and sub-millisecond response times.

📝 Definition of Done (Acceptance Criteria Check)
[x] Rates update every 60s.

[x] Graceful handling of source failures.

[x] Alerts triggered for stale rates.

[x] Sub-millisecond lookup via Redis.

Fixes #26

…ltiple providers, caching, and historical storage, along with supporting infrastructure.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exchange Rate Service - Multi-Source Aggregation

1 participant