Design a ride sharing service
hard 90 minModel riders, drivers, offers and trips as objects.
Watch lesson4:42
Where it shows up
The same pattern appears across everyday software.
H3
An open source grid of hexagons over the globe, developed to address the data science needs of Uber. Cells have a resolution, and neighbours within k steps can be listed: the rings of the matching page.
S2 Geometry
A library that works on a sphere and not on a flat map. It maps the globe to cells with 64 bit ids, so cells can be keys of an ordinary index.
Redis GEOSEARCH
Members with a longitude and latitude, searched by radius or box and sorted by distance. A geo index that several processes can share. Taking a driver still needs its own atomic step.
PostGIS nearest neighbours
`ORDER BY place <-> point LIMIT 10` uses a GiST index for a true nearest neighbour search. A few rows, sorted by distance, without a walk over the table.
OSRM table service
Computes the duration of the fastest route between all pairs of given coordinates. This is the ranking by travel time, and the input of a batch.
Valhalla
An open source routing engine with time and distance matrices and map matching: noisy points become a path on roads, as in the meter of the tracking page.
Stripe idempotent requests
A key with the request lets a client repeat it safely after a broken connection. It is the `trip-2` of `charge`.
Stripe: hold, then capture
Authorisation and capture can be separate calls, so a card is checked before the ride and charged with the final amount after it.
Java LongAdder
Its documentation calls it usually preferable to AtomicLong for statistics under contention, and says that the sum is not an atomic snapshot. Right for ride counters, wrong for money.
Transactional outbox
The pattern saves a message in the same database transaction as the change and relays it later. Here: trip and event.