ఒక hot post పై ప్రతి event కి UPDATE posts SET views = views + 1 ను ఎప్పుడూ చేయవద్దు — ఆ ఒక్క row ఒక lock bottleneck అవుతుంది. Redis లో increment చేసి, ప్రతి కొన్ని సెకన్లకు DB కి batch-flush చేయండి, మరియు count ను Redis నుండి read చేయండి. DB live traffic కాదు, durable totals ను store చేస్తుంది.
ఆర్కిటెక్చర్
Client tap ─▶ API ─▶ Redis INCR views:{post} (live, source of truth for reads)
│ └── dedup: SADD seen:{post} {user/ip}
▼
every ~5s / N ops
Flusher ─▶ UPDATE posts SET views = views + delta (durable)
▲
read path: GET Redis (fallback DB on miss)
