Day 12 10 min
Counting page views
1 / 6 · ≈ 14 min left
The problem
A recipe site shows each author a dashboard: how many people opened each of their recipes, hour by hour. Nadia posts a soup recipe at 9 a.m. and refreshes the dashboard at 9:05 to see if anyone came.
Each page load sends one small request to the site: "page 48213 was viewed". On a Sunday evening that is 20 000 requests per second.
The first version ran UPDATE pages SET views = views + 1 for each request. Every view of a popular page waited for the same row lock.