KatInterview

Design a Real-Time Ride-Matching Platform and a Price-Alert Service

System DesignModel answer
HardModel answerSystem Designsystem-designdistributed-systemsgeospatial

Last updated

Architect two scalable backend platforms: a low-latency, geo-partitioned ride-hailing system and an asynchronous, queue-decoupled price tracking and notification pipeline.

This system design problem requires you to architect two distinct, large-scale distributed systems. Treat each part as an independent design while applying consistent architectural principles around latency, availability, fault tolerance, and data integrity.


Core Operating Assumptions & Constraints

  • Scale: Multi-million daily active users. Systems must scale horizontally by expanding compute and storage tiers rather than relying on vertical capacity limits.
  • Geographic Scope: Multi-region, global deployment footprint with regional user traffic patterns.
  • Client Topology: Mobile clients interacting via short-lived HTTPS REST/gRPC for transactional commands, paired with persistent multiplexed channels (WebSocket, gRPC streaming, or MQTT) when foregrounded for real-time streaming.
  • Latency SLAs:
    • Part 1 (Ride Matching): $p95 < 300,\text{ms}$ total response time to surface candidate drivers and assign requests.
    • Part 2 (Price Tracking): Alert delivery within 3–5 minutes of a verified price drop.
  • Availability Target: $\ge 99.99%$ availability for real-time dispatch and price monitoring components. Graceful degradation mechanisms must absorb localized regional or network failures.
  • Consistency Models:
    • Financial & Booking State: Strict serializability / strong ACID guarantees (trips, ledger transfers, user balances).
    • Spatial & Monitoring Telemetry: Eventual consistency (driver positions, ETAs, aggregate surge metrics, price snapshots).

Part 1: Real-Time Ride-Hailing Platform

Design a distributed backend connecting riders and service drivers in real time.

Core Functional Capabilities

  1. Ingest driver location updates every 2–5 seconds with minimal overhead.
  2. Index current driver positions to serve spatial radius queries with sub-300ms $p95$ latency.
  3. Manage the end-to-end ride lifecycle: request, driver matching/offering, acceptance, trip start, trip completion, and cancellation.
  4. Calculate localized surge pricing based on real-time spatial supply/demand imbalance.
  5. Guarantee idempotent transaction processing to eliminate double-assignments or duplicate billing.

Key Architectural Requirements

  • Outline the high-level system architecture, service boundaries, and data stores chosen for specific read/write patterns.
  • Detail the geospatial indexing scheme (e.g., Geohash vs. Google S2) and explain the nearest-driver query flow (candidate retrieval, filtering, ranking).
  • Explain the locking/reservation strategy used during match acceptance to prevent race conditions across concurrent dispatch workers.

Part 2: Product Price Tracking and Alert System

Design an asynchronous, high-throughput backend that monitors external product prices and fires notifications when trigger criteria are satisfied.

Core Functional Capabilities

  1. Allow users to register monitored items via URL or standardized Product Identifiers.
  2. Support configurable condition rules (e.g., price drop below fixed value $X$, or percentage drop $\ge Y%$ relative to a rolling baseline).
  3. Ingest price telemetry via scheduled Web crawling and external partner API feeds.
  4. Store durable, append-only price history for analytical reporting and baseline calculations.
  5. Send multi-channel notifications (Push, SMS, Email) with idempotency guarantees.

Key Architectural Requirements

  • Provide a end-to-end architecture diagram or flow detailing ingestion, history persistence, rule evaluation, and notification delivery.
  • Explain how the ingestion layer respects target site rate limits (politeness) while prioritizing high-demand items.
  • Detail the data modeling for rule evaluation at scale (millions of rules against thousands of price updates per minute).
  • Explain how notification duplication and alert fatigue are avoided during transient price volatility.

Hints

Hint 1

Break data pipelines into clear read, write, and background execution stages; never use transactional RDBMS instances for high-frequency location or price telemetry streams.

Hint 2

For spatial searching, use hierarchical cell indexes like Google S2 or H3 over standard 2D R-Trees to allow simple key-value lookups and ring expansions across spatial boundaries.

Hint 3

Prevent race conditions during driver assignment by employing atomic lock-and-set operations (e.g., Redis Lua scripts or conditional SQL updates) with short-lived TTL reservations.

Hint 4

Decouple price fetching from rule evaluation using event streams (e.g., Kafka); group rule evaluations by product ID so a single price update triggers a single batch cache lookup.