Mixin it Up:DatastoreEdition                Chris Cahoon                Eric Oestrich
Using only anobject storeon a largeish appand then remembering you can use morethan one database in a system
The (Central) ProblemHierarchical forms & responses
Survey                    Response  Question (text)           Answer  Question Group            Answer Group     Question ...
NUMBERSLots of questionsLots of formsLots of usersLots of responses= Lots of queries
"We need anobject store!"
MONGOID!feels like ActiveRecord inside MongoDB
"This form belongs_touser!"
"Mongoid has helpers for            relations?!"
Response   SurveyUser           Not bad.
(months pass...)
User                       Survey       Campaign                          (etc.) (very etc.)Organization            Respon...
Mongoid works perfectlyfor those two models
...but everythingelse is relational!
There areproblems with object stores
... used like a       relational db(there are things wemissed from relationalDBs)
Relations
Can only queryone collection at          a time
Denormalization
No foreign keys
I accidentally the object
Can I have my cake?           and eat it too?
Just Mongoid
Querying# 2 queriessurveys = Survey.where(:campaign_id.in =>     @user.campaigns.map(&:id))survey_ids = surveys.map(&:id)#...
Interlude
Mongoid & ActiveRecord
Bridging the gap
Search with SQL, storewith Mongo# 1 queryResponse.   joins(:survey, :campaign).   where(complete => true,     "campaigns.u...
Should we gemify this?
GitHub:https://github.com/oestrich/mixin_it_up_datastore(look at the branches)
Thanks
Mixin' it Up: Datastore_edition
Mixin' it Up: Datastore_edition
Mixin' it Up: Datastore_edition
Mixin' it Up: Datastore_edition
Mixin' it Up: Datastore_edition
Mixin' it Up: Datastore_edition
Mixin' it Up: Datastore_edition
Mixin' it Up: Datastore_edition
Mixin' it Up: Datastore_edition
Mixin' it Up: Datastore_edition
Upcoming SlideShare
Loading in...5
×

Mixin' it Up: Datastore_edition

160

Published on

Combining relational and NoSQL databases in a Rails app.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
160
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mixin' it Up: Datastore_edition

  1. 1. Mixin it Up:DatastoreEdition Chris Cahoon Eric Oestrich
  2. 2. Using only anobject storeon a largeish appand then remembering you can use morethan one database in a system
  3. 3. The (Central) ProblemHierarchical forms & responses
  4. 4. Survey Response Question (text) Answer Question Group Answer Group Question (date) Answer (date) Question (phone #) Answer (phone #)
  5. 5. NUMBERSLots of questionsLots of formsLots of usersLots of responses= Lots of queries
  6. 6. "We need anobject store!"
  7. 7. MONGOID!feels like ActiveRecord inside MongoDB
  8. 8. "This form belongs_touser!"
  9. 9. "Mongoid has helpers for relations?!"
  10. 10. Response SurveyUser Not bad.
  11. 11. (months pass...)
  12. 12. User Survey Campaign (etc.) (very etc.)Organization Response Oh.
  13. 13. Mongoid works perfectlyfor those two models
  14. 14. ...but everythingelse is relational!
  15. 15. There areproblems with object stores
  16. 16. ... used like a relational db(there are things wemissed from relationalDBs)
  17. 17. Relations
  18. 18. Can only queryone collection at a time
  19. 19. Denormalization
  20. 20. No foreign keys
  21. 21. I accidentally the object
  22. 22. Can I have my cake? and eat it too?
  23. 23. Just Mongoid
  24. 24. Querying# 2 queriessurveys = Survey.where(:campaign_id.in => @user.campaigns.map(&:id))survey_ids = surveys.map(&:id)# + 1 queryResponse.where(:survey_id.in => survey_ids, :complete => true).first.answers# = 3 total queries for search, notchainable
  25. 25. Interlude
  26. 26. Mongoid & ActiveRecord
  27. 27. Bridging the gap
  28. 28. Search with SQL, storewith Mongo# 1 queryResponse. joins(:survey, :campaign). where(complete => true, "campaigns.user_id" => @user.id). first. answer_collection# = 1 total query for search, chainable
  29. 29. Should we gemify this?
  30. 30. GitHub:https://github.com/oestrich/mixin_it_up_datastore(look at the branches)
  31. 31. Thanks
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×