System Design AI

Design a Ride-Sharing Dispatch System: Junior, Senior and Staff Answers

When you hear "design a ride-sharing dispatch system" the interview is probing three things: how you think about real-time matching, how you balance latency against consistency, and how you anticipate operational complexity. The problem is concrete enough to sketch a full request path, yet open enough to discuss sharding strategies, caching layers, and failure handling. Below we walk through the core design, then layer on what each interview level is expected to deliver.

Core Design Overview

1. Request flow, one hop at a time

  1. Rider request – The mobile client sends a POST /requestRide with GPS coordinates and rider preferences to an API Gateway (AWS API Gateway). The gateway forwards the request to a stateless Dispatch Service (ECS/Fargate) via an internal ALB.
  2. Persist request – The service writes the ride request to a DynamoDB table RideRequests. The primary key is requestId; a GSI on status lets us query pending rides.
  3. Locate nearby drivers – The service queries an ElastiCache Redis geospatial index (GEOADD/GEOSEARCH) that holds each driver's latest location (updated every few seconds by driver apps). A radius query returns a shortlist of candidate drivers.
  4. Matchmaking – The Dispatch Service runs a simple scoring function (distance, vehicle type, driver rating). It picks the best driver and writes a Match record to DynamoDB (Matches table). The driver’s entry in Redis is marked busy.
  5. Notify driver – The service publishes a message to an SQS queue DriverNotifications. A Lambda consumer pulls the message and pushes a push notification to the driver’s device.
  6. Confirm ride – The driver accepts, hitting POST /acceptRide. The service updates the Match status and writes an event to an MSK Kafka topic RideEvents for downstream analytics.
  7. Trip tracking – During the trip the driver app keeps sending location updates, which refresh Redis and are pushed to the rider over a WebSocket connection. The raw points are archived to S3 (hourly partitions) for analytics.

2. Data model snapshot

EntityPrimary KeyImportant AttributesAccess Pattern
RideRequestsrequestId (UUID)riderId, pickupLatLng, dropoffLatLng, statusGet by requestId, scan pending status
DriversdriverId (UUID)currentLatLng, vehicleType, rating, statusRedis geospatial index for fast geo lookup
MatchesmatchId (UUID)requestId, driverId, score, statusQuery by requestId, stream to Kafka

3. Key architectural choice

We choose DynamoDB for persistent state because it gives single-digit millisecond reads, automatic scaling, and strong consistency when needed (e.g., confirming a match). The alternative would be Aurora MySQL, which offers richer queries but higher latency and more operational overhead. DynamoDB’s write-throughput can be provisioned to handle the peak request rate, and its partition key design (UUID) spreads load evenly.

What the Interviewer Is Testing

  • Scalability – Can you estimate request volume and size the data plane?
  • Latency – How will you keep the rider-to-driver match under a few seconds?
  • Consistency vs. availability – When a driver accepts, how do you avoid double-booking?
  • Operational insight – Do you think about monitoring, failure recovery, and cost?

Driving Numbers (Ballpark)

  • Peak request rate – Assume the whole platform peaks at 10 k ride requests per second (about 864 million per day if sustained). That is deliberately generous, well above what any single city produces, so the design has headroom.
  • Matching latency target – Riders expect a driver within 5 seconds. This drives our choice of in-memory location store (Redis) and the need for sub-second DynamoDB reads.
  • Driver update frequency – Drivers push location every 5 seconds. With 500 k active drivers, that's 100 k updates per second, which calls for a partitioned stream (Kinesis or Kafka) feeding the Redis location store.

Junior Answer Checklist

  • State the basic request flow (API → service → DB → driver notification).
  • Sketch a simple data model with RideRequests and Drivers.
  • Mention DynamoDB for persistence and Redis for fast driver lookup.
  • Identify primary latency goal (under 5 seconds) and give the rough request volume.
  • Note that the system can be horizontally scaled by adding more ECS tasks.
  • Misses: no discussion of sharding, no caching beyond Redis, no operational metrics.

Senior Answer Additions

  • Sharding strategy – Partition RideRequests by geographic region (e.g., city) to keep hot partitions low. Explain how a composite key city#requestId spreads traffic.
  • Cache warm-up – Use a read-through pattern: if a driver location is missing in Redis, fall back to DynamoDB and repopulate the cache.
  • Reliability – Add SQS dead-letter queues for failed notifications, and retry logic in the Lambda.
  • Metrics – Emit CloudWatch custom metrics for request latency, match success rate, and driver-busy ratio.
  • Cost awareness – Show rough cost: DynamoDB reads/writes at 10 k RPS, Redis on-demand instances, and S3 for logs.
  • Misses: no deep failure-mode analysis, no discussion of operational runbooks.

Staff Answer Depth

  • Failure modes – Enumerate scenarios: driver app crash after assignment, network partition between API Gateway and DynamoDB, Redis cache eviction, Kafka broker outage. Propose mitigations: idempotent match writes, fallback to DynamoDB for driver status, use MSK replication, and implement a periodic reconciliation job.
  • Operational tooling – Describe a health-check dashboard aggregating latency percentiles, a canary deployment pipeline for the Dispatch Service, and automated scaling policies for ECS based on request queue length.
  • Cost optimization – Suggest using DynamoDB on-demand for burst traffic, then moving to provisioned with auto-scaling for steady state. Use Redis cluster with auto-scaling shards, and enable S3 Intelligent-Tiering for trip logs.
  • Defendable trade-off – Choose strong consistency on match confirmation over eventual consistency to avoid double-booking, accepting a slight increase in write latency. Explain why the user experience cost of a double-booked ride outweighs the latency penalty.
  • Operations runbook – Outline steps for a driver-busy-stale bug: (1) pause new matches, (2) run a reconciliation script that scans pending matches and re-queues unmatched requests, (3) resume service after cache warm-up.

Common Mistakes That Sink the Question

MistakeWhy it hurts
Ignoring latencyFails to address the core user expectation; interviewers will probe how you keep matching under 5 seconds.
Over-engineering the data modelAdds unnecessary complexity; a simple key-value store is sufficient for the core flow.
Forgetting idempotencyLeads to double-booking when retries occur; interviewers look for safe writes.
Not discussing scalingWithout sharding or auto-scaling, the design cannot handle peak traffic.
Skipping failure handlingReal-time systems need graceful degradation; missing this signals a lack of operational mindset.

How to practice this

  1. Study the worked design in the System Design AI library. Observe how the diagram builds the request path step by step.
  2. Create your own canvas: draw the flow, label each AWS component, and write brief notes for each block (what it does, what to say, typical failure).
  3. Run through the practice brief: use the provided rubric to check that you covered requirements, numbers, junior, senior and staff depth, and the common pitfalls.

Questions people ask

What are the main scalability concerns for a ride-sharing dispatch system?

The biggest concerns are handling a high request rate (tens of thousands per second) and keeping driver-lookup latency low. You need to shard data by region, use in-memory stores for driver locations, and design the write path to avoid hot partitions.

Why choose DynamoDB over a relational database for ride requests?

DynamoDB provides single-digit millisecond reads and writes, automatic scaling, and fine-grained throughput control. A relational database would add latency and operational overhead without offering a clear advantage for the simple key-value access pattern.

How do you prevent double-booking of a driver?

Make the match write idempotent and use a conditional update on the driver’s status in DynamoDB (or Redis) so that only one match can succeed. If the update fails, retry with another driver.

What is a good way to monitor latency in this system?

Emit custom CloudWatch metrics for each stage of the request path (API latency, dispatch service latency, driver notification latency) and set alarms on the 95th-percentile to stay within the 5-second target.