# Design a Ride-Sharing Matching System — System Design: Architecture, Scale and Trade-offs

Source: https://www.skillbyai.com/en/system-design/sd-design-ride-sharing

> Design a ride-sharing matcher using geohash or quadtree indexes and atomic assignment to handle surges.

## Requirements

Drivers stream their location continuously; a rider requests a trip and should be matched with a nearby available driver within a few seconds; the system must handle a surge (concert ending) without collapsing.

## Geospatial indexing

Divide the map into cells using **geohashing** or a **quadtree**, and keep an in-memory index of `cell -> available drivers`. A match query looks up the rider's cell and expanding rings around it instead of scanning every driver on Earth.

## Air traffic control, not a phone book

You don't find a nearby driver by scanning a list of every driver's exact address, like a phone book. It's more like air traffic control watching a live radar grid — drivers constantly update their cell, and the matcher only looks at the handful of nearby blips.

## Handle the race: two riders, one driver

Two match requests can target the same driver simultaneously. Use an atomic compare-and-set (or a per-driver lock) so exactly one request wins the driver and the other retries against the next-nearest candidate.

## Final quiz 1 of 8

Final quiz

**Quiz:** Which is a non-functional requirement?

- [ ] Users can post a message
- [ ] Users can edit a profile
- [x] p99 latency under 200ms
- [ ] Users can search orders

*Answer:* p99 latency under 200ms. Non-functional requirements describe quality: latency, availability, scale.

## Final quiz 2 of 8

Final quiz

**Quiz:** Roughly what average QPS is 86.4M requests per day?

- [ ] 10
- [ ] 100
- [ ] 10,000
- [x] 1,000

*Answer:* 1,000. A day has about 86,400 seconds, so 86.4M / 86,400 ≈ 1,000 QPS.

## Final quiz 3 of 8

Final quiz

**Quiz:** What does cache-aside do on a cache miss?

- [x] The app loads from the database and fills the cache
- [ ] The cache calls the database itself
- [ ] The request fails
- [ ] The database writes to the CDN

*Answer:* The app loads from the database and fills the cache. In cache-aside the application owns loading and populating the cache.

## Final quiz 4 of 8

Final quiz

**Quiz:** Which problem does consistent hashing mainly solve?

- [ ] Slow TLS handshakes
- [x] Massive key remapping when nodes change
- [ ] Duplicate messages
- [ ] SQL injection

*Answer:* Massive key remapping when nodes change. Only a small share of keys move when a node joins or leaves.

## Final quiz 5 of 8

Final quiz

**Quiz:** Why do at-least-once consumers need to be idempotent?

- [ ] Messages are always lost
- [ ] Queues are encrypted
- [x] Messages can be delivered more than once
- [ ] Ordering is guaranteed

*Answer:* Messages can be delivered more than once. Retries cause duplicates, so repeating work must be safe.

## Final quiz 6 of 8

Final quiz

**Quiz:** In a network partition, a CP system will…

- [ ] Return stale data to everyone
- [ ] Ignore the partition
- [ ] Add more replicas automatically
- [x] Reject some requests to stay consistent

*Answer:* Reject some requests to stay consistent. CP chooses consistency over availability during a partition.

## Final quiz 7 of 8

Final quiz

**Quiz:** What does a circuit breaker do?

- [x] Stops calling a failing dependency to prevent cascades
- [ ] Encrypts traffic
- [ ] Caches responses forever
- [ ] Shards the database

*Answer:* Stops calling a failing dependency to prevent cascades. It fails fast so one slow dependency does not take down callers.

## Final quiz 8 of 8

Final quiz

**Quiz:** What should you do first in a design interview?

- [ ] Draw the database schema
- [x] Clarify requirements, users and scale
- [ ] Pick a cloud provider
- [ ] List every technology

*Answer:* Clarify requirements, users and scale. Requirements and scale drive every later decision.
