2dbi

Design a Hotel Search System

viaLeetCode

Problem Design a hotel search system returning priced results for a check-in/check-out range, with prices decomposed (base, taxes, fees) and formatted in the requester's currency. Covers HLD and the pricing LLD.

Functional requirements

  • Search (location, dates, guests) → hotels with total + itemized stay price; price breakdown per line item; display in any supported currency with correct formatting.

Non-functional requirements

  • Search is the hot read path (thousands QPS, p99 < ~500 ms); prices must be consistent with what booking will charge; FX rates refresh periodically.

Key components (HLD)

  • Search service (geo/attribute index) → availability service (room-night inventory) → pricing service (rate plans + tax/fee rules engine per jurisdiction) → currency service (rate cache with versioned snapshots, refreshed from an FX feed) → response assembler. Cache priced results keyed by (hotel, dates, occupancy, currency-version) with short TTL.

Core design (LLD)

  • Hotel 1—N RoomType 1—N RatePlan(nightly base by date, cancellation policy); PriceBreakdown = list of PriceComponent(type: BASE/TAX/FEE/DISCOUNT, amount as Money); Money(amountMinorUnits, currency) — never float; PricingEngine composes components via rule strategies; CurrencyConverter(snapshot) applied at the edge, formatting via locale-aware formatter (symbol position, decimals — JPY has none).

Deep dives / trade-offs

  • Convert-then-sum vs sum-then-convert (rounding drift on line items — round per component, reconcile the total); pinning an FX snapshot id through search → booking so the quoted price holds.
  • Tax computation ordering (taxes on discounted base?) as a rules-engine concern; caching priced search results without serving stale prices into checkout (recheck authoritatively at booking).
Add a follow-up question they asked
No follow-ups yet. Be the first to add one.
asked …
LeaderboardSalary
Language
Account