Design a Station-Based Bike Sharing Platform
Show nearby station availability, unlock a dock by QR code, end rides safely, and price completed distance.
Problem statement
For this exercise, assume the following practice scope. Design a station-based bike sharing platform. A rider sees nearby stations and approximate available bike and dock counts, scans a QR code for a specific bike or dock, and requests unlock.
A station controller performs the physical unlock and reports a signed result. Exactly one active ride may own a bike and rider. Ending a ride requires a dock controller to secure the bike; the ride closes only after that authoritative physical event.
Price is based on accepted ride distance derived from ordered telemetry, with an explicit fallback when telemetry is incomplete. Search counts may be stale, but unlock and return decisions use station inventory authority.
Design station discovery, inventory, QR and device authentication, unlock, ride state, telemetry, return, pricing, synchronization, offline station behavior, and reconciliation. Payment collection, bike maintenance logistics, and fleet rebalancing optimization are outside scope.
What to build
- Find nearby stations with freshness-marked available bike and dock counts.
- Authenticate a QR target and complete one retry-safe physical unlock.
- Maintain one active ride per rider and bike with guarded state transitions.
- Accept ordered distance telemetry and compute an auditable final price with fallback.
- End a ride only after a station controller proves the bike is secured in a dock.
At scale
- Assume 20,000 stations, 500,000 bikes, 100,000 concurrent rides, and 10,000 unlock attempts per second at peak.
- Nearby search should finish within 300 ms p95; online unlock and return within three seconds p99.
- Station controllers may be disconnected for up to fifteen minutes, and telemetry may arrive late or duplicated.
- No timeout or retry may start two rides, unlock two bikes for one request, or charge one ride twice.