feat(fx): add resilient provider caching and stale-data semantics - #141
Open
woahwhattheheck wants to merge 1 commit into
Open
woahwhattheheck wants to merge 1 commit into
woahwhattheheck wants to merge 1 commit into
Conversation
Bounded TTL cache with primary→fallback providers, freshness metadata, quote versioning, stampede-safe singleflight, and reject_stale transfer pricing so outages cannot silently price on expired rates. Transfers bind quote identity (quoteId/quoteVersion) at creation. Closes RemitFlow#129
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #129
Problem
Provider outages can block transfers, or worse, let an expired exchange rate be treated as a current quote. The previous rate path read a static table with no TTL, no fallback, no freshness signal, and no quote identity on transfers.
What this PR does
fxCacheServicestores one USD-cross snapshot withFX_CACHE_TTL_MS(default 30s)primary→fallbackwalk infxProviders.fetchWithFallbackfreshness.{status,stale,providerId,fetchedAt,expiresAt,ageMs,...}quoteId+ monotonicquoteVersion, stored for later bindingreject_stale(transfers) vsallow_stale(display); codesQUOTE_STALE,QUOTE_EXPIRED,FX_PROVIDERS_DOWN,FX_REFRESH_IN_PROGRESSFX_REFRESH_IN_PROGRESSor serves within-grace stale underallow_stale— never a second provider callstale: true;assertUsable/ transfer binding refuse them underreject_stale['primary','fallback']attempt orderquoteId,quoteVersion,rateProvider,rateFetchedAt,rateStale. Optional clientquoteIdmust match amount/currencies; omitting it mints a fresh quote and still bindsDesign tradeoffs
GET /api/ratesandGET /api/quotecan surface a visibly-stale snapshot withinFX_STALE_GRACE_MS. Transfer pricing defaults toreject_staleso an outage cannot silently price a remittance. Opt-in:FX_ALLOW_STALE_TRANSFERS=true.quoteIdis optional onPOST /api/transfers. Existing clients keep working; every transfer still receives bound quote provenance. PassingquoteIdis the path that locks the sender to the quote they saw.Compatibility impact
freshness,quoteId,quoteVersion, …).quoteIdon transfer create (validated when present).{ base, rates: [...] }withfreshnessadded alongside.Tests
test/fxCache.test.js(16) covers:reject_stale; visibly-stale underallow_stalequoteIdtest/config.test.jscovers FX env defaults/overrides.Verification
Baseline on
upstream/mainwas 256. No unrelated tests were skipped, deleted, or weakened.Out of scope