Design a Multi-Provider Money Transfer Price Comparison Service
System DesignModel answerLast updated
Design a service that gathers remittance quotes from many providers, computes true customer cost against a mid-market rate, and clearly marks stale or missing data.
Scenario
A consumer finance app wants to show people which service is cheapest for sending money abroad on a given route, such as USD to PHP or EUR to INR. The headline exchange rate alone is misleading: a provider may charge a small upfront fee but give a worse rate than the interbank mid-market rate, which is a hidden cost.
Design a prototype and its architecture for a price comparison service. It pulls prices from provider APIs, public web pages, and data partners, converts them to one comparable total cost, and serves the result to end users and to internal pricing analysts.
Requirements
Functional
-
Query and normalization. A request is
(source_currency, target_currency, send_amount, delivery_method). For each provider compute:total_cost = upfront_fee + send_amount * (1 - provider_rate / mid_market_rate) -
Provenance. Every quote keeps its source, retrieval time, expiry/TTL, and a pointer to the raw response it was derived from.
-
Partial results. If a provider times out, rate-limits you, or breaks, return the comparison for the others and explicitly mark the missing or outdated entries. Never fail the whole request because of one provider.
-
Extensibility. Adding a provider or a fallback parser should need little code.
Non-functional
- Latency. P95 under 800 ms for cached or pre-warmed routes. Live on-demand fetching must finish within 3 seconds.
- Freshness. FX quotes must be no more than 5 minutes old during active market hours.
- Transparency. Show fee breakdowns plainly. Do not hide provider disclaimers or tiered and promotional pricing.
Scale
- 100 active routes (corridors) and 20 providers.
- Around 3,000 comparison requests per minute at peak.
- Mid-market reference rates refresh every 30 seconds from trusted feeds.
What to cover
- Data model: quotes, provider adapters, raw payloads, normalized comparisons.
- Architecture: ingestion (APIs versus scrapers), caching, worker pools, fallbacks.
- Failure and staleness semantics: how a client tells live data from stale data from a failed provider.
- Production readiness: rate-limit protection, circuit breaking, observability, and automatic detection of broken parsers.
Hints
Hint 1
Do the capacity math first: convert requests per minute to QPS, then count route x provider x amount-tier x delivery-method combinations and divide by the refresh interval. Work out which load actually dominates.
Hint 2
Decouple the read path from the fetch path. Reads should hit a cache of normalized quotes, while a scheduler and per-provider workers keep that cache fresh in the background.
Hint 3
Make status a per-quote property (live, fresh cache, stale, unavailable) with an age and a reason, and pin each comparison to a single mid-market snapshot so every provider is judged against the same baseline.
Hint 4
Isolate providers from each other with separate worker pools, rate limiters, and circuit breakers, and validate parsed quotes (range and delta checks) before publishing so a broken scraper cannot poison results.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Framing
This is mostly a data-integrity and isolation problem, not a traffic problem. Read volume is small. The hard parts are comparing everyone against one trustworthy baseline, keeping 20 unreliable upstreams from hurting each other, and being honest about how old each number is. I would state this up front and back it with numbers.
Capacity estimate
- Reads: 3,000 per minute is about 50 QPS. A cache-backed read path handles that easily.
- Fetches: 100 routes x 20 providers = 2,000 route-provider pairs. Fees and rates are tiered by amount, so use buckets (say 100, 500, 1,000, 5,000, 10,000 in USD-equivalent) and 2-3 delivery methods (bank, cash pickup, wallet). That gives roughly 10-20k quote keys. Refreshing each about every 3 minutes (to stay under the 5-minute limit) means roughly 60-110 upstream calls per second.
- Conclusion: provider rate limits and scraping cost, not user traffic, are the binding constraint.
- Mid-market: about 100 currency pairs every 30 s, which is negligible.
Clarifying questions: can users send arbitrary amounts (interpolate between buckets, or go live)? Is freshness relaxed on weekends? Are consumers and internal tools both served (affects disclosure and access control)?
API
GET /v1/comparisons?source=USD&target=PHP&amount=500&delivery=bank&mode=cached|live
The response includes a snapshot_id and mid-market rate, a list of quotes, and a completeness summary. Each quote carries: provider, status (LIVE, FRESH_CACHE, STALE, UNAVAILABLE), upfront_fee, provider_rate, fx_markup_cost, total_cost, recipient_gets, retrieved_at, expires_at, age_seconds, pricing_type (standard or promo), disclaimers, source, and an error reason if any.
Notes on the formula:
- Compute the markup in the source currency:
amount * (1 - provider_rate / mid_rate). - A rate better than mid-market gives a negative markup. Keep it and flag it for review rather than clamping to zero.
- Pin every comparison to one mid-market snapshot so results are consistent and reproducible for audits.
- Internal tools get an endpoint to fetch the raw payload behind a quote.
Data model
- MidMarketSnapshot: snapshot_id, pair, rate, contributing sources, as_of. Append-only. Use the median of 2-3 feeds with an outlier check.
- ProviderAdapterConfig: provider_id, kind (API, partner, scraper), supported routes, rate limit, timeout, fallback chain, parser_version, enabled.
- RawPayload: payload_id, provider_id, fetched_at, HTTP status, content hash, object-storage URI, parser_version. Immutable, kept for the audit window.
- Quote: quote_id, provider_id, route key, amount bucket, delivery method, upfront_fee and currency, provider_rate, pricing_type, eligibility conditions, disclaimers, retrieved_at, expires_at, payload_id, validation_status.
- Comparison: comparison_id, request params, snapshot_id, quote ids with per-quote status, created_at. Logging it answers "what exactly did we show this user?"
Storage: Postgres or a time-series store for quote history and analytics, object storage for raw payloads, Redis for hot quotes.
Architecture
- Mid-market service pulls trusted feeds every 30 s, validates, and publishes snapshots to Redis and the durable store. It is independent of provider fetching.
- Scheduler emits fetch jobs per (provider, route, bucket, method), prioritized by route traffic and time to expiry, and pre-warms hot routes.
- Worker pools, one per provider (bulkheads), each with its own rate limiter, concurrency cap, and circuit breaker. Scrapers (headless browsers) run in a separate, costlier pool.
- Adapter interface:
A new provider is one adapter class plus one config row. The fallback chain (API, then partner feed, then scraper) is configuration.class ProviderAdapter(Protocol): def fetch(self, req: QuoteRequest) -> RawPayload: ... def parse(self, raw: RawPayload) -> list[NormalizedQuote]: ... def health(self) -> AdapterHealth: ... - Validation stage before publishing: schema checks, range checks (rate within X% of mid-market, fee within historical bounds), and delta checks against the last good quote. Failures are quarantined and never served.
- Two-tier cache: a fresh tier with TTL = min(provider expiry, 5 min), and a stale tier holding the last known good quote for up to 24 h.
- Comparison service is stateless: read the latest snapshot, multi-get fresh quotes, fall back to the stale tier on misses, normalize, return. In
livemode, fan out to adapters in parallel under a global deadline (about 2.5 s); anything late gets its cached value plus a flag.
Failure and staleness semantics
Status is per quote, never per response:
LIVE: fetched during this request.FRESH_CACHE: younger than the freshness SLA.STALE: from the stale tier, withage_secondsand a reason (CIRCUIT_OPEN,RATE_LIMITED,TIMEOUT,PARSE_FAILED).UNAVAILABLE: nothing usable.
Return HTTP 200 as long as any quote exists. Clients show a badge for stale entries, and stale quotes are excluded from the "cheapest" ranking unless policy allows them.
Latency
The cached path is one Redis multi-get plus arithmetic, well under 50 ms, so 800 ms P95 is comfortable. On a miss for a hot key, serve stale and refresh asynchronously (stale-while-revalidate), with request coalescing so concurrent misses trigger one upstream call.
Production readiness
- Rate limiting: token bucket per provider, shared via Redis; honor
Retry-After; exponential backoff with jitter; under pressure refresh hot routes first and let cold ones degrade. - Circuit breakers: trip per provider when errors or timeouts exceed about 50% in a rolling window. While open, serve from the stale tier only; use half-open probes to recover.
- Broken-parser detection: canary fetches with golden fixtures, parser_version tracking, alerts when the share of quarantined quotes or null fields jumps, and automatic fallback to the next adapter in the chain.
- Observability: per-provider success rate, latency, quote age distribution, quarantine rate, cache hit ratio, and a "fraction of comparisons with full coverage" SLO. Trace each comparison through its snapshot and quote ids.
- Compliance: always carry disclaimers, promo conditions, and eligibility through to the response; never drop them during normalization.
Trade-offs and common mistakes
- Precomputing everything wastes upstream budget on cold routes; prioritize by traffic.
- Failing the whole request on one provider error defeats the partial-availability requirement.
- Using each provider's own "mid-market" or a different timestamp per provider makes totals incomparable.
- Silently ranking stale quotes as cheapest misleads users.
- Clamping negative markups hides data problems that should be investigated.
- Sharing one worker pool across providers lets one slow upstream starve the rest.