51

For example - Vote Gets/Puts/Posts are all super fast across the Stack Exchange sites. I can imagine by now there must be millions of rows on that table.

What strategies does the Stack Exchange team employ to guarantee speedy operations across these (and other high-volume) records? Partitioning? Indexing? Caching? Leveraging something other than SQL to store these?

(I think maybe this belongs on meta.stackexchange.com - but I can't seem to post over there. Can someone help?)

19
  • 2
    If you're interested in SO's architecture (I don't believe it covers your question in particular, though) but you may be interested in: nickcraver.com/blog
    – Rob Mod
    Commented May 5, 2016 at 2:15
  • @Rob Thanks man - I'm a regular over there and haven't seen this covered. Such an informative blog though.
    – RobVious
    Commented May 5, 2016 at 2:17
  • 7
    102,632,301 to be exact ... I don't think that table is of any concern. If a table needs special attention it is posthistory, not as many rows but due to it's data-size per row.
    – rene
    Commented May 5, 2016 at 6:47
  • @rene so cool. Thanks for that.
    – RobVious
    Commented May 5, 2016 at 6:54
  • 9
    If you want Nick to cover it, go add a card for it.
    – user1228
    Commented May 5, 2016 at 13:35
  • 3
    @Will done
    – RobVious
    Commented May 5, 2016 at 15:47
  • 1
    RobVious, you simply keep a running total of the + and - votes, for each question. it's an everyday approach. (Unless I misunderstand your question.) (I have nothing to do with SO, but this is a commonplace on the sundry social media systems encircling out planet these days.)
    – Fattie
    Commented May 5, 2016 at 18:05
  • 1
    @JoeBlow - ah, so some practical denormalization. That's cool, but I guess my real question is 'What performance strategies does SO employ to keep queries across huge SQL datasets speedy?' - I'll update the title (if I can...)
    – RobVious
    Commented May 5, 2016 at 18:14
  • 1
    hi RobVious. "ah, so some practical denormalization" Right. You know, I think like in the 1950s or something we'd talk about "orthogonal" data and whatever. That's totally out the window. Nowadays you gorge on logically pointless but convenient sums, duplicates, legers and so on. the entire concept of trying to minimize data (or whatever the hell it was people were trying to do back then) is completely out the window. I'm not even sure it's meaningful to talk about denormalization now - it would be rather like saying a display is "flat!" or music "digital" you know - heh.
    – Fattie
    Commented May 5, 2016 at 18:24
  • @JoeBlow and boy do I love that. I prefer sanity and speed to religion and purity :)
    – RobVious
    Commented May 5, 2016 at 18:25
  • 1
    lol right on! :)
    – Fattie
    Commented May 5, 2016 at 19:00
  • 2
    for the sake of completeness, some of their queries are very slow and some even time out
    – gnat
    Commented May 5, 2016 at 19:37
  • 1
    SO uses big iron on their SQL boxes, they also employ very serious caching usage. Additionally they built their own custom servers for some portions like "tags". The short answer to your question is, they have paid alot of time and money for it. Commented May 5, 2016 at 20:38
  • 1
    @JoeBlow: That's utter nonsense. You refer to the caching that SO does on its votes for added speed, yes fine. But the actual votes are still normalised away in a database table. That's still a totally normal (lol) and good thing to do when using a RDBMS, contrary to your assertion that it hasn't been done since the 1950s (what?! that would be particularly impressive since Codd didn't define 3NF until 1971). Commented May 7, 2016 at 19:40
  • 1
    @RobVious: Yep, exactly. You'd have to ask the devs to find out how often that occurs here, but that's precisely how it works. :) Also, from what I can tell, the caching is needed mainly because of the volume of visitors; a database table of a million rows is not inherently slow to use (for one user) unless it's been terribly designed, because it's not really that much data in the grand scheme of things. Worth remembering. Commented May 7, 2016 at 23:57

1 Answer 1

37

Stack Exchange uses a massive caching implementation to make all of this streamlined.

The hardware used is very impressive, expensive, and top of the line. This has always been a very large sticking point for Stack Exchange.

The core software approach used is to have a sliding time window which stores the composed SQL used to query the database. Re-using these queries, or execution plans, saves a large amount of time.

Often, when accessing a page, as a user you are not really asking for a large amount of data from the database. The largest amount of time is composing the query, paired with how long it takes for the data to make it over the wire.

There are some places where large data sets need to be accessed on the site, for example the review history, and those can take several seconds to complete because of the amount of data being examined.

In general, the content caching mechanisms in addition to the spectacular hardware are where the performance comes from.

As for all of the tools and gadgets used, there is a post which is maintained that details that on MSE Which tools and technologies are used to build the Stack Exchange Network? , and to see an analysis of how the caching works for views, I have a small writeup (contains some code) on MSE as well https://meta.stackexchange.com/a/224165/178816

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .