Uber / Ride-Hailing

Matching riders to moving drivers in real time — worked through the TOGAF ADM phases so the high-write location pipeline and the matcher in Phase D fall out of the requirements.

Uber / ride-hailing, the ADM way, in 30 seconds

  • Why TOGAF here: it forces business intent → requirements → data/app → technology in order, so the location pipeline and matcher in Phase D are consequences, not guesses.
  • A (Vision): match a rider to a nearby driver fast and reliably; principles — real-time, write-heavy on location, strongly consistent on assignment.
  • B (Business): three capabilities — stream driver location, request & match a ride, run the trip.
  • C (Data/App): a hot driver-location store with a geo index, a trips store, and a matcher service; stateful connections to drivers and riders.
  • D (Technology): the real meat — drivers stream GPS into a location store + geo index, a matcher reuses proximity search to find nearby available drivers, high write volume, a trips DB, real-time push, and one-driver-per-request consistency.
  • E–H: launch city-by-city; govern with match-latency and availability SLOs.
  • The lesson: "real-time, write-heavy, consistent on assignment" (Phase A) is exactly why Phase D splits a fast-churning location index from a durable trips store with a locked assignment.

Like an air-traffic board plus a single boarding pass

Picture two things happening in an airport at once. There's a big live board showing where every plane is right now — constantly updating, and nobody minds if a plane's dot is a second behind reality, because the next refresh fixes it. And there's the gate agent handing you a boarding pass for seat 14C — where it is absolutely unacceptable for two people to get the same seat. One job wants speed and freshness; the other wants correctness, no matter what. They feel like the same system but they could not be more different.

Ride-hailing is exactly this pairing. The live board is millions of drivers streaming their GPS every few seconds — a firehose where the latest dot wins and a dropped update barely matters. The boarding pass is the moment one rider is matched to one driver — where a race that hands the same car to two riders is a real-world failure you can't take back. The entire design comes from refusing to run both jobs with the same tool.

What makes it hard — the problem before the solution

  • Two jobs with opposite needs share one app. A torrent of location pings (fast, lossy-OK) and a one-driver-per-rider assignment (slow is fine, wrong is not) must coexist without poisoning each other.
  • The write volume is staggering. Millions of drivers pinging every few seconds is hundreds of thousands of writes per second — persisting each one durably would drown any normal database.
  • The match must find a moving target fast. 'Nearby available drivers' is a spatial search over data that changes every few seconds, and it must return in well under a second.
  • Exactly-one is sacred. Two concurrent ride requests must never claim the same driver — the assignment needs real, strong consistency even though almost nothing else does.

Why work ride-hailing through TOGAF?

Ride-hailing is two very different problems wearing one app: an enormous firehose of GPS updates from moving drivers, and a correctness-critical moment where exactly one driver must be assigned to one rider. Jump straight to technology and you'll conflate them. The ADM's discipline of order keeps them separate: Phase B names them as distinct capabilities with opposite needs, so Phase D can give the location firehose a throwaway, write-optimized index and give the assignment a strongly consistent, locked write — each defending a requirement set earlier.

We walk every phase, but Phase D — Technology Architecture — is where the location pipeline and matcher live.

Phase A — Architecture Vision

Intent: agree what we're building, for whom, and the principles that will constrain every later choice.

  • Vision: a service that matches a rider to a nearby available driver within seconds and tracks the trip in real time, at city-to-global scale.
  • Stakeholders: riders (want a car fast, live ETA); drivers (want nearby requests, reliable tracking); the business (wants high match rates and low wait times).
  • Principles (the constraints that cascade): real-time (locations and ETAs update continuously); write-heavy on location (millions of GPS pings must be absorbed cheaply); strongly consistent on assignment (a driver is matched to at most one rider at a time).

Phase B — Business Architecture

Intent: model the business capabilities and value streams before any technology talk.

  • Value stream: driver goes online → streams location → rider requests a ride → system matches a nearby driver → both track the trip live → trip ends and is recorded.
  • Capability 1 — Stream driver location: extreme write volume, lossy-tolerant (one dropped ping is fine), freshness over durability.
  • Capability 2 — Request & match a ride: correctness-critical — exactly one driver per request; must be fast but above all right.
  • Capability 3 — Run the trip: durable record of pickup, route, fare, status; real-time status pushed to both parties.

Impact: these three could not be more different. Location streaming optimizes for write throughput and tolerates loss; matching optimizes for correctness; trips optimize for durability. That split, found here in Phase B, is exactly what Phase D builds to — three stores with three different consistency postures.

Phase C — Information Systems Architecture (Data & Application)

Intent: define the data and application architecture, and the gap from today (today = nothing; greenfield).

Data architecture

  • Driver location: driverId → (lat, lng, heading, status, updatedAt) — constantly overwritten, indexed by location cell for "who's near here".
  • Trip: tripId → (riderId, driverId, pickup, drop, status, fare, timestamps) — durable, append-and-update, queried by id and by user.
  • Access patterns: for locations, "nearby available drivers to (lat,lng)" — the same spatial range query as the proximity service; for trips, key lookups and user history.
  • Conclusion: the hot location data wants a fast in-memory store with a spatial index (reuse the proximity design); trips want a durable transactional store (see SQL vs NoSQL). Two shapes, two stores.

Application architecture

  • Location-ingest service that absorbs GPS pings and updates the geo index — stateless, horizontally scalable per the Phase A principle.
  • Matcher service that, on a ride request, queries the geo index for nearby available drivers and assigns exactly one.
  • Trip service holding the durable trip lifecycle, plus a real-time channel pushing status to rider and driver.

Phase D — Technology Architecture (the core)

Intent: choose the concrete technologies and the physical/deployment design that realize Phase C — and justify each one against the principles and requirements. This is where a technical interviewer spends most of the time, so we'll cover every step.

The Phase D realization: a write-heavy location pipeline feeding a geo index, a matcher that locks one driver per request, and a durable trips store with live updates.

D1 — Estimate the load (sizing drives technology)

Back-of-envelope sizing (pseudo)
# 3M active drivers, each pings every 4 seconds
location_writes_per_sec = 3_000_000 / 4        # ~750,000 writes/sec

# Ride requests are far rarer than pings
requests_per_sec = 5_000_000 / 86_400          # ~58 ride requests/sec (5M/day)

# Location data is tiny & disposable: overwrite in place, ~100 B/driver -> ~300 MB live
# Trips: 5M/day * 365 * 5y ~ 9B rows, ~1 KB each -> ~9 TB durable
# Verdict: location = massive write throughput, in-memory, lossy-OK
#          trips    = modest rate, must be durable & transactional (set in D2/D4)

The numbers make the Phase B split undeniable: ~750k location writes/sec dwarf ~58 ride requests/sec. The location path is a throughput problem; the match is a correctness problem. They cannot share one store.

D2 — The location pipeline & geo index

  • Drivers stream GPS every few seconds over a persistent connection; an ingest tier writes each ping into a fast in-memory location store keyed by driverId.
  • Index by location cell, exactly as the proximity service does — geohash or grid cells — so "nearby available drivers" is a cell lookup, not a scan.
  • Overwrite in place: each new ping replaces the last; there's no history to keep, so the store stays tiny and writes are cheap.
  • Lossy-tolerant: a dropped ping just means the next one corrects it a few seconds later — freshness over durability, straight from Phase A.
  • Shard the index by region/cell (see Sharding) so the firehose spreads across nodes and most lookups stay on one shard.
Absorb a GPS ping: overwrite in place and re-bucket by cell (python)
# ~750k pings/sec: keep it tiny and disposable, overwrite in place (D2).
def on_location_ping(geo_index, driver_id, lat, lng, status):
    old = geo_index.locations.get(driver_id)
    new_cell = geohash_encode(lat, lng, precision=7)  # fine cell for cities

    # Move the driver between cell buckets only when the cell changes.
    if old and old.cell != new_cell:
        geo_index.cells[old.cell].discard(driver_id)
    geo_index.cells.setdefault(new_cell, set()).add(driver_id)

    # Latest value wins; a dropped ping self-corrects on the next one.
    geo_index.locations[driver_id] = Loc(lat, lng, new_cell, status)

Why an in-memory, throwaway index, and why not persist every ping?

The instinct that gets people in trouble is 'it's data, write it to the database.' Persisting ~750,000 GPS pings a second durably would flatten any normal store — and for what? Yesterday's position of a car is worthless; only its latest location matters. So you keep locations in a fast in-memory store, overwrite in place, and accept that a lost ping self-corrects on the next one. Durability here would be paying a huge bill for data you immediately throw away.

ApproachWhat it buysThe gap it can't fill
Persist every ping to the DBA full location history; nothing is ever lost.~750k durable writes/sec drowns the database — and history of a moving dot has no value.
In-memory, overwrite-in-place (chosen)Absorbs the firehose cheaply; the store stays tiny; latest-wins.Not durable — but a dropped or lost ping self-corrects in seconds, which is acceptable.
Append to a log, index laterDecoupled ingest; replayable.Adds latency and a processing stage for data that's stale the instant it lands — overkill for 'where is this car now'.

D3 — Matching: one driver per request (the correctness core)

  • On a ride request: the matcher computes the rider's cell and searches that cell plus neighbors for available drivers (reusing the proximity neighbor-cell search), then ranks by ETA.
  • Assign exactly one: the chosen driver must be claimed atomically so two concurrent requests can't grab the same car. Mark the driver assigned with a conditional/transactional update (compare-and-set on status), or take a short lock (see Distributed locking).
  • Strong consistency here only: the assignment is the one place we pay for a transactional write — everything else stays eventually consistent. This realizes the Phase A consistent on assignment principle.
  • If the driver declines or times out: release the claim and offer the next-best driver — a bounded retry, not a scan.
Match: find nearby drivers, claim exactly one with compare-and-set (java)
// Correctness core (D3): exactly one rider may win a given driver.
String matchDriver(GeoIndex index, double lat, double lng) {
  // Reuse the proximity neighbor-cell search, then rank by ETA.
  List<Driver> nearby = index.nearbyAvailable(lat, lng);
  nearby.sort(Comparator.comparingDouble(Driver::etaSeconds));

  for (Driver d : nearby) {
    // Atomic claim: flip AVAILABLE -> ASSIGNED only if still AVAILABLE.
    boolean won = store.compareAndSet(d.id(), "AVAILABLE", "ASSIGNED");
    if (won) {
      return d.id();          // this request is the single winner
    }
    // Lost the race to a concurrent request -> try the next-best driver.
  }
  return null;                 // no driver available right now
}

Why compare-and-set, and why not just read-then-write?

The naive match reads the list of available drivers, picks one, then writes 'assigned.' Under load this is a classic race: two requests both read the same driver as available, both pick it, both write 'assigned' — and now two riders own one car. Compare-and-set closes the gap by fusing the check and the write into one atomic step: 'set to ASSIGNED only if still AVAILABLE.' Exactly one request can win that transition; the loser sees failure and moves to the next driver. A distributed lock achieves the same guarantee with more machinery — fine when the claim spans multiple writes, but heavier than a single CAS.

ApproachWhat it buysThe gap it can't fill
Read-then-writeSimple; one query then one update.A race: two requests read the same driver as free and both assign it — double-booking, the one unforgivable bug.
Compare-and-set (chosen)Atomic 'flip only if unchanged'; exactly one winner, minimal overhead.Only guards a single value — fine here, since the claim is just a status flip.
Distributed lockGuards a multi-step critical section, not just one field.More moving parts (lease, renewal, fencing); overkill when a single CAS suffices.

D4 — The trips store & real-time updates

  • Trips DB: a durable, transactional store for the trip lifecycle (requested → matched → en route → completed), queried by tripId and by user (see SQL vs NoSQL); replicate for durability (see Replication).
  • Real-time push: rider and driver each hold a persistent connection (see WebSockets) so ETA, driver position, and status stream live without polling.
  • Decouple side effects: fare calculation, receipts, and notifications run off a queue (see Message queues) so they never block the match or the live trip view.
  • Idempotency on the request-ride call (see Idempotency) so a retried tap doesn't create two trips.

D5 — The edge & cross-cutting concerns

  • Front the APIs with a load balancer (see Load balancing) and a rate limiter (see Rate limiting) to protect the ingest and request paths.
  • Observability: trace the request-to-match path and alert on match latency, match rate, and location-write lag (see Distributed tracing).
  • Consistency posture, explicit: location is eventually consistent, the assignment is strongly consistent, trips are durable (see Consistency models) — three postures by design, not by accident.

Scaling & bottlenecks — what breaks first

Turn the dial up and ride-hailing fails in a predictable order. The location firehose is built to absorb load, so the first thing to buckle is usually a hot city or the assignment contention when demand spikes against scarce supply.

Breaks first as you scaleThe symptomThe fix
A hot city shardRush hour in one metro overloads the single node owning its cells.Shard the geo index finer within the city; replicate hot shards; route by cell so load spreads.
Assignment contentionMany riders chase few drivers; CAS failures spike and matching retries thrash.Batch-match in a short window; fan requests to distinct top candidates; back off and widen the search.
Location write amplificationRe-bucketing drivers between cells on every ping dominates CPU.Only move a driver when its cell actually changes; coarsen ping frequency for idle drivers.
WebSocket connection fan-outMillions of simultaneous live-trip connections exhaust a push tier.Shard the connection gateways; push only on meaningful change; drop to periodic updates when idle.

Phases E & F — Opportunities, Solutions & Migration Planning

  • Greenfield, so sequence by risk and geography: launch one city with the location index, matcher, and trips store before going multi-region.
  • Reuse first: stand up the geo index from the proximity service rather than reinventing it, so the firehose has a proven home on day one.
  • Add live tracking and async receipts after the core match works — each is independently shippable and reversible, the same strangler-fig / expand-contract spirit as the TOGAF commerce scenario.

Phases G & H — Governance & Change Management

  • Governance (G): define SLOs (e.g. match p95 < 5s, 99.95% availability on the request path), set per-client quotas on the ingest API, and review that the build still honors the Phase A principles — especially one-driver-per-request.
  • Change management (H): adding pooled rides, surge pricing, or a new vehicle class is a bounded change, not a re-architecture — because location, matching, and trips were kept on clean boundaries.

Why do driver locations and trip records live in two different stores?

Because they have opposite needs. Location is a firehose of GPS pings — extreme write volume, lossy-tolerant, and only the latest value matters, so it fits a fast in-memory geo index that's overwritten in place. Trips must be durable, transactional, and queryable by id/user, so they belong in a replicated transactional store. Forcing both into one store would either drown the trip store in writes or make the location path needlessly durable and slow.

Hint: Compare write volume and durability needs of a GPS ping vs. a completed trip.

A rider taps 'request'. How do you guarantee two riders can't be matched to the same driver?

Make the assignment an atomic, strongly-consistent operation: the matcher finds candidate drivers from the geo index, then claims one with a conditional update (compare-and-set on the driver's status from 'available' to 'assigned') or a short lock. Only one concurrent request can win that transition; the rest see the driver is taken and move to the next candidate. The geo index can be eventually consistent, but the assignment is the one place you pay for strong consistency.

Hint: Which single step needs strong consistency, and what primitive enforces 'exactly one winner'?

Your matcher is slow under load. Before scaling, what would you check?

Whether the geo search is bounded: are you reading just the rider's cell plus neighbors (good) or scanning too wide a radius repeatedly (bad)? Whether the location index is sharded by region so a hot city isn't all on one node. Whether the assignment lock is being held longer than the claim itself. And whether side effects (fare calc, notifications) are wrongly on the synchronous match path instead of a queue.

Hint: Think about the spatial query's blast radius, sharding, lock duration, and what's blocking the critical path.

Why is it safe for driver location to be eventually consistent but not the trip assignment?

A location that's a second or two stale just means a driver is shown slightly behind their real position — the next ping corrects it, and no harm is done. A stale or racy assignment means two riders believe they have the same car, which is a real-world failure you can't undo gracefully. You spend strong consistency only where incorrectness is unacceptable, and accept eventual consistency where it isn't — drawing the line per capability.

Ride-hailing is where real-time location, high-write ingestion, and transactional correctness collide — and it shows how reusing a proximity service turns a terrifying problem into a tractable one.

Why it matters

  • It separates a write-throughput problem (locations) from a correctness problem (assignment) — the single most important modeling move in the design.
  • It demonstrates reuse: the proximity geo-index is dropped straight in to answer 'nearby available drivers'.
  • It shows a system holding three consistency postures at once, each deliberate and defensible.

If ignored

  • You store every GPS ping durably and drown in write load, because location was treated like trip data.
  • Two riders get the same driver, because the assignment wasn't made atomic.
  • Receipts and pricing block the live trip, because side effects weren't decoupled.

Where it fits

  • Phase D is the technical core — location pipeline, reused geo index, locked matcher, durable trips, real-time push.
  • Earlier phases (A–C) supply the real-time, write-heavy, consistent-on-assignment constraints; later phases (E–H) handle city-by-city rollout and governance.
  • It sits beside the proximity service as its real-time, correctness-critical sibling.

Related topics

Interview lens

Questions it unlocks

  • Design Uber / Lyft ride-hailing.
  • How do you ingest millions of GPS updates per second and still match fast?
  • How do you guarantee exactly one driver is assigned to one rider?

60-second answer

I'd frame it as an ADM walk. Phase A sets principles — real-time, write-heavy on location, strongly consistent on assignment. Phase B names three very different capabilities: stream location, match a ride, run the trip. Phase C splits the data into a hot, disposable location store with a spatial index versus a durable trips store. Then Phase D is the real design: drivers stream GPS every few seconds into an in-memory location store, indexed by cell exactly like the proximity service, overwritten in place and lossy-tolerant because freshness beats durability. On a request the matcher searches the rider's cell plus neighbors for available drivers and claims exactly one with a compare-and-set or short lock — the single place I pay for strong consistency. Trips live in a durable transactional store, status streams over WebSockets, and side effects like fares run off a queue. E–H launch city-by-city under match-latency SLOs. Every Phase D mechanism traces back to a Phase A principle — including the deliberate three different consistency postures.

Common traps

  • Persisting every GPS ping durably instead of overwriting a tiny in-memory index, drowning in write load.
  • Making the driver assignment non-atomic, so two riders can grab the same car.
  • Letting fare calculation, receipts, or notifications block the match or the live trip view.

Search topics

↑↓ to move · Enter to open · Esc to close