Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

NoSQL: onde, como e por quê? Cassandra e MongoDB

10,071 views

Published on

Visão geral sobre bancos de dados NoSQL e detalhes técnicos dos modelos de dados e arquiteturas das implementações Apache Cassandra e MongoDB.

Published in: Technology
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/qURD } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/qURD } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download doc Ebook here { https://soo.gd/qURD } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/qURD } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/qURD } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/qURD } ......................................................................................................................... Download doc Ebook here { https://soo.gd/qURD } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

NoSQL: onde, como e por quê? Cassandra e MongoDB

  1. 1. NoSQL: onde, como e por quê? Rodrigo Hjort [email_address]
  2. 2. Quem aqui usa banco de dados?
  3. 3. Por que precisamos de SQL?
  4. 4. Onde usamos SQL (i.e. ACID)?
  5. 5. <ul>MAS... </ul>
  6. 6. Universo digital em expansão Fonte: IDC White Paper, &quot;The Diverse and Exploding Digital Universe&quot;, 2008.
  7. 7. Aplicações web modernas
  8. 8. <ul>Escalabilidade vertical é complicada e/ou cara! </ul>
  9. 9. Os modelos transacionais <ul><li>ACID pessimista, forçando consistência ao final de cada operação
  10. 10. BASE otimista, aceitando que a consistência esteja em um “estado de fluxo” </li></ul>http://queue.acm.org/detail.cfm?id=1394128 Possibilita a escalabilidade horizontal...
  11. 11. NoSQL = Not Only SQL http://nosql-database.org/ distribuídos não relacionais horizontalmente escaláveis esquemas flexíveis replicáveis APIs simples
  12. 12. Zoologia dos bancos NoSQL Wide Column Store / Column Families Key-Value Store Document Store NoSQL Database
  13. 13. <ul>MAS... </ul>
  14. 14. <ul>Você precisa escolher 2! </ul>Teorema de Brewer: CAP <ul><li>Consistência : visão única para os clientes
  15. 15. Disponibilidade : toda operação tem uma resposta
  16. 16. Partição : sistema continua operante mesmo enfrentando partições na rede </li></ul>Consistência Consistency Disponibilidade Availability Partição Partition Tolerance
  17. 17. I. Consistência e Disponibilidade <ul><li>Limitações na escalabilidade (leitura e escrita) </li></ul>C A
  18. 18. II. Consistência e Partição <ul><li>Completamente inacessível se qualquer um dos nós estiver fora! </li></ul>C P
  19. 19. III. Disponibilidade e Partição <ul><li>Nem sempre lê a informação mais recente: futuramente consistente </li></ul>A P
  20. 20. “ A high performance, scalable, distributed storage and processing system for structured and unstructured data.”
  21. 21. Cassandra: um breve histórico Bigtable Dynamo
  22. 22. Um novo modelo de dados Row schema-less schema-optional
  23. 23. Exemplo: modelagem do Twitter Users Following Followers @paul segue @brigitte desde 22/08/2010 john name: John Doe pass: swordfish joined: 20091115 paul name: Paul Lane pass: thepass joined: 20091129 john paul: 20091204 brigitte: 20100815 paul john: 20091205 debora: 20100729 brigitte: 20100822 john tom: 20091128 paul: 20091205 brigitte john: 20100815 paul: 20100822
  24. 24. Exemplo: modelagem do Twitter Statuses (Tweets) Timeline Userline Tweets do @john Tweets dos usuários que o @paul segue data/hora tweet 12345 user: john body: Nuvem privada do @serpro! retweets: 123 12346 user: brigitte john 20100116083155: 12346 paul 20100116083002: 12345 20100116083155: 12346 john 20100116083002: 12345 20100118235914: 23457 brigitte 20100116083155: 12346 tweet body: Acabei de #acordar. tags acordar: 1
  25. 25. CQL (Query Language) CREATE COLUMNFAMILY users ( KEY varchar PRIMARY KEY, name varchar, pass varchar, joined bigint); INSERT INTO users (KEY, name, pass) VALUES ('jsmith', 'John Smith', 'changeme') USING CONSISTENCY QUORUM; SELECT * FROM users WHERE KEY = 'jsmith'; u'jsmith' | u'pass',u'changeme' SELECT name..pass FROM users WHERE KEY >= 'h' LIMIT 10; CREATE INDEX users_joined_idx ON users (joined); DELETE joined FROM users where KEY = 'jsmith';
  26. 26. “ It took two weeks to perform ALTER TABLE on the statuses [tweets] table.” – Twitter
  27. 27. Particionamento e replicação Fixed Circular Space (Ring) Virtual Nodes Consistent Hashing (MD5) <ul>N=3 </ul><ul>h(key2) </ul><ul>0 </ul><ul>1 </ul><ul>1/2 </ul><ul>F </ul><ul>E </ul><ul>D </ul><ul>C </ul><ul>B </ul><ul>A </ul><ul>h(key1) </ul>
  28. 28. Ajuste de parâmetros (N, R, W) <ul><li>Consistência versus Escalabilidade
  29. 29. Ajuste por requisição (R, W) </li></ul><ul><ul><li>Zero
  30. 30. One
  31. 31. Quorum: N / 2 + 1
  32. 32. All </li></ul></ul><ul><li>N: réplicas
  33. 33. R + W > N
  34. 34. Read repair </li></ul>ack cliente réplica réplica réplica coordenador
  35. 35. Comunicação entre os nós Gossip-Based Protocol
  36. 36. Relacional versus NoSQL Dados do benchmark <ul><li>Base com 50 GB de dados </li></ul>MySQL <ul><li>leitura: ~350 ms
  37. 37. escrita: ~300 ms </li></ul>Cassandra <ul><li>leitura: ~15 ms
  38. 38. escrita: ~0,12 ms </li></ul>Leitura 23x mais rápida! Escrita 2500x mais rápida!
  39. 39. “ MongoDB (from &quot;humongous&quot;) is a scalable, high-performance, open source, powerful, document-oriented database written in C++.”
  40. 40. O modelo de dados Relacional (Tabular) Orientado a Documentos
  41. 41. Modelo Relacional
  42. 42. Modelo Orientado a Documentos
  43. 43. { _id : ObjectId(&quot;5ebf5e0fec5fab7db2b9b40e&quot;), title : &quot;Introdução ao MongoDB&quot;, slug : &quot;introducao-ao-mongodb&quot;, body : &quot;Este é o texto do post...&quot;, published : true, created : &quot;Jun 28 2011 13:48:22 AMT&quot;, updated : &quot;Jun 28 2011 17:01:15 AMT&quot;, comments : [ { author : &quot;john&quot;, email : &quot;john@doe.com&quot;, body : &quot;Caramba!&quot;, created : &quot;Jun 28 2011 15:01:30 BRST&quot; } ] , tags : [ &quot;databases&quot;, &quot;MongoDB&quot;, &quot;nosql&quot; ] } Um documento JSON Array Object ID Embedded Document
  44. 44. Linguagem de Consulta SELECT * FROM usuarios > db.usuarios.find() SELECT nome FROM usuarios > db.usuarios.find({}, {“nome”: 1}) SELECT * FROM usuarios WHERE idade = 29 > db.usuarios.find({“idade”: 29}) SELECT * FROM usuarios WHERE idade = 29 AND ativo = true > db.usuarios.find({“idade”: 29, “ativo”: true}) SELECT * FROM usuarios WHERE idade >= 18 AND idade <= 30 > db.usuarios.find({“idade”: {“$gte”: 18, “$lte”: 30}}) SELECT * FROM usuarios WHERE nome LIKE “%admin%” > db.usuarios.find({“nome”: /admin/i})
  45. 45. Linguagem de Consulta SELECT * FROM usuarios ORDER BY nome > db.usuarios.find().sort({“nome”: 1}) SELECT * FROM usuarios ORDER BY idade DESC, nome > db.usuarios.find().sort({“idade”: -1, “nome”: 1}) SELECT * FROM usuarios LIMIT 3 > db.usuarios.find().limit(3) SELECT * FROM usuarios OFFSET 5 > db.usuarios.find().skip(5) SELECT * FROM usuarios LIMIT 3 OFFSET 5 > db.usuarios.find().limit(3).skip(5) SELECT * FROM usuarios ORDER BY nome LIMIT 3 > db.usuarios.find().sort({“nome”: 1}).limit(3)
  46. 46. Map Reduce índices capped collections Server-Side Scripting GridFS ad hoc queries
  47. 47. Sharding
  48. 48. Auto-Sharding + Replicação
  49. 49. A grande ruptura
  50. 50. A segunda ruptura
  51. 51. “ NoSQL adoption is inevitable because, just as in every other walk of life, there are different tools for different jobs” – Stephen O'Graddy (RedMonk) Rodrigo Hjort [email_address] http://www.hjort.co

×