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

SpringOne 2gx 2012 : MongoDB and Spring Data

cj_harris5
October 16, 2012

SpringOne 2gx 2012 : MongoDB and Spring Data

Spring and and MonogDB

cj_harris5

October 16, 2012
Tweet

More Decks by cj_harris5

Other Decks in Technology

Transcript

  1. MongoDB and Spring Data Chris Harris Twitter : cj_harris5 Email

    : [email protected] © 2012 SpringOne 2GX. All rights reserved. Do not distribute without permission. Tuesday, 16 October 12
  2. 22 Solution Architect at 10gen (the company behind MongoDB) -

    Previous Roles: • EMEA Architect at SpringSource • EMEA Principal JBoss Consultant at RedHat About Me Tuesday, 16 October 12
  3. Terminology RDBMS MongoDB Table Collection Row(s) JSON Document Index Index

    Join Embedding & Linking Partition Shard Partition Key Shard Key Tuesday, 16 October 12
  4. As simple as possible, but no simpler Depth of functionality

    Scalability & Performance Memcached Key / Value RDBMS MongoDB Tuesday, 16 October 12
  5. Welcome to Dev News • User Story 1: – As

    a user I should be able to create “News Articles” Tuesday, 16 October 12
  6. What is a News Article? { title: “What is new

    in 2.2 MongoDB”, date : new Date(), author : “Fred” text : “.......” } Tuesday, 16 October 12
  7. Welcome to MongoDB News Dev • User Story 1: –

    As a user I should be able to create “News Articles” • User Story 2: – As a user I should be able to find a “News Articles” by Name Tuesday, 16 October 12
  8. Welcome to MongoDB News Dev • User Story 1: –

    As a user I should be able to create “News Articles” • User Story 2: – As a user I should be able to find a “News Articles” by Name • User Story 3: – As a user I should be able to comment on “News Articles” Tuesday, 16 October 12
  9. What is a Comment? { title: “What is new in

    2.2 MongoDB”, date : new Date(), author : “Fred” text : “.......” tags : [“mongodb”, “nosql”] comments : [ {author : “chris”, text: “this is great” , date : new Date()}, {author : “tom”, text: “rock on”, date : new Date()} ] } Tuesday, 16 October 12
  10. Welcome to MongoDB News Dev • User Story 1: –

    As a user I should be able to create “News Articles” • User Story 2: – As a user I should be able to find a “News Articles” by Name • User Story 3: – As a user I should be able to comment on “News Articles” • User Story 4: –As a user I want to know how many comments are on a “Articles” Tuesday, 16 October 12
  11. What is a Comment? { title: “What is new in

    2.2 MongoDB”, .... comments : [ {author : “chris”, text: “this is great” , date : new Date()}, {author : “tom”, text: “rock on”, date : new Date()} ] , comments: count : 2 } Tuesday, 16 October 12
  12. Wait for Journal Sync - Same as RDBMS Driver MongoDB

    apply in memory write j:true Write to journal Tuesday, 16 October 12
  13. Replica Set • Data Protection • Multiple copies of the

    data • Spread across Data Centers, AZs • High Availability • Automated Failover • Automated Recovery Tuesday, 16 October 12
  14. Durability Summary Memory Journal Secondary Other Data Center RDBMS Default

    "Fire & Forget" w=1 w=1 j=true w="majority" w=n w="myTag" Less More Tuesday, 16 October 12
  15. Understanding Eventual Consistency Primary Secondary Thread #1 Insert Update Read

    Read reads v2 reads v1 v2 v2 v1 v1 Tuesday, 16 October 12
  16. Understanding Eventual Consistency Primary Secondary Thread #1 Insert Update Read

    Read Thread #2 v2 v2 v1 v1 v1 does not exist on Secondary Tuesday, 16 October 12
  17. Understanding Eventual Consistency Primary Secondary Thread #1 Insert Update Read

    Read Thread #2 v2 v2 v1 v1 v1 does not exist on Secondary Reads v1 but Primary at v2 Read v2 Tuesday, 16 October 12
  18. MongoDB Sharding • Automatic partitioning and management • Range based

    • Convert to sharded system with no downtime • Fully consistent Tuesday, 16 October 12
  19. How mongoDB Sharding works • Range keys from -∞ to

    +∞ • Ranges are stored as "chunks" -∞ +∞ > db.runCommand({addshard: "shard1"}); > db.runCommand({shardCollection: "mydb.users", key: {age: 1}}) Tuesday, 16 October 12
  20. How mongoDB Sharding works • Data in inserted • Ranges

    are split into more "chunks" -∞ +∞ -∞ 40 41 +∞ > db.users.save({age: 40}) Tuesday, 16 October 12
  21. How mongoDB Sharding works -∞ +∞ -∞ 40 41 +∞

    41 50 51 +∞ 61 +∞ 51 60 > db.users.save({age: 40}) > db.users.save({age: 50}) > db.users.save({age: 60}) Tuesday, 16 October 12
  22. -∞ 40 41 50 61 +∞ 51 60 > db.runCommand({addshard:

    "shard2"}); > db.runCommand({addshard: "shard3"}); How mongoDB Sharding works Tuesday, 16 October 12
  23. -∞ 40 41 50 61 +∞ 51 60 shard1 >

    db.runCommand({addshard: "shard2"}); > db.runCommand({addshard: "shard3"}); How mongoDB Sharding works Tuesday, 16 October 12
  24. -∞ 40 41 50 61 +∞ 51 60 shard1 shard2

    shard3 > db.runCommand({addshard: "shard2"}); > db.runCommand({addshard: "shard3"}); How mongoDB Sharding works Tuesday, 16 October 12
  25. Architecture C1 C2 C3 Config Servers mongos mongos app app

    mongod Shard 1 mongod mongod mongod Shard 2 mongod mongod Shard 4 mongod Shard 3 mongod mongod Replica Set mongod mongod mongod Tuesday, 16 October 12
  26. Balancing config config config Shard 1 Shard 2 Shard 4

    Shard 3 mongos balancer 5 9 1 6 10 2 7 11 3 8 12 4 13 14 15 16 17 18 19 20 21 22 23 24 Imbalance Data inserted all in a range mongos Tuesday, 16 October 12
  27. Balancing config config config Shard 1 Shard 2 Shard 4

    Shard 3 mongos balancer 5 9 1 6 10 2 7 11 3 8 12 4 13 14 15 16 17 18 19 20 21 22 23 24 Move chunk 1 to Shard 2 mongos Tuesday, 16 October 12
  28. Balancing config config config Shard 1 Shard 2 Shard 4

    Shard 3 balancer 5 9 6 10 2 7 11 3 8 12 4 13 14 15 16 17 18 19 20 21 22 23 24 1 mongos Tuesday, 16 October 12
  29. Balancing config config config Shard 1 Shard 2 Shard 4

    Shard 3 balancer 5 9 6 10 2 7 11 3 8 12 4 13 14 15 16 17 18 19 20 21 22 23 24 1 mongos Tuesday, 16 October 12
  30. Balancing config config config Shard 1 Shard 2 Shard 4

    Shard 3 mongos balancer 5 9 1 6 10 2 7 11 3 8 12 4 13 14 15 16 17 18 19 20 21 22 23 24 mongos Tuesday, 16 October 12
  31. • MongoDB 2.2 –Improved concurrency –Tag-aware sharding –Aggregation framework –TTL

    collections • Free online MongoDB training –Develop –Deploy –Classes start Oct. 2012 Questions Tuesday, 16 October 12