On many web sites you would see a counter how many time given object - blog post, forum thread, image, movie etc was viewed. This is sometimes handy feature but it can be rather expensive from performance point of view.
The nasty thing with counters as they are implemented the most trivial way - they convert read load to write load. When you would simply fetch given object information now you do not only fetch the data but also update the view counter.
For smaller single system web site with no caching the overhead may well be insignificant - as you run update for the same row which just was fetched it does not cause any synchronous IO and background IO can be batched rather effectively.
As the system growths however and you implement some form of caching, ie memcache you end up reducing number of reads from database dramatically but writes still have to happen at full speed. It also really hurts if you choose replication …
[Read more]