Skip to content

Instantly share code, notes, and snippets.

View tommarshall's full-sized avatar

Tom Marshall tommarshall

View GitHub Profile
@tsabat
tsabat / 1_justification.md
Last active September 16, 2017 11:06
View Counts in MySql

We store views in a single MySQL row, indexed by the redis key. Without redis in front of the DB this would cause lock contention, but redis keeps us reading/writing to the DB on the first, 10th, 25, and mod 100th read.

Without redis backing, using a single row to store counts would cause lock contention.

Using a row per view would result in slow reads on count(*) and in a write-heavy situation will cause the re-index to slow/stop replication because indexes are single-threaded.