← PracticeBeginnerShared State

The Counter That Is Always Low

Pull up the evidence one item at a time, commit to a diagnosis, and only then see the schedule that actually ran.

What was reported

We count feature-flag evaluations in memory and scrape the map every 15 seconds. In the test suite the count is exact. In production it is always low and never high — yesterday the request log had 1,204,338 evaluations and the counter reported 1,199,871. That is a 0.37% shortfall. Nothing throws, nothing is logged, and the gap gets wider on our busiest hosts.
1# metrics.py — one process, 8 worker threads, CPython 3.12
2from collections import defaultdict
3
4counts = defaultdict(int)
5
6def record(flag: str) -> None:
7 counts[flag] += 1 # read, add, store — not one operation

Evidence

Nothing here is labelled as relevant. Some of it is not.

What is actually happening?