KatInterview

Build a Live Bike Rental Platform: Tracking, Holds and Unlocks

System DesignModel answer
MediumModel answerSystem Designsystem-designgeospatialconcurrency

Last updated

Design a bike rental backend where riders see nearby bikes live, hold one, unlock it, and end the trip, covering telemetry ingestion, geospatial lookup and race-free reservations.

You are asked to design the backend for a city-scale bike rental service. A rider opens the mobile app, sees bikes close by on a map, holds one for a short time, unlocks it, rides, and finishes by locking it. The platform must always know where each bike is and which state it is in.

Assumptions:

  • Every bike has a smart lock with GPS and a cellular modem. It reports position and lock status and can receive an unlock command.
  • Whether bikes return to docks or can be parked anywhere in a service zone is up to you to clarify. Point out which parts of your design depend on the answer.
  • Payments are mostly out of scope. You only need to start and stop billing for a trip.

Questions you may want to ask first: docked or free-floating, how long a hold lasts and whether one rider may hold several bikes, the target scale (bikes, cities, peak concurrent trips), and how fresh and accurate map positions must be.

Part 1: Requirements and core flows. List functional and non-functional requirements and rough load estimates. Sketch the components, data model, bike state machine and APIs for find, reserve, unlock, ride and return.

Part 2: Location tracking and the write path. Pick a location reporting rate and defend it. Describe how updates travel from the bike to a rider's map, and how you stop the update volume from overwhelming your database. Cover offline bikes and out-of-order messages.

Part 3: Reservations, unlocking and contention. Two riders try to hold the same bike in the same second. Explain how exactly one wins, how holds expire, and how unlock and trip start/end stay consistent when the bike's connection is flaky.

Hints

Hint 1

Separate the data into two kinds: slow-changing transactional state (bike status, reservations, trips) and fast, disposable telemetry (positions). They deserve different stores and different guarantees.

Hint 2

For the reservation race, think of a single conditional write on the bike's row (compare-and-set on status or version) rather than a distributed lock held across services. Add an expiry timestamp so a hold cleans itself up.

Hint 3

Assume every message to or from a bike can be lost, duplicated or delayed. Give each command a unique ID, make handlers idempotent, and define what the server believes when the bike never answers.