CSE Roadmap

Core tier · about 4 hours · 6 parts

Part 2 of 6 · 2 min read

Requirements

Request, match, ride, pay.

Think of a taxi rank where the dispatcher has a radio. A rider calls with a pickup place. The dispatcher looks at the free cabs, picks one that is close, and tells the driver. The driver drives to the rider, then to the destination. At the end the rider pays by a meter. If the rider changes their mind early, the cab goes back to the rank.

Questions and the answers assumed here:

  1. Where is everything? Each driver and each pickup has a location on a plane. Distance is a straight line, as a simplification.
  2. How is a driver chosen? The nearest available driver. This should be replaceable.
  3. What if no driver is free? The request fails with a clear answer.
  4. What can the rider do? Request, and cancel before the trip starts.
  5. How is the fare set? A base amount, a rate per kilometre and a rate per minute, with an optional surge multiplier.
  6. Many requests at once? Yes.
  7. Out of scope: maps and roads, payments, ratings, and pooling.

The numbered requirements:

  • R1. A driver is offline, available or on a trip.
  • R2. A request goes to the nearest available driver.
  • R3. A driver is never assigned to two trips at once.
  • R4. A trip moves through requested, assigned, started and completed. It may be cancelled before it starts.
  • R5. Illegal moves, such as starting a cancelled trip, are refused.
  • R6. When a trip ends, the driver becomes available at the drop-off point.
  • R7. The fare comes from a replaceable rule.

State machine

A state machine is a model with a fixed set of states and a fixed set of allowed moves between them. Any move not in the set is refused.

Example: a trip may go from assigned to started, but never from completed back to started.

Check yourself: 1. Why must a driver never hold two trips? 2. Which moves are allowed from the assigned state? 3. Where is the driver after a trip ends?