3

This is a more technical question. I just found that I can browse the history of all my actions. Does Stack Exchange use event sourcing and store all my actions in the database? I wonder if CQRS is also used. What is the database used by Stack Exchange? Do you store actual state or do you store events (event store)?

user profile activity page actions tab

How are the actions stored? And how is the reputation stored?

  • 1
    I don't think comment are the best example of event-sourcing for stackexchange, maybe reputation is better: each individual reputation gain or loss is stored, and can be used to compute the actual reputation. – Kepotx Jun 27 '18 at 13:39
  • @Kepotx yes, I wonder how is this solved though. It would be interesting to see the database schema behind it :) – Konrad Jun 27 '18 at 13:42
  • 2
    The database schema is not that much different from the public version. – Glorfindel Jun 27 '18 at 13:46
  • 1
    IIRC there is a reputation-events table but the aggregate is stored denormalized in the users.reputation field – rene Jun 27 '18 at 13:54
  • 1
    For reputation I have written an answer here. – rene Jun 27 '18 at 13:56
4

That timeline is pretty much this:

Select stuff from Comments
Union
Select stuff from Posts
Union
Select stuff from PostHistory
Union
Select stuff from Votes
Union
Select stuff from ReviewTaskResults

Reputation is slightly more complex, but essentially there's a row for every reputation change and those get rolled up for display according to various rules. RepHistory is probably a lot closer to what you were thinking with an event source log.

  • Ahh, that's nice to know. Does StackExchange use DDD services or do you handle your logic in MediatR like fashion? – Konrad Jun 27 '18 at 14:36
  • Ouch, this explains why profile page takes 10-20 seconds to load for users with lots of activity. No way to create cache tables for this to allow faster load time of profile pages? – Shadow9 Jun 28 '18 at 14:42
  • I've never seen that, @ShadowWizard. Have an example? – Undo - Reinstate Monica Jun 28 '18 at 14:57
  • @Undo meta.stackexchange.com/q/311765/152859. Also note it only happens when viewing own profile, as it loads much more data, e.g votes, which are not displayed for others. (So you can't reproduce by viewing someone's else profile.) – Shadow9 Jun 28 '18 at 14:59
  • Yeah, this has nothing to do with what I posted here @Shadow (which, to be clear, is not a real query - I typed this answer on my phone). Something's going on with RepHistory; Nick is poking it with a stick. – Shog9 Jun 28 '18 at 16:43
  • @Shog9 thanks! Any results just yet? – Shadow9 Jun 28 '18 at 19:14
  • New build is in the pipeline, @Shadow. Cross fingers. Knock on wood. Throw salt at the servers. Sacrifice a chicken to the indexes. – Shog9 Jun 28 '18 at 19:23

You must log in to answer this question.

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