A hot row is a database row modified frequently by concurrent transactions. Relational databases commonly lock the affected row, forcing competing updates to wait and increasing latency. section 6.11.1
Popular-post likes
A Likes table stores one counter per post, and each like runs an UPDATE that increments its post row. When a post becomes popular, concurrent requests serialize on that row, making the Like API slow. section 6.11.1
Common responses trade contention against freshness, reliability, or operational complexity:
- Batch updates through a local counter and periodic background writes; this reduces database load but complicates retries, locking, and partitioning. section 6.11.1
- Buffer writes in a write-optimized database and periodically transfer them to the relational database; this adds infrastructure and count latency. section 6.11.1
// /like/{post_id} handler
function like(postID string) {
if randomInt(N) == 0 {
increment(postID, N)
}
}
A probabilistic increment reduces write frequency by applying an increment of N only when a random draw selects one request in N. section 6.11.1
