Pick the fix
A page-view counter takes 20,000 increments a second and can lose a few seconds of counts on a crash. Best write strategy?
Hint 1 of 1
Can you afford to lose a few seconds?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Write-behind: INCR in Redis, flush totals to the database every few seconds
Correct. Fast writes; the bounded loss is acceptable here.
When some loss is acceptable, counting in memory and writing totals in batches turns 20,000 row updates a second into one write every few seconds. The risk is only the counts since the last flush.
Why not the others?
- B Write-through: update the database on every view. 20,000 row updates a second on one hot row.
- C Write-around: only write the database. Same database load.
- D No cache. The database becomes the bottleneck.