r/programming • • Feb 17 '16

Stack Overflow: The Architecture - 2016 Edition

http://nickcraver.com/blog/2016/02/17/stack-overflow-the-architecture-2016-edition/
1.7k Upvotes

461 comments sorted by

View all comments

1

u/titoonster Feb 18 '16

Hey Nick, amazing as always.
Can you elaborate any more on this trick?

We do some simple tricks here such as ROWVERSION in SQL Server (the data source) compared against a “last position” document in Elastic. Since it behaves like a sequence, we can simply grab and index any items that have changed since the last pass.

So is the trick that you are taking the rowversion is actually treating it a sequence? I thought it was a binary hash. Are you saying it's a binary sequence and you store that in Elastic?

2

u/nickcraver Feb 18 '16

ROWVERISON is a sequence yeah, you can cast it as a BIGINT and in Elasticsearch we keep a single document with a "position" type that simply stores the highest one we saw on the last pass and a timestamp for kicks. That way Elasticsearch knows what position the index it contains is at; beign a self-contained info source on this is big. On the next pass we just select rows with a ROWVERSION > last position and index those - easy delta that SQL server managed by itself.

In other cases where related updated that affect the index aren't on that row (so ROWVERSION doesn't increment), or it has something like ViewCount we don't index...so it increment too often: we just have a LastChangeDate field we compare instead. And it's up to our code to set that when something that affects the index happens. The upcoming Developer Story feature has this setup with the story and sub-items in the story.