Keeping the ride alive: why CyclingPlay simulates on the client

The ride simulation in CyclingPlay runs entirely in the rider's browser. Every input source, from today's keyboard to the trainer sensors coming next, is only an adapter feeding that loop. The backend stores rides and never gates a pedal stroke. This record lays out the server-authoritative design we turned down, why we turned it down, and the one product shift that would make us revisit it before freeze.

The option we rejected

The strongest alternative was a server-authoritative session. The browser streams cadence and power to a backend, the backend integrates speed and position on the virtual course, and the client only renders what it receives. It deserves a fair hearing. One source of truth makes leaderboards trustworthy, because a rider cannot edit a local physics constant and post an impossible climb, and it makes group rides trivial to synchronise since every participant reads the same state. It also lets us tune the rider model centrally without shipping a client release. Teams building competitive indoor platforms choose this route for good reasons.

Why the loop stays on the client

The cost of that design is that every network hiccup becomes a physical event for someone sweating on a bike. With the server in the loop, a dropped WebSocket freezes the avatar or snaps it backwards on reconnect, and a backend outage ends every ride at once. That puts a single shared failure domain into a product whose core experience is solitary. Running the integrator locally splits the system into parts that fail independently: the input adapter, the simulation, the renderer and the sync service. The ride is buffered on the device and uploaded when the backend answers, so a server outage costs history, not exercise. We accept that results posted this way are self-reported, and we label them that way.

When the sensor goes quiet

The failure that matters most arrives with real hardware. Trainers and sensors speak through fitness interoperability profiles such as Bluetooth FTMS and ANT+, and a Bluetooth link from a laptop or phone drops more often than anyone expects, through radio interference, a sleeping screen or a browser tab losing focus. Both naive implementations fail badly: zeroing power on disconnect stops the rider dead mid-climb, while holding the last value keeps the bike cruising indefinitely with nobody pedalling. Our rule is that any sample older than 3 s is stale. At that point the simulation switches to a coasting decay governed by gradient and drag, the segment is flagged as unverified, and the keyboard adapter becomes live again so the rider can keep moving while the sensor reconnects in the background. Within that window the last value is held, because short gaps are far more common than real stops.

What would change the answer

If ranked, real-time races between riders become the product rather than a feature, the trust argument outweighs the isolation argument, and the right move is to keep this local loop for feel while adding a server that replays submitted input streams and certifies results, not one that drives the avatar.

Why not make the 3 s window adapt to each sensor's reporting rate?

We may, once we have field data. A fixed window is easier to test and explain, and being slightly conservative with a fast-reporting power meter only costs a brief coast that nobody notices.

Back to CyclingPlay · Domains

← Back to CyclingPlay
Engineering & Architecture Brief

Keeping the ride alive: why CyclingPlay simulates on the client

The ride simulation in CyclingPlay runs entirely in the rider's browser. Every input source, from today's keyboard to the trainer sensors coming next, is only an adapter feeding that loop. The backend stores rides and never gates a pedal stroke. This record lays out the server-authoritative design we turned down, why we turned it down, and the one product shift that would make us revisit it before freeze.

The option we rejected

The strongest alternative was a server-authoritative session. The browser streams cadence and power to a backend, the backend integrates speed and position on the virtual course, and the client only renders what it receives. It deserves a fair hearing. One source of truth makes leaderboards trustworthy, because a rider cannot edit a local physics constant and post an impossible climb, and it makes group rides trivial to synchronise since every participant reads the same state. It also lets us tune the rider model centrally without shipping a client release. Teams building competitive indoor platforms choose this route for good reasons.

Why the loop stays on the client

The cost of that design is that every network hiccup becomes a physical event for someone sweating on a bike. With the server in the loop, a dropped WebSocket freezes the avatar or snaps it backwards on reconnect, and a backend outage ends every ride at once. That puts a single shared failure domain into a product whose core experience is solitary. Running the integrator locally splits the system into parts that fail independently: the input adapter, the simulation, the renderer and the sync service. The ride is buffered on the device and uploaded when the backend answers, so a server outage costs history, not exercise. We accept that results posted this way are self-reported, and we label them that way.

When the sensor goes quiet

The failure that matters most arrives with real hardware. Trainers and sensors speak through fitness interoperability profiles such as Bluetooth FTMS and ANT+, and a Bluetooth link from a laptop or phone drops more often than anyone expects, through radio interference, a sleeping screen or a browser tab losing focus. Both naive implementations fail badly: zeroing power on disconnect stops the rider dead mid-climb, while holding the last value keeps the bike cruising indefinitely with nobody pedalling. Our rule is that any sample older than 3 s is stale. At that point the simulation switches to a coasting decay governed by gradient and drag, the segment is flagged as unverified, and the keyboard adapter becomes live again so the rider can keep moving while the sensor reconnects in the background. Within that window the last value is held, because short gaps are far more common than real stops.

What would change the answer

If ranked, real-time races between riders become the product rather than a feature, the trust argument outweighs the isolation argument, and the right move is to keep this local loop for feel while adding a server that replays submitted input streams and certifies results, not one that drives the avatar.

Technical FAQ: Why not make the 3 s window adapt to each sensor's reporting rate?

We may, once we have field data. A fixed window is easier to test and explain, and being slightly conservative with a fast-reporting power meter only costs a brief coast that nobody notices.

Related Architecture Specifications (CYCLINGPLAY): vrindoorcycling.com · cyclingplay.com

More Technical Articles on vrindoor.com

Keep the ride local when the sensor goes silent →Decoupling Cadence Ingestion from Frame Stepping in Browser Cycling Simulation →