Design a Currency Exchange Rate Calculation and Conversion System
Company: ByteDance
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Onsite
Design a system that calculates currency exchange rates and uses them to convert amounts between currencies for other services. Only the topic was reported, so settle the scope with the interviewer: where the rates come from, who consumes them, and how exact and how fresh they must be.
```hint Not every pair is quoted
Consider what the system returns when no source quotes the requested pair directly, and whether two different ways of deriving the same rate can disagree.
```
```hint A conversion must be reproducible
Decide how rates and amounts are represented and rounded, and what the system must record so that a conversion made today can be explained, or repeated, months from now.
```
### Constraints and Clarifications
- Not given: the number of currencies, which pairs the sources quote, how often rates change, request volume, latency and freshness targets, and whether the rates are only displayed or also used to move money. Ask, or state your assumptions.
### Clarifying Questions
- Who consumes the rates: price display, settlement of real payments, financial reporting, or several of these with different requirements?
- Where do rates come from (external providers, an internal treasury team), and do the sources quote every pair or only some?
- How fresh must a rate be, and what should callers get when the sources stop updating?
- Do callers need the rate at a past moment, for example for refunds or audits?
- What precision and rounding rules apply per currency, and are spreads or fees part of this system or applied elsewhere?
### What a Strong Answer Covers
- Requirements and estimates first, including the difference between display-only use and use for moving money
- Ingestion from one or more sources, with validation, normalization and failover
- A defined, deterministic rule for deriving rates for pairs that are not quoted directly
- A low-latency read path that does not query the database on every request
- Exact arithmetic, per-currency rounding, and versioned rates so that every conversion is reproducible
- Staleness detection, failure handling and observability
### Follow-up Questions
- Two sources disagree on one pair by more than expected. What does the system serve, and how is the disagreement detected?
- A rate derived through intermediate currencies differs from a direct quote for the same pair. Which one do you return, and why?
- A refund must use the exact rate of a purchase made months earlier. What do you store, and where?
- A source has stopped updating, but nothing has crashed. How do you notice, and what do callers see in the meantime?
Overview: Design a system that computes currency exchange rates and converts amounts between any two supported currencies for other services. It tests rate ingestion and validation, deriving rates for pairs that are not quoted directly, exact rounding, reproducible rate versions, staleness handling and low-latency serving.