Normalization & DenormalizationdebuggingIntermediate

The follower count is visibly wrong

Symptoms

  • A profile shows 1,240 followers but listing the followers returns 1,207.
  • The discrepancy varies per user and grows over time.
SELECT u.follower_count AS cached, count(f.id) AS actual
FROM users u LEFT JOIN follows f ON f.followee_id = u.id
WHERE u.id = 7 GROUP BY u.follower_count;
  cached: 1240   actual: 1207   drift: 33

Investigate

Inspect areas in any order (0/4 inspected). When you think you know the root cause, commit to it.

How the counter is maintained
Code paths that modify follows
Transaction boundaries
Race conditions