Recently, I read the Stack Overflow Blog about how they have some of their infrastructure laid out.
I was curious to know, does Stack Overflow using caching (both at the application layer and/or database layer) and if so, how?
migrated from stackoverflow.com Nov 1 '10 at 21:01
This question came from our site for professional and enthusiast programmers.
Oh boy, have I been waiting for somebody to ask something like this.
We really aggressively cache... basically everything.
Virtually all pages accessed by (and subsequently served to) anonymous users are cached, whole cloth, via Output Caching. This isn't terribly interesting, but it is terribly fast.
Perhaps more interesting, we use Redis as a caching layer for the entire network. Kyle recently mentioned the specs of the machine in passing. Prior to the NY move our Redis instance was in a virtual machine on a (lightly loaded) web tier machine.
In our (admittedly limited) experience, Redis is so fast that the slowest part of a cache lookup is the time spent reading and writing bytes to the network. This is not surprising, really, if you think about it.
We compensate for this in two ways:
Conceptually, each site has 3 distinct caches:
We do our best to avoid cache invalidation, thus most things in the cache merely expire and are never explicitly removed. However, for those rare cases where removal is necessary we use Redis messaging to publish removal notices** (only to those sites that care, for scaling's sake).
Some quick stats:
*Still, for some common use cases the largest part of a Redis command is the key name. One of these days I'm going to find some time to experiment with compressing the entire command stream, and see what kind of performance gains can be made.
**These removals are necessary to invalidate the "L1 Cache," Redis naturally keeps itself in a coherent state in the face of removals.