Hacker News new | ask | show | jobs
by joevandyk 5366 days ago
Isn't updating a counter in SQL just: update counters set amount = amount + 1 where id = something?
2 comments

In a basic application yes this is true. But if you have a large cluster and data is spread out it becomes more difficult not to mention time consuming to run that query. With redis and other nosql solutions they are designed with this in mind so they are much faster and easier.
You didn't check for overflow.
Don't check for overflow. Simply use a data type so large that it would take centuries to overflow.

If you were doing a million increments per second it would take almost 600,000 years to overflow a 64 bit int.

Check your assumptions. The field could be updated at any time to any value by another connection.

And who's to say we started at zero.