Build a Global Marketplace Pricing System for Multiple Currencies
System DesignModel answerLast updated
Design the full stack — data model, APIs, exchange-rate pipeline, rounding, and UX — for a travel marketplace that lets guests browse and pay in any of ~50 currencies.
Scenario
You are a senior engineer at a global travel marketplace. Hosts list properties and set prices in their local currency. Guests come from all over the world and expect to browse, get a binding price quote, and complete payment in their own currency. The platform processes over 100 000 bookings per day and renders hundreds of millions of prices on search pages.
Your Task
Walk through how you would design the end-to-end multi-currency pricing system for this platform. Your answer should address each of the following areas:
Currency selection and defaulting How does the platform decide which currency to show a new visitor? How does a logged-in user save a preference, and what takes priority?
Storage currency vs. presentation currency Where are canonical prices stored, and how does that differ from what a guest actually sees? What does that mean for the data model?
Conversion timing When is a floating (approximate) conversion acceptable, and when must a rate be locked? What should happen if rates shift between the moment a guest sees a price and the moment they pay?
Exchange-rate sourcing and lifecycle Where do rates come from, how often are they refreshed, and how do you protect the system against a bad rate update or a vendor outage?
Rounding and localization How do you convert line items without accumulating errors? How do you format amounts correctly across different locales and currency conventions?
Taxes and fees Many taxes are defined in the local jurisdiction's currency (for example, a flat €3 city fee per night). How does that interact with the conversion pipeline?
Caching strategy Search pages are latency-sensitive. How do you serve fast price estimates without hitting a live FX service on every request?
Consistency across the booking lifecycle How do you ensure that confirmation emails, PDF invoices, alterations, and refunds all show the same amounts the guest agreed to at checkout?
API and data model Sketch the key endpoints and the most important tables or records. What fields are essential for auditability?
What is Expected
This is a system design question, so a strong answer reasons through trade-offs rather than jumping straight to a schema. Cover the full lifecycle from a guest's first search to a host payout and a potential refund. Call out failure modes, edge cases, and the decisions that are hard to change later.
Hints
Hint 1
There are four distinct currency roles in this system — listing, presentation, charge, and payout — and they are often all different. Naming them explicitly before drawing any data model prevents a lot of confusion downstream.
Hint 2
The most important architectural decision is when a rate gets locked. Browse-time prices can be approximate and ephemeral, but a price the guest has agreed to pay must be frozen in an immutable snapshot that every future artifact (invoice, refund, ledger entry) can reference.
Hint 3
Never store or compute money as a float. Use integer minor units paired with an ISO-4217 currency code, and keep a single shared table of currency exponents (JPY=0, USD=2, KWD=3). Rounding mode and cash-rounding rules also belong in that config, not scattered across services.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify Scope First
Before designing anything, pin down a few numbers and constraints.
- Around 40–60 supported currencies; assume full ISO-4217 coverage for display, a smaller set for actual charging.
- Search pages must be fast: target p99 under 200 ms for the pricing contribution.
- Quoted and charged amounts must be exact, auditable, and reproducible from stored data. Estimates are fine for browse; they are not fine for anything the guest has agreed to.
- Rate outages must not block bookings.
The one sentence that frames everything else: display prices can be approximate; quoted and charged prices must be locked.
2. Name the Four Currency Roles
Most mistakes in multi-currency systems come from treating "the currency" as a single thing. There are four distinct roles:
| Role | Owned by | Example |
|---|---|---|
| Listing (storage) currency | Host, set at listing time | JPY |
| Presentation currency | Guest's choice or device default | EUR |
| Charge (settlement) currency | Usually equals presentation | EUR |
| Payout currency | Host's bank preference | USD |
Canonical prices live in the listing currency. Everything else is derived. This means a refund or alteration years later can always be recomputed from the original numbers without relying on a live rate.
Money representation: store as (amount_minor: int64, currency: ISO-4217). Never floats. Maintain a single shared exponent table (JPY → 0, USD → 2, KWD → 3). All services import that table; none hard-code it.
3. Conversion Timing: Float vs. Lock
Browse and search. Convert at render time using a cached rate snapshot. Mark results as approximate. Nothing is persisted. This is fine because the guest has not agreed to anything yet.
Quote (when the guest hits "Reserve" or loads checkout). Run the full pricing calculation — nightly rate, cleaning fee, service fee, taxes — and persist a Quote record that includes every line item in both currencies, the fx_snapshot_id used, and an expiry (typically 30 minutes).
Checkout. POST /bookings references the quote_id. If the quote is still valid, charge exactly the quoted amount even if market rates have moved since. The platform absorbs small FX drift or hedges it externally. If the quote has expired, re-quote and surface the new total to the guest before charging — do not silently charge a different amount.
Payout. Convert from listing currency to payout currency at payout time using a separate snapshot. The host is guaranteed their listing-currency earnings; FX risk on the payout side is explicit and disclosed.
The payoff of this design: every downstream artifact (email, PDF invoice, refund, accounting ledger entry) can be regenerated deterministically by reading the stored line items and the immutable snapshot.
4. Exchange-Rate Service
Sources. Ingest from at least two vendors (a market data provider plus the payment processor's own rates). Take the median, then apply a configured spread per currency pair.
Refresh cadence. Publish a new immutable fx_snapshot every 15–60 minutes. Each snapshot has a unique ID, a timestamp, a base currency, and the full rate map. Snapshots are never updated in place.
Guardrails:
- Reject any update that moves more than ~5% from the previous snapshot without manual approval.
- On vendor failure, keep the last-known-good snapshot and alert if it ages past ~4 hours.
- Some pegged currencies can be frozen; volatile ones may need tighter change limits.
Distribution. On publish, write to the database and emit an event to a pub/sub topic. Downstream services (search, quote) consume the topic and cache locally. This avoids a synchronous dependency on the rate service at request time.
5. Rounding and Localization
Pipeline order matters. Convert each line item individually, then round to the target currency's exponent. Define the total as the sum of the already-rounded line items. This way the receipt arithmetic always checks out. Never convert a pre-totaled amount and hope the parts still add up.
For any situation where a converted total must be split across installments or participants, use largest-remainder allocation so the parts sum exactly to the total.
Rounding mode is per-currency config. CHF uses cash rounding to 0.05. Most currencies use half-even (banker's rounding). JPY has no decimals at all.
Formatting. Locale and currency are independent — a fr-CA user might be looking at USD. Use ICU/CLDR (Intl.NumberFormat on web, platform equivalents on mobile). Disambiguate ambiguous symbols explicitly: "US$", "CA$", "MX$" rather than "$".
Client rule: the server returns minor units and a currency code. The client formats only. It never does arithmetic on prices.
6. Taxes and Fees
Many taxes are legally defined in the local jurisdiction's currency — for example, a €3 per-person-per-night city levy. The tax engine should produce line items in the jurisdiction's currency first, then the conversion pipeline converts them to presentation currency.
Percentage-based fees (like a guest service fee) should be computed in the listing currency and then converted, not the other way around.
Some regulatory environments (EU, certain US states) require all-in totals in search results, not just the nightly rate. Search therefore needs an estimated fee and tax model baked into the pricing query, not a post-hoc addition.
Legal tax invoices often must show the local-currency amount and the exchange rate applied. Store both on the line item.
7. Key Data Model
-- Canonical host prices
listing_price(listing_id, currency, nightly_minor, cleaning_minor, rules_json)
-- Immutable rate snapshots — never updated
fx_snapshot(id, created_at, base_currency, rates_json, source_meta)
-- A priced, time-limited commitment to the guest
quote(id, listing_id, user_id, check_in, check_out, guests,
listing_currency, presentation_currency,
fx_snapshot_id, expires_at, status)
-- One row per fee/tax component, amounts in both currencies
quote_line_item(quote_id, type, amount_listing_minor,
amount_presentation_minor, tax_jurisdiction)
-- Confirmed booking references quote for full audit trail
booking(id, quote_id, charge_currency, charge_total_minor,
listing_total_minor, fx_snapshot_id)
-- Append-only, double-entry; each row is single-currency
ledger_entry(id, booking_id, account, amount_minor, currency,
fx_snapshot_id, type) -- type: charge|refund|payout|fx_gain_loss
FX gains and losses are real money and need explicit ledger accounts, not silent rounding buckets.
8. Core API Sketch
GET /v1/search?currency=EUR&locale=de-DE
→ listings[{price: {amount_minor, currency, is_estimate: true}}]
POST /v1/quotes
{listing_id, check_in, check_out, guests, currency}
→ {quote_id, expires_at, fx_snapshot_id, line_items[], total}
POST /v1/bookings
{quote_id, payment_method_id, idempotency_key}
→ 201 booking | 409 QUOTE_EXPIRED {new_quote_preview}
GET /v1/bookings/{id}/receipt ← regenerated from stored line items
POST /v1/bookings/{id}/refunds
{amount_minor | percent, reason, idempotency_key}
All money-mutating endpoints take an idempotency key. The 409 path on an expired quote surfaces a new estimated total rather than silently re-quoting and charging.
9. Currency Selection UX
Default precedence (first match wins):
- Saved account preference.
- Last-used currency from a prior session cookie.
- Currency associated with the billing country on the payment method.
- Country inferred from IP geolocation.
- Platform default (usually USD).
Always let the guest override in one click. Persist the override immediately so it survives navigation. Do not force a currency based on the listing's location — a US guest booking in Japan likely still wants USD.
10. Common Mistakes to Call Out
- Float arithmetic for money: silent precision loss compounds across millions of transactions.
- Mutable rate records: updating a snapshot in place makes historical bookings unreproducible.
- Converting the total before splitting line items: receipts that don't add up to their own total erode trust and fail audits.
- One "currency" field per booking: failing to separate listing, charge, and payout currencies causes incorrect accounting when they differ.
- Letting the client format by doing math: the client should only call
Intl.NumberFormat, never add or subtract minor units.