Bird
Raised Fist0

Uber - Driver Matching, Surge Pricing, Real-Time Location Tracking

HLDhardInterview freq: high
Choose your preparation mode4 modes available
▶
Request Trace
Step 1/5
API Gateway

Receives rider's ride request with location

Rider sends ride request via WebSocket connection

Protocol:WebSocket
BeforeRider has not sent any request
AfterAPI Gateway has received and parsed rider's request
Matching Srv

Queries Location Store for nearby drivers

Matching Srv requests driver locations near rider

Protocol:REST API
BeforeMatching Srv has rider location but no driver info
AfterMatching Srv has list of candidate drivers near rider
Surge Pricing Srv

Calculates surge multiplier for rider's area

Surge Pricing Srv computes dynamic price based on demand

Protocol:RPC
BeforeMatching Srv has candidate drivers but no price info
AfterMatching Srv has surge multiplier to apply
Notification Srv

Sends ride request notification to matched driver

Notification Srv pushes request to driver's app

Protocol:RPC
BeforeDriver unaware of new ride request
AfterDriver receives ride request notification
Location Ingest Srv

Receives real-time driver location updates

Driver app sends location updates continuously

Protocol:Redis SET
BeforeLocation Store has last known driver location
AfterLocation Store updated with latest driver location
🏗️
Architecture Diagram
Architecture Diagram
┌───────────────┐
│  API Gateway  │
└───────┬───────┘
        │ WebSocket
        ▼
┌───────────────────────┐
│ Location Ingest Srv   │
│ (processes driver loc)│
└───────┬───────────────┘
        │ Redis SET
        ▼
┌───────────────┐
│ Location Store│
│ (driver loc DB)│
└───────┬───────┘
        │ REST API
        ▼
┌───────────────┐
│ Matching Srv  │
│ (finds drivers│
│  near rider)  │
└───────┬───────┘
        │ RPC
        ▼
┌───────────────────────┐
│ Surge Pricing Srv     │
│ (calculates surge)    │
└───────┬───────────────┘
        │ RPC
        ▼
┌───────────────────────┐
│ Notification Srv      │
│ (sends driver request)│
└───────────────────────┘

This architecture supports Uber's core features: driver matching, surge pricing, and real-time location tracking. The API Gateway handles client requests over WebSocket, forwarding ride requests to the Matching Srv. Matching Srv queries the Location Store to find nearby drivers, which is kept updated by the Location Ingest Srv processing driver location updates via Redis. Surge Pricing Srv calculates dynamic pricing based on current demand and supply, informing Matching Srv. Finally, Notification Srv sends ride requests to matched drivers. This vertical flow ensures low latency and scalability by separating concerns and using efficient protocols like Redis for location updates and RPC for internal service communication.

Primary Focus

✓

Practice

(1/5)
1. In the request flow of a video call setup, at step 5 the Signaling Server receives an SDP offer from Alice and forwards it to Bob. What state does the Signaling Server maintain immediately after forwarding the offer?
easy
A. It stores the offer and waits for Bob's SDP answer before updating session state
B. It queues the offer indefinitely until Bob acknowledges receipt
C. It deletes the offer after forwarding, assuming Bob will respond directly to Alice
D. It marks the session as established and starts media relay between Alice and Bob

Solution

  1. Step 1: Trace Signaling Server behavior at step 5

    The server forwards Alice's SDP offer to Bob and stores it to correlate with Bob's answer.
  2. Step 2: Understand session state management

    Session is not established until Bob's SDP answer arrives; the offer must be retained temporarily.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Signaling Server stores offer awaiting answer before session established [check]
Hint: Signaling stores offer until answer arrives, then session established [check]
Common Mistakes:
2. For a globally distributed collaborative editor with many offline users, which approach better supports eventual consistency and offline edits, and why?
medium
A. Use Operational Transformation (OT) because it requires a central server to order operations
B. Use a relational database with strict locking to serialize all edits globally
C. Use CRDTs because they allow local operations to be merged without coordination and support offline edits
D. Use a message queue with timestamp ordering to ensure global operation order

Solution

  1. Step 1: Compare OT and CRDT for offline and distributed scenarios

    OT typically requires a central server to order and transform operations, making offline support complex.
  2. Step 2: Understand CRDT advantages

    CRDTs are designed for decentralized environments, allowing local operations to be merged eventually without coordination, ideal for offline edits and global distribution.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    CRDTs enable offline edits and eventual consistency without central coordination [check]
Hint: CRDTs merge offline edits without central coordination [OK]
Common Mistakes:
3. If the idempotency key store becomes unavailable, what is the most likely failure mode for the payment API when a client retries a payment request?
medium
A. The payment API processes each retry as a new payment, causing duplicate charges
B. The payment API queues requests until the store recovers, delaying all payments
C. The payment API rejects all requests with 503 Service Unavailable errors
D. The payment API returns cached responses from a fallback in-memory store

Solution

  1. Step 1: Understand idempotency store role in retries

    Without the store, the API cannot verify if a request is a retry, so it must delay processing to avoid duplicates.
  2. Step 2: Eliminate other options

    Rejecting all requests is possible but not typical; processing retries as new causes duplicates, which is avoided; fallback caches are uncommon and inconsistent.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Unavailable idempotency store causes request queuing to prevent duplicates [check]
Hint: No idempotency store -> queue retries to avoid duplicates [check]
Common Mistakes:
4. For a distributed lock system requiring low latency and fault tolerance, which approach is better and why?
medium
A. Use ZooKeeper for strong consistency but higher latency
B. Use a single Redis instance with SETNX and expiration for simplicity
C. Use Redlock algorithm with multiple Redis masters to tolerate partial failures
D. Use a database-based lock with distributed transactions for atomicity

Solution

  1. Step 1: Compare fault tolerance and latency

    Single Redis is low latency but single point of failure; ZooKeeper is fault tolerant but higher latency.
  2. Step 2: Evaluate Redlock trade-offs

    Redlock balances low latency with fault tolerance by coordinating multiple Redis masters.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Redlock balances latency and fault tolerance better than single Redis or ZooKeeper [check]
Hint: Redlock balances latency and fault tolerance best [check]
Common Mistakes:
5. For a multiplayer online game requiring real-time position updates with minimal delay, which transport protocol and design choice best balances speed and reliability?
medium
A. Use UDP without any reliability mechanism to maximize speed
B. Use TCP exclusively to ensure all packets arrive in order
C. Use UDP with application-level sequence numbers and selective retransmission
D. Use TCP with aggressive Nagle's algorithm tuning to reduce latency

Solution

  1. Step 1: Analyze game requirements

    Real-time position updates require low latency but some reliability to avoid inconsistent state.
  2. Step 2: Evaluate protocol trade-offs

    UDP provides low latency; adding application-level sequence numbers and selective retransmission balances speed and reliability.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    UDP + app-level reliability fits real-time game updates [check]
Hint: UDP + app reliability balances speed and correctness [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard