Build an FX Rate Cache That Refreshes Once Under Load

Last updated: November 29, 2026

Quick Overview

Multi-currency card spend needs a current FX rate for every authorization. Build a thread-safe TTL cache where a burst of misses for the same currency pair triggers only one upstream fetch, and stale rates are served briefly if the provider is down.

Ramp
Software Engineering Fundamentals
Software Engineer
Ramp
November 29, 2026
Software Engineer
Onsite
Software Engineering Fundamentals
Hard

0

0

0 solved


Multi-currency card spend needs a current FX rate for every authorization. Build a thread-safe TTL cache where a burst of misses for the same currency pair triggers only one upstream fetch, and stale rates are served briefly if the provider is down.

Ramp supports spend in many currencies, and when a cached rate expires at peak, hundreds of threads can stampede the rate provider at once. The interviewer checks concurrency primitives beyond a single mutex: holding locks only around shared state, coordinating waiters with events, and choosing a failure policy that keeps authorizations flowing.

What the Interviewer Expects
  • Recognizes the thundering-herd problem when a hot key expires
  • Never holds the lock while doing network I/O
  • Elects a single leader per key and makes followers wait on an event
  • Guarantees the in-flight marker is cleared on success and on failure
  • Defines a bounded stale-serving window and explains the business risk
Key Topics to Cover
Single-flight
Thundering herd
Condition signaling
TTL caching
Graceful degradation
How to Approach This
  1. Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
  2. Choose data structures based on access patterns, not familiarity.
  3. Prefer immutable data and message passing over shared mutable state for concurrency.
  4. Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
  • How would you refresh ahead of expiry so no request ever waits?
  • How does this change across 50 processes, and would you use a distributed lock?
  • What if the upstream returns an obviously wrong rate (off by 100x)?
  • How would you test that followers do not spin when the leader fails?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

get(pair) returns a rate younger than ttl. Concurrent misses for the same pair share one fetch call. Different pairs never block each other on I/O. If the fetch fails, a rate younger than `max_s...

High-Level Design

One mutex protects two dicts: cached entries and in-flight events. A caller that finds a fresh entry returns immediately. On a miss, the first caller registers an Event and becomes the leader; later...


Submit Your Answer
Markdown supported