Databases · Senior · Question 13 of 75

Many requests update the same counter row (UPDATE stats SET views = views + 1 WHERE id = 1). What's the problem and a fix?

Explanation

Each update waits for the previous one to commit. Sharded counters (N rows summed on read) or counting in Redis with periodic flushes remove the contention.

Further reading

Problem with a question

Databases · Senior · question 13

Test yourself

Take the Databases · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz