マイクロサービスとクライアントとコンテキスト境界 / 20181030 #microserv

704056da9a4c4e075ad14479beaebab7?s=47 takasek
October 30, 2018

マイクロサービスとクライアントとコンテキスト境界 / 20181030 #microserv

Microservices Meetup vol.9 (FiNC App & Frontend) - connpass
https://microservices-meetup.connpass.com/event/105174/
の発表資料です。

「クライアント・サーバ間のコンテキスト境界をどこに置くか」
という話を、ドメイン駆動設計の概念などを引きながら検討しました。

704056da9a4c4e075ad14479beaebab7?s=128

takasek

October 30, 2018
Tweet

Transcript

  1. ϚΠΫϩαʔϏεͱ
 ΫϥΠΞϯτͱ
 ίϯςΩετڥք For Microservices Meetup vol.9 2018/10/30 FiNC Technologies

    Inc. / iOS Development Team ؔ ོٛ(takasek)
  2. !2 • ོؔٛ • !UBLBTFL • 'J/$5FDIOPMPHJFT • $MJFOU&OHJOFFS J045FBN

    ࣗݾ঺հ
  3. !3 • ʮJ04ΞϓϦઃܭύλʔϯೖ໳ʯ ڞஶ  • 1&",4ΑΓ݄ϦϦʔε༧ఆʂ IUUQTQFBLTDDJ04@BSDIJUFDUVSF .7$ .71

    .77. 'MVY 3FEVY $MFBO"SDIJUFDUVSF  ϞόΠϧಛ༗ͷىಈܦ࿏ɾը໘ભҠͷ੔ཧ·Ͱ໢ཏʂ ؔ͸ɺʮઃܭͱ͸Կ͔ʯͱ͍͏େ͖ͳओޠͰষ΄Ͳʂ ೥ .7$ ʙ͔Β࿈໖ͱଓ͘ ΞʔΩςΫνϟύλʔϯͷྺ࢙ͷ੔ཧʂ ϚαΧϦඞࢸͷϏοάΠγϡʔʹՌ׶ʹ௅Έ·ͨ͠ʂ એ఻
  4. !4 ຊ೔ͷ͓୊ ʮΫϥΠΞϯτɾαʔόؒͷ ίϯςΩετڥքΛͲ͜ʹஔ͔͘ʯ

  5. !5 ίϯςΩετڥքʁ • ڥք಺Ͱ͸ɺϞσϧΛ࿦ཧతʹ౷Ұ͞Εͨঢ়ଶʹอͭ͜ͱ • ͨͩ͠ɺڥքͷ֎ʹద༻Ͱ͖Δ͔Ͳ͏͔͸ؾʹ͢Δඞཁ͕ͳ͍ ʮ͋ΔϞσϧΛͲͷίϯςΩετͰ ɹద༻͢΂͖Ͱͳ͍ͷ͔ʯΛࣔ͢ - ΤϦοΫɾΤϰΝϯεͷυϝΠϯۦಈઃܭ

    ΑΓ
  6. !6 ίϯςΩετڥքʁ ˞ڥք͚ͮΒΕͨίϯςΩετΛఆٛͨ͠ΒɺͦΕΛ҆ఆͤ͞ͳ͚Ε͹ͳΒͳ͍ • ಉ͡νʔϜͰ΋ɺίϛϡχέʔγϣϯ్͕੾Εͯ͠·͏ͱղऍ͕িಥ͠͏Δ • ಉ͡νʔϜͰ΋ɺݹ͍ઃܭ৽͍͠ઃܭͰίϯςΩετڥքʹͳΔ ʮڥք͸νʔϜฤ੒ͷྠֲʹै͏ʯ - ΤϦοΫɾΤϰΝϯεͷυϝΠϯۦಈઃܭ

    ΑΓ
  7. !7 BFF BFF (Backends For Frontends) micro- services Repository UseCase

    Domain ViewModel View Server side Client side
  8. !8 BFFʁ ΫϥΠΞϯτϩδοΫͷͨΊͷαʔό • ௨৴ͷू໿ • ू໿ϩδοΫͷڞ༗ Backends For Frontends

  9. !9 Repository BFF (Backends For Frontends) micro- services Repository UseCase

    Domain ViewModel View Server side Client side
  10. !10 Repositoryʁ σʔλΛͲ͔͜Βऔಘ͢ΔͲ͜ʹӬଓԽ͢Δ͔Λߟ͑ͳ͍ • ϝϞϦ • ετϨʔδ • ωοτϫʔΫ •

    FUDʜ σʔλऔಘɾӬଓԽͷৄࡉΛӅṭ͢Δઃܭύλʔϯ
  11. !11 Repositoryʁ ෳࡶͳϩδοΫΛυϝΠϯ͔Β੾Γ཭ͨ͢ΊʹϦϙδτϦ૚Λઃ͚Δ ʮΫϥΠΞϯτ͕ඞཁͱ͢Δͷ͸ɺ ɹ͢Ͱʹଘࡏ͢ΔυϝΠϯΦϒδΣΫτ΁ͷࢀরΛखʹೖΕΔɺ ɹ࣮༻తͳखஈͰ͋Δʯ - ΤϦοΫɾΤϰΝϯεͷυϝΠϯۦಈઃܭ ΑΓ

  12. ʮ࣮ࡍʹ௚઀తͳΞΫηεΛඞཁͱ͢Δ ू໿ϧʔτʹରͯ͠ͷΈɺϦϙδτϦΛఏڙ͢Δ͜ͱʯ - ΤϦοΫɾΤϰΝϯεͷυϝΠϯۦಈઃܭ ΑΓ

  13. !13 ू໿ʁ • ෆม৚݅ʢৗʹ੔߹ੑΛอ͍ͬͯΔඞཁͷ͋ΔϏδωεϧʔϧʣΛ
 อূ͢Δ୯Ґ • ू໿಺Ͱ͸੔߹ੑΛҡ࣋͢Δ

  14. !14 UseCase BFF (Backends For Frontends) micro- services Repository UseCase

    Domain ViewModel View Server side Client side
  15. !15 UseCaseʁ ʮ%PNBJOʢ஌ࣝͷදݱʣΛͲͷΑ͏ʹ࢖͏͔ʯΛࣔ͢ 4૚ϨΠϠԽΞʔΩςΫνϟͰݴ͏ͱ͜ΖͷApplication૚

  16. !16 ViewModel, View BFF (Backends For Frontends) micro- services Repository

    UseCase Domain ViewModel View Server side Client side
  17. !17 ViewModelʁ .77. .PEFM7JFX7JFX.PEFM ύλʔϯͷίϯϙʔωϯτ ͨͩɺΞʔΩςΫνϟͷ࢔ࡉ͸ࠓճओ୊Ͱ͸ͳ͍ ʮ.PEFM7JFXؒͷม׵૚ʯͱ͚ͩଊ͍͑ͯͩ͘͞ υϝΠϯϞσϧͷσʔλΛɺView༻ͷσʔλʹม׵͢Δ૚

  18. !18 Viewʁ આ໌ෆཁ ը໘දࣔΛ࢘Δ૚

  19. !19 ϚΠΫϩαʔϏεͱίϯςΩετϚοϓ BFF (Backends For Frontends) micro- services Repository UseCase

    Domain ViewModel View Server side Client side
  20. !20 ຊ೔ͷ͓୊ (reprise) ʮΫϥΠΞϯτɾαʔόؒͷ ίϯςΩετڥքΛͲ͜ʹஔ͔͘ʯ

  21. !21 ίϯςΩετڥքΛͲ͜ʹஔ͔͘ɿBFF BFF (Backends For Frontends) micro- services Repository UseCase

    Domain ViewModel View Server side Client side
  22. !22 BFFΛม׵૚ͱͯ͠ݟͳ͢ • ϝϦοτ • ੔߹ੑʹ͍ͭͯͷ৺഑ࣄΛυϝΠϯ͔Βഉআ • ϓϥοτϑΥʔϜ J04"OESPJE౳ ͷॏෳ࣮૷Λഉআ

    • σϝϦοτ • #''ʹཔΓ͗͢Δʹ෼ࢄίϯϐϡʔςΟϯάͷݪଇ΁ͷ௅ઓ
  23. !23 ෼ࢄίϯϐϡʔςΟϯάͷݪଇ • ωοτϫʔΫ͸৴པͰ͖ͳ͍ • ʢ࣌ʹ͸͔ͳΓͷʣ஗Ԇ͕ৗʹൃੜ͢Δ • ଳҬ෯ʹ͸ݶΓ͕͋Δ • ωοτϫʔΫ͸ηΩϡΞͰ͸ͳ͍

    • ؅ཧऀ͸ෳ਺Ͱ͋Δ • సૹίετ͸θϩͰ͸ͳ͍ • ωοτϫʔΫ͸Ұ༷Ͱ͸ͳ͍ - ࣮ફυϝΠϯۦಈઃܭ ΑΓ
  24. !24 ίϯςΩετڥքΛͲ͜ʹஔ͔͘ɿRepository micro- services Repository UseCase Domain ViewModel View Server

    side Client side
  25. !25 RepositoryΛม׵૚ͱͯ͠ݟͳ͢ • ϝϦοτ • ੔߹ੑʹ͍ͭͯͷ৺഑ࣄΛυϝΠϯ͔ΒഉআͰ͖Δ • σϝϦοτ • ͜Ε͸΋͸΍ϏδωεϩδοΫͳͷͰ͸ʜʁ

    • ϓϥοτϑΥʔϜ J04"OESPJE౳ ͷॏෳ࣮૷
  26. !26 ίϯςΩετڥքΛͲ͜ʹஔ͔͘ɿUseCase micro- services Repository Domain ViewModel View Server side

    Client side UseCase
  27. !27 UseCaseΛม׵૚ͱͯ͠ݟͳ͢ • ϝϦοτ • ʮαʔόͷίϯςΩετΛΫϥΠΞϯτͰͲͷΑ͏ʹѻ͏͔ʯ
 ʹϏδωεϩδοΫͰ͋Δɺͱ͍͏ೝࣝ • ΫϥΠΞϯτ։ൃͰ͸ɺࣗવʹ͜͜ʹམͪண͘͜ͱ͕ଟͦ͏ •

    σϝϦοτ • ϓϥοτϑΥʔϜ J04"OESPJE౳ ͷॏෳ࣮૷
  28. !28 ίϯςΩετڥքΛͲ͜ʹஔ͔͘ɿViewModel micro- services Repository View Server side Client side

    UseCase ViewModel Domain
  29. !29 ίϯςΩετڥքΛͲ͜ʹஔ͔͘ɿViewModel micro- services Server side Client side ViewModel View

  30. !30 ViewModelͷ੹຿ • ૢ࡞ͷ఻ୡ • ϓϨθϯςʔγϣϯঢ়ଶͷอ࣋ • 7JFX༻ͷσʔλ΁ͷม׵ • ը໘ؒͷ੔߹ੑ୲อ

    • αʔϏεؒͷ੔߹ੑ୲อ
  31. !31 ViewModelΛม׵૚ͱͯ͠ݟͳ͢ • ΞϯνύλʔϯͰ͸ʁ

  32. !32 ίϯςΩετڥքΛͲ͜ʹஔ͔͘ɿView micro- services Server side Client side View Micro

    Frontends
  33. !33 ViewΛม׵૚ͱͯ͠ݟͳ͢ • ϝϦοτ • 7JFXϚΠΫϩαʔϏεͷ୯Ґͱݟͳ͢ • σϝϦοτ • ΞϓϦͷ৔߹ʹ͸ɺ


    7JFX͸ϚΠΫϩαʔϏεʢಠཱͯ͠ϏϧυՄೳͳ୯ҐʣͰ͸ͳ͍ • ΍͸Γը໘ίϯϙʔωϯτؒͷ੔߹ੑΛؾʹ͠ͳ͚Ε͹ͳΒͳ͍ • ͦΕ͸7JFXͷ੹຿ͩΖ͏͔ʁ
  34. !34 ΫϥΠΞϯτ͕୲อ͢΂͖੔߹ੑ • .PEFMͱ7JFXͷؒͷ੔߹ੑ • 6*ૢ࡞Λ.PEFMʹ఻ୡ • .PEFMͷঢ়ଶมߋΛ7JFXʹ൓ө • ڞ௨͢Δ.PEFMʹؔ৺ͷ͋Δ͢΂ͯͷ7JFXʹมߋ͕ಉظ͞ΕΔ

    • .PEFMͱ.PEFMͷ੔߹ੑ • αʔϏε"͔ΒͷϨεϙϯεͱ
 αʔϏε#͔ΒͷϨεϙϯεΛͻͱͭͷ.PEFMʹ݁߹͢Δ • αʔϏε"Λߋ৽ͨ͠ΒɺαʔϏε#ʹ΋มԽ͕ੜ͍ͯ͡Δ͔΋͠Εͳ͍
  35. !35 Q.ʮModelͱModelͷ੔߹ੑʯ͸ΫϥΠΞϯτ͕୲อ͢΂͖΋ͷʁ ʮαʔϏε"͕มΘͬͨΒαʔϏε#ʹ΋มߋ͕͋Δʯ͸αʔόͰ୲อ͢΂͖Ͱ͸ʁ " ʢΫϥΠΞϯτ͕"1*Λೳಈతʹୟ͍ͯߋ৽Λऔಘ͢Δੈք؍Ͱ͸ʣͦΕ͸ݪཧతʹແཧ • ʮαʔϏε"ͷߋ৽͕ɺαʔϏε#ʹ൓ө͞ΕΔʯͱͯ͠ʜ • ΫϥΠΞϯτ͸ɺαʔϏε"ͷߋ৽"1*Λୟ͍ͨ͋ͱɺ
 ໌ࣔతʹαʔϏε#ͷऔಘ"1*Λୟ͘ඞཁ͕͋Δ

    • αʔϏε͕ؒ݁Ռ੔߹ੑΛલఏʹ͍ͯ͠Δ৔߹ɺ
 ͞ΒʹʮͲͷ͘Β͍Ͱ൓ө͞Ε͏Δ͔ʯʮϦτϥΠΛͲ͏͢Δ͔ʯ΋ߟྀ • ΫϥΠΞϯτ͕࣋ͭαʔϏε#ͷঢ়ଶ͸εφοϓγϣοτͰ͔͠ͳ͍ • ΫϥΠΞϯτ͸ϚΠΫϩαʔϏεؒͷؔ܎ੑʹ͍ͭͯͷ஌ࣝΛ࣋ͨ͟ΔΛಘͳ͍
  36. !36 ໰୊ͷয఺ • αʔόϨεϙϯεͷ੔ܗ 6*ૢ࡞ͷαʔό΁ͷ఻ୡʁ • αʔϏεؒͷϋϒͱͯ͠ɺදࣔ಺༰ͷ੔߹ੑΛҡ࣋͢Δʁ • ෼ࢄίϯϐϡʔςΟϯάΛආ͚ΔͨΊͷϩʔΧϧͳΠϯλϑΣʔεʁ •

    ෳ਺ͷը໘ؒͰͷ੔߹ੑͷҡ࣋ʁ • ΫϥΠΞϯτͱαʔόͷίϯςΩετ͕Ͳ͜·Ͱ౷߹Մೳ͔͸ɺ
 ʮϏδωεϩδοΫʯͷް͞ͰมΘΓ͏Δ ΫϥΠΞϯτʹ͓͚ΔʮϏδωεϩδοΫʯͱ͸Կ͔
  37. ʮϏδωεϩδοΫʯͷఆٛ͸ ΞϓϦʹΑͬͯɺ αʔϏεʹΑͬͯҧ͏͸ͣ

  38. ͋ͳͨͷαʔϏεʹ͓͍ͯ ΫϥΠΞϯτͷίϯςΩετ ͱ͸ԿͰ͔͢ʁ