Problem
A patient looking for a doctor wants results sorted by the earliest free appointment. Doctolib computed free slots on the fly, and one doctor's calendar takes from several dozen to several hundred milliseconds. The rules are heavy: opening hours, absences, bookings, shared equipment and assistants, insurance-specific hours, per-day limits. A search covers from a handful to thousands of doctors. Brute force is too slow, and a 50% speed-up would not help.
Example from the article: 1000 doctors at 100 ms on average is 10 seconds per search, and 2000 doctors at 200 ms is 40 seconds. The target was a couple of hundred milliseconds for hundreds of doctors, a 99% improvement.
Solution in brief
Precompute the stable, input-independent first part of the slot calculation and store it as an intermediate representation. At request time, load it and run only the fast second part to get each doctor's first available slot. Nightly jobs and event listeners keep the data fresh.
Questions this case answers
- How to rank a large candidate set by a value that is expensive to compute per item when the response budget is a few hundred milliseconds and the inputs change all day
- How to split an expensive computation into a stored stable part and a fast request-time part so that logic changes do not invalidate the store
- How to sort hundreds of doctors by earliest available appointment within a couple of hundred milliseconds when one doctor's availability takes up to hundreds of milliseconds to compute?
- How to precompute an expensive per-item calculation without invalidating the stored data on every logic change?
Tools and methods
- Intermediate representation of availabilities — stored result of phase 1 of the slot calculation
- Two-phase computation — slow stable phase offline, fast phase per request
- Layered cache invalidation — events, nightly rebuild, variable TTL
- Proof of concept framed as questions — scoping the feasibility study
- Shadow production, feature toggles, canary and cluster rollout — gradual release
- Redis — cache backend
- Sentry — crash monitoring
Google or a one-time email code. No password.