Overview
Mueve’s exchange rate system is built on a multi-layered architecture that ensures high availability, performance, and data persistence. The system uses Redis for real-time caching and MySQL for historical persistence, with intelligent fallback mechanisms to guarantee service continuity.Architecture Components
The rate management system consists of three main components:Rate Retrieval
When the API retrieves the current USD to Bolivares exchange rate, it follows a two-tier fallback strategy:The fallback mechanism ensures that even if Redis is temporarily unavailable, the API can continue serving exchange rates using the most recent persisted value from MySQL.
Rate Persistence Strategy
The persistence service runs in the background and intelligently decides when to save rates to MySQL based on two conditions:Persistence Triggers
Minimum Delta Threshold
Minimum Delta Threshold
Rates are persisted when the price changes by at least 0.2% (0.002) relative to the last saved rate. This prevents excessive database writes for minor fluctuations.
Maximum Age Threshold
Maximum Age Threshold
Even if the rate hasn’t changed significantly, rates are persisted at least once per hour (3600 seconds) to maintain a continuous historical record.
Configuration Parameters
The persistence service accepts configurable parameters:How often the service checks if rates should be persisted (in seconds). Default is 5 minutes.
Minimum relative change (0.2%) required to trigger persistence.
Maximum time (1 hour) before forcing a persistence operation regardless of price change.
Rate Validation and Tolerance
When users initiate transactions, the API validates that the rate they’re using is still current. This prevents issues where users might complete a transaction with an outdated rate.Tolerance Mechanism
Mueve implements a ±0.35 tolerance window for rate validation:Database Schema
Rates are stored in MySQL with the following structure:Auto-incrementing primary key
Exchange rate with 8 decimal precision
Origin of the rate data (typically “redis”)
When the rate was persisted to the database
High Availability Design
The multi-layered architecture provides several availability benefits:Redis Primary: Ultra-fast access for 99.9% of requests with sub-millisecond latency.
MySQL Fallback: Automatic failover to database if Redis is unavailable, ensuring continuous service.
Historical Data: Complete audit trail of rate changes for compliance and analysis.
Best Practices
When integrating with the rate system:- Always validate rates before finalizing transactions using the tolerance mechanism
- Cache rates client-side for short periods (30-60 seconds) to reduce API calls
- Handle rate change errors gracefully by prompting users to refresh
- Monitor rate freshness by checking the
created_attimestamp from the database - Never hardcode rates - always fetch from the API in real-time
Related Resources
- Transactions - Learn how rates are applied to buy and sell transactions
- Commissions - Understand how commission fees are calculated
- API Reference - Get current exchange rate endpoint