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

NoSQLの歴史にみる、Cloud Firestoreとの正しい付き合い方

Cfb5f4339bc51c3293511cd1c8a48356?s=47 Naomichi Okada
September 01, 2018

NoSQLの歴史にみる、Cloud Firestoreとの正しい付き合い方

Cfb5f4339bc51c3293511cd1c8a48356?s=128

Naomichi Okada

September 01, 2018
Tweet

Transcript

  1. NoSQL ͷྺ࢙ʹΈΔɺ Cloud Firestore ͱͷ ਖ਼͍͠෇͖߹͍ํ 2018.09.01 iOSDC Day2 Naomichi

    Okada
  2. ࣗݾ঺հ • Naomichi OkadaʢԬా௚ಓʣ / @na0m1chikun • ౦ژେֶम࢜2೥ʢԽֶ޻ֶʣ → தୀ

    • ελʔτΞοϓͰiOSத৺ʹ։ൃશൠ΍ͬͯ·͢ • recruit-lifestyle/FeedbackMan
  3. Firebase Cloud Firestore • Firebase ͔Β2017.10ʹൃදɺݱࡏ΋β൛ • Firebase Realtime Database

    ͷ࣍ੈ୅൛ͱ͍͏ݟํ͕ڧ͍ • υΩϡϝϯτࢦ޲ͷ NoSQL σʔλϕʔε • ಺෦తʹ͸ GCP Cloud Datastore
  4. Firestore ͷಛ௃ • αʔόʔϨεͰΦʔτεέʔϧ • ʮੈքͰ΋࠷େن໛ͷΞϓϦ͔Βͷ࠷΋աࠅͳϫʔΫϩʔυʹରԠͰ͖Δʯ • σʔλ͸४ϦΞϧλΠϜʹಉظ͞ΕɺΦϑϥΠϯͰ΋ಈ࡞ • εΩʔϚϨεͰɺॊೈ͔ͭ௚ײతʹσʔλΛ֨ೲՄ


  5. ࣌୅എܠ

  6. ͦͷ̍

  7. ൒ߏ଄ɺඇߏ଄σʔλͷ૿Ճ • ߏ଄Խσʔλɿߏ଄͕ݻఆͰ͋Γɺਖ਼نԽ͞Ε͍ͯΔσʔλ
 ྫʣۚ༥औҾɾձܭɾ঎඼؅ཧ • ൒ߏ଄σʔλɿܕ΍ߏ଄Λ͕࣋ͭɺݻఆͰͳ͘සൟʹߋ৽͞ΕΔσʔλ
 ྫʣγεςϜϩάɺAPIϨεϙϯεʢXML, JSONʣ • ඇߏ଄σʔλɿશ͘ߏ଄Λ͍࣋ͬͯͳ͍σʔλ


    ྫʣςΩετɺԻ੠ɺը૾ɺಈըʢϚϧνϝσΟΞʣ

  8. ൒ߏ଄ɺඇߏ଄σʔλͷ૿Ճ • ߏ଄Խσʔλɿߏ଄͕ݻఆͰ͋Γɺਖ਼نԽ͞Ε͍ͯΔσʔλ
 ྫʣۚ༥औҾɾձܭɾ঎඼؅ཧ • ൒ߏ଄σʔλɿܕ΍ߏ଄Λ͕࣋ͭɺݻఆͰͳ͘සൟʹߋ৽͞ΕΔσʔλ
 ྫʣγεςϜϩάɺAPIϨεϙϯεʢXML, JSONʣ • ඇߏ଄σʔλɿશ͘ߏ଄Λ͍࣋ͬͯͳ͍σʔλ


    ྫʣςΩετɺԻ੠ɺը૾ɺಈըʢϚϧνϝσΟΞʣ
 ͜ΕΒͷσʔλϞσϧʹదͨ͠DB͕ඞཁ
  9. υΩϡϝϯτࢦ޲DB • JSONΛอଘ͢Δ͜ͱʹಛԽͨ͠DB • Key-ValueͷValueʹ഑ྻ΍ϋογϡ౳༷ʑͳσʔλܕΛ֨ೲՄೳ • ࣄલʹεΩʔϚΛఆٛ͢Δ͜ͱͳ͘ɺ൒ߏ଄σʔλΛྲྀ͠ࠐΊΔ • JSONπϦʔ಺ͷ஋ͷݕࡧɺΠϯσοΫε͕Մೳ •

    λʔϯΞϥ΢ϯυλΠϜ͕୹͘ɺΦϖϨʔγϣϯ༻్ʹద͢Δ

  10. ͦͷ̎

  11. ۙ೥ͷσʔλॲཧʹ͓͚Δ3V • Volume: ϚϧνϝσΟΞͷਁಁʹΑΔσʔλྔͷ૿Ճ • Velocity: ΠϯλʔωοτͷΞΫηε਺૿ՃʹΑΔཁٻॲཧ଎౓ͷ޲্ • Variety: ϚϧνϝσΟΞͷਁಁʹΑΔσʔλߏ଄ͷଟ༷ੑͷ૿Ճ

  12. ۙ೥ͷσʔλॲཧʹ͓͚Δ3V • Volume: ϚϧνϝσΟΞͷਁಁʹΑΔσʔλྔͷ૿Ճ • Velocity: ΠϯλʔωοτͷΞΫηε਺૿ՃʹΑΔཁٻॲཧ଎౓ͷ޲্ • Variety: ϚϧνϝσΟΞͷਁಁʹΑΔσʔλߏ଄ͷଟ༷ੑͷ૿Ճ

    େྔɾߴ଎ͷσʔλॲཧ͕ٻΊΒΕΔΑ͏ʹ
  13. εέʔϧΞοϓͱεέʔϧΞ΢τ • εέʔϧΞοϓɿϋʔυ΢ΣΞͷεϖοΫΛ্͛Δ • εέʔϧΞ΢τɿϊʔυΛԣʹฒ΂ͯฒྻʹॲཧΛ෼ࢄ

  14. εέʔϧΞοϓͱεέʔϧΞ΢τ • εέʔϧΞοϓɿϋʔυ΢ΣΞͷεϖοΫΛ্͛Δ • εέʔϧΞ΢τɿϊʔυΛԣʹฒ΂ͯฒྻʹॲཧΛ෼ࢄ • RDBͰ͸εέʔϧΞ΢τʹΑΔੑೳ޲্͸ࠔ೉

  15. εέʔϧΞοϓͱεέʔϧΞ΢τ • εέʔϧΞοϓɿϋʔυ΢ΣΞͷεϖοΫΛ্͛Δ • εέʔϧΞ΢τɿϊʔυΛԣʹฒ΂ͯฒྻʹॲཧΛ෼ࢄ • RDBͰ͸εέʔϧΞ΢τʹΑΔੑೳ޲্͸ࠔ೉ ͦΕ͸ͳ͔ͥʁ

  16. RDB͸ACIDಛੑΛ࣋ͭ • Atomicity: ݪࢠੑ
 τϥϯβΫγϣϯͷؚ·ΕΔૢ࡞͸ɺશͯߦΘΕΔ or શ͘ߦΘΕͳ͍ ͷ͍ͣΕ͔Ͱ͋Δɻ • Consistency:

    Ұ؏ੑ
 τϥϯβΫγϣϯ͕DBͷ੔߹ੑΛຬͨ͢͜ͱΛอূ͠ɺϧʔϧΛຬͨ͞ͳ͍΋ͷ͸ࣦഊ͢Δɻ • Isolation: ಠཱੑ
 τϥϯβΫγϣϯಉ࢜͸ޓ͍ʹӨڹΛ༩͑ͳ͍ɻ • Durability: Ӭଓੑ
 ίϯϐϡʔλγεςϜ͕Ϋϥογϡͯ͠΋ɺ੒ޭͨ͠τϥϯβΫγϣϯͷ݁Ռ͸ࣦΘΕͳ͍ɻ
  17. ݫີͳACIDಛੑ͕ᐫͱͳΔ • ෼ࢄ͞ΕͨRDB΋ɺACIDಛੑΛຬͨ͢τϥϯβΫγϣϯΛ੾Δ
 ͦͷͨΊͷํ๏͕ʮ෼ࢄτϥϯβΫγϣϯʯ • ෳ਺ͷϊʔυͰίϛϡχέʔγϣϯΛऔΓɺίϛοτ४උΛߦ͏ ❌ ॲཧ͕ෳ਺ͷϊʔυʹލͬͯ͠·͍ɺ஗͘ͳΔ ❌ ಠཱੑͷͨΊɺଞͷϦΫΤετ͸ͦͷؒͣͬͱ଴ͨ͞ΕΔ

  18. ෼ࢄγεςϜͷBASEಛੑ • Basically Available: جຊతʹͲΜͳ࣌Ͱ΋ಈ࡞͢ΔՄ༻ੑ • Soft-state: ৗʹ੔߹ੑΛอͭඞཁ͸ͳ͍ɻ֎෦ͷঢ়گʹԠͯ͡มԽ • Eventually

    Consistent: ࠷ऴతʹ͸੔߹ੑ͕อͨΕΔɺ݁Ռ੔߹ੑ
 • ੔߹ੑΛ؇΍͔ʹ͢Δ͜ͱͰɺ෼ࢄγεςϜʹΑΔεέʔϧΞ΢τΛՄೳʹ͢Δɺ
 େྔσʔλ࣌୅ͷάουϓϥΫςΟε

  19. Firestore ͸࣌୅ʹదͨ͠ສೳDBʁ

  20. CAPఆཧ • ෼ࢄίϯϐϡʔςΟϯάγεςϜͷσʔλෳ੡ʹؔ͢Δఆཧ • 2000೥ʹEric BrewerࢯʹΑͬͯఏҊ͞Εɺ2002೥ʹূ໌͞Ε͍ͯΔ

  21. CAPఆཧ • Consistency: ੔߹ੑ
 શͯͷϊʔυʹ͓͍ͯɺಉ࣌ʹಉ͡σʔλ͕ݟ͑Δɻ • Availability: Մ༻ੑ
 ো֐ʹΑΓɺੜଘϊʔυ͸μ΢ϯ͠ͳ͍ɻ୯Ұো֐఺͕ଘࡏ͠ͳ͍ɻ •

    tolerance to network Partitions: ෼அ଱ੑ
 ωοτϫʔΫͷ෼அʹରͯ͠ɺܧଓͯ͠ಈ࡞Λߦ͏ɻ
 • ͜ͷ3ͭͷཁૉͷ͏ͪɺ࠷େ2ͭ·Ͱ͔͠ಉ࣌ʹຬͨ͢͜ͱ͕Ͱ͖ͳ͍
  22. None
  23. CA, CP, AP ܕͷಛ௃ • CAܕʢ੔߹ੑʴՄ༻ੑʣ
 Active-StandbyΫϥελߏ੒ΛऔΓɺωοτϫʔΫো֐࣌ʹ͸ยํΛ੾ΓࣺͯΔ
 ྫʣRDBશൠʢMySQL, PostgreSQL…ʣ •

    CPܕʢ੔߹ੑʴ෼அ଱ੑʣ
 ෼அ͞Εͨ2ͭͷΫϥελͷ͏ͪɺϊʔυ਺ͷଟ͍ํͷΈΛੜଘͤ͞ɺ੔߹ੑΛ֬อ
 ྫʣRedis, MongoDB, HBase • APܕʢՄ༻ੑʴ෼அ଱ੑʣ
 ෼அ࣌΋શͯͷϊʔυ͕ϦΫΤετΛडཧɺҰ࣌తʹ੔߹ੑ͕ࣦΘΕΔ͕ޙʹಉظ͢Δ݁Ռ੔߹ੑΛ΋ͭ
 ྫʣFirestore, Cassandra, CouchDB, Couchbase
  24. ͱɺ͍͏͜ͱ͸……

  25. Firestoreʹ΋ෆಘҙ෼໺͕͋Δ • σʔλͷॻ͖ࠐΈʹରͯ͠ڧ͍੔߹ੑʢҰ؏ੑʣ͕ඞਢͱ͞ΕΔ෼໺ • Ϣʔβʔͷ՝ۚɾܾࡁॲཧ • ઓಆதͷΦϯϥΠϯήʔϜϓϨʔϠʔͷείΞ
 • ͦ΋ͦ΋JSONܕͷ൒ߏ଄σʔλ͕ద͞ͳ͍෼໺ •

    ۚ༥औҾɺ౷ܭௐࠪσʔλͳͲ

  26. Firestoreͷಘҙ෼໺͸ʁ • ݁Ռ੔߹ੑͰ੒ཱ͠ɺେྔͷ൒ߏ଄σʔλΛѻ͏෼໺ • ঎඼৘ใɾΧλϩά؅ཧ • ෳ਺ࣄۀऀͷσʔλΛूΊͯ1αΠτʹू໿͢ΔΑ͏ͳαʔϏε • ΞϓϦέʔγϣϯ΍ϛυϧ΢ΣΞͷϩά؅ཧ •

    ৽نࣄۀʹ͓͚ΔPMFԾઆݕূͷͨΊͷߴ଎։ൃ

  27. ·ͱΊ • Firestore ͸ඇৗʹڧྗͳεέʔϦϯάੑΛ࣋ͭศརͳDB • ͨͩ͠ɺNoSQLɾυΩϡϝϯτࢦ޲DBͷσʔλϞσϧΛཧղ͍ͯ͠ͳ͍ͱɺ
 ։ൃ͕͏·͍͔͘ͳ͍Մೳੑ͕͋ΔͷͰ஫ҙ • ڧ͍੔߹ੑ͕ඞਢʹͳΔΑ͏ͳ৔໘Ͱ͸ૉ௚ʹRDB࢖͓͏ •

    ۜͷ஄ؙ͸ͳ͍ʂʂ