Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Aggregating data accountably and consistently

Aggregating data accountably and consistently

Overview of the Event Sourcing pattern and a story of how we used it on a project to aggregate data from bunch of various social networks. All for the sake of preventing conflicts in data and being able to pin down transient bugs by tracking changes in the data.

Nikica Jokić

October 04, 2014
Tweet

More Decks by Nikica Jokić

Other Decks in Programming

Transcript

  1. 3 –  Someone  on  Hacker  News "Every  large  enough  soBware

     system   has  an  badly  implemented  subset  of  git   contained  within  itself."
  2. 4

  3. 4

  4. 4

  5. 4

  6. 4

  7. 4

  8. 4

  9. 4

  10. Problems  of  this  system 8 Hard  to  filter  out  repeaOng

     (noisy)  data [{…},  {…},  {…},  {…},  {…},  {…},  {…},  {…}]
  11. 9 –  Mar1n  Fowler “The  fundamental  idea  of  Event  Sourcing

     is  that   of  ensuring  every  change  to  the  state  of  an   applicaOon  is  captured  in  an  event  object,  and   that  these  event  objects  are  themselves  stored   in  the  sequence  they  were  applied  for  the  same   lifeOme  as  the  applicaOon  state  itself.”
  12. 10

  13. 11

  14. CharacterisOcs  of  ApplicaOon  State also  called  EnOOes have  relaOonships  to

     other  things  in  the  system we’re  able  to  update  them 14
  15. Events  vs.  EnOOes  immutable  vs.  mutable  value  vs.  idenOty  ∆

     of  informaOon  vs.  ∫  of  informaOon 15
  16. 16 { "number": 1347, "state": "open", "title": "Found a bug",

    "body": "I'm having a problem …”, "url": “https://api.github…”, "labels": [{ /* label */ }], "user": { /* user object */ }, "assignee": { /* user object */ }, "closed_by": { /* user object */ } } Github  Issues  API
  17. 16 { "number": 1347, "state": "open", "title": "Found a bug",

    "body": "I'm having a problem …”, "url": “https://api.github…”, "labels": [{ /* label */ }], "user": { /* user object */ }, "assignee": { /* user object */ }, "closed_by": { /* user object */ } } ! { "id":"2299367813", "user":"neektza", "repo_id":3228363, "issue_id": :43320689, "action":"opened", } Github  Issues  API
  18. 16 { "number": 1347, "state": "open", "title": "Found a bug",

    "body": "I'm having a problem …”, "url": “https://api.github…”, "labels": [{ /* label */ }], "user": { /* user object */ }, "assignee": { /* user object */ }, "closed_by": { /* user object */ } } ! { "id":"2299367813", "user":"neektza", "repo_id":3228363, "issue_id": :43320689, "action":"opened", } { "id":"2299367814", "user":"neektza", "repo_id":3228363, "issue_id":43320689, "action":"updated", } Github  Issues  API
  19. 16 { "id":"2299367815", "user":"neektza", "repo_id":3228363, "issue_id":43320689, "action":"closed", } ! {

    "id":"2299367813", "user":"neektza", "repo_id":3228363, "issue_id": :43320689, "action":"opened", } { "id":"2299367814", "user":"neektza", "repo_id":3228363, "issue_id":43320689, "action":"updated", } { "number": 1347, "state": "closed", "title": "Found a bug", "body": "I'm having a problem …”, "url": “https://api.github…”, "labels": [{ /* label */ }], "user": { /* user object */ }, "assignee": { /* user object */ }, "closed_by": { /* user object */ } } Github  Issues  API
  20. 18 Events ID ENTITY_ID MD5 JSON … … … …

    Entities ID TYPE TITLE BODY … … … … The  structure  of  data
  21. The  state 23 Events ID ENTITY_ID MD5 JSON 123 987

    845b7853f39adb1… {  ..  } Entities ID TYPE TITLE BODY 987 Post Cocurency  primiOves  and  abstracOons  in  R …
  22. The  state 27 Events ID ENTITY_ID MD5 JSON 123 987

    845b7853f39adb1… {  ...  } 124 ? c9155434978967… {  …  }
  23. Final  state 29 Events ID ENTITY_ID MD5 JSON 123 987

    845b7853f39adb1… {  …  } 124 987 c9155434978967… {  …  } Entities ID TYPE TITLE BODY 987 Post Concurency  primiOves  and  abstracOons  in   …
  24. Problems?  Solved! 1st  problem  solved!  —>  tracking  changes 2nd  problem

     solved!    —>  able  to  filter  out  noise 30
  25. Problems?  Solved! 1st  problem  solved!  —>  tracking  changes 2nd  problem

     solved!    —>  able  to  filter  out  noise a  natural  soluOon 30
  26. Much  power complete  rebuild  of  state temporal  query  of  past

     states easy  to  capture  business  intent 31
  27. Much  power complete  rebuild  of  state temporal  query  of  past

     states easy  to  capture  business  intent goes  nicely  with  FP  philosophy 31
  28. There’s  no  silver  bullet more  complex  architecture   very  hard

     to  introduce  retroacOvely applicaOon  state  is  eventually  consistent 32
  29. QuesOons? 33 [email protected] @neektza Further  reading:   1.  MicrosoB  Developer

     Network  (MSDN)   2.  LosTechies  community  blog