5 ms·
The Slotted Counter Pattern
- josephcsible 4y ago> It is a common database pattern to increment an INT column when an event happens, such as a download or page view. > You can go far with this pattern until bursts of these types of events happen in parallel and you experience contention on a single row. When multiple transactions are trying to update the counter, you are essentially forcing these transactions to run serially, which is bad for concurrency and can cause deadlocks. I can see how that would cause slowdowns, but not deadlocks, unless by "cause" it means "trigger one that was already present all along due to a bug in your code". Well-written code should work completely fine (other than being slow) with that pattern.