The Day View That Is Fast For Quiet Clinics

Decide what you would do from the brief alone, including whether you would change anything at all. Everything below it is available, but the exercise stops working if you open it first.

The brief you were given

The clinician's day view takes several seconds for a busy clinic and is instant for a quiet one. The endpoint calls appointmentRepository.findByClinician(id) and then, for each appointment, reads patient.insurancePolicy.status.

The trap — the fix that looks like good design and is not

Putting a cache in front of the policy lookup. The day view gets fast, the change is small and local, the query count in the logs drops by an order of magnitude, and there is a metric to show for it. You have introduced a staleness question about the one piece of data the view exists to display — coverage status, which changes exactly when a policy lapses — and the N+1 is still there for every cold entry, so the slow path is now rare, unpredictable and concentrated first thing in the morning when the cache is empty and every clinician opens their day at once. The sibling trap is enabling eager loading globally, which fixes this view and loads the policy for every other query in the system.

Read this even if you are confident. It is here rather than behind a button because it is the answer most teams actually ship, it passes review, and the cost of it does not arrive until the change after this one.