TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

The Slotted Counter Pattern

2 pointsby nedpalmost 3 years ago

1 comment

josephcsiblealmost 3 years ago
&gt; It is a common database pattern to increment an INT column when an event happens, such as a download or page view.<p>&gt; 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.<p>I can see how that would cause slowdowns, but not deadlocks, unless by &quot;cause&quot; it means &quot;trigger one that was already present all along due to a bug in your code&quot;. Well-written code should work completely fine (other than being slow) with that pattern.