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

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

takasek
October 30, 2018

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

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

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

takasek

October 30, 2018
Tweet

More Decks by takasek

Other Decks in Technology

Transcript

  1. ϚΠΫϩαʔϏεͱ

    ΫϥΠΞϯτͱ

    ίϯςΩετڥք
    For Microservices Meetup vol.9
    2018/10/30
    FiNC Technologies Inc. / iOS Development Team
    ؔ ོٛ(takasek)

    View full-size slide

  2. !2
    ● ོؔٛ
    ● !UBLBTFL
    ● 'J/$5FDIOPMPHJFT
    ● $MJFOU&OHJOFFS J045FBN

    ࣗݾ঺հ

    View full-size slide

  3. !3
    ● ʮJ04ΞϓϦઃܭύλʔϯೖ໳ʯ ڞஶ

    ● 1&",4ΑΓ݄ϦϦʔε༧ఆʂ
    IUUQTQFBLTDDJ04@BSDIJUFDUVSF
    .7$ .71 .77. 'MVY 3FEVY $MFBO"SDIJUFDUVSF
    ϞόΠϧಛ༗ͷىಈܦ࿏ɾը໘ભҠͷ੔ཧ·Ͱ໢ཏʂ
    ؔ͸ɺʮઃܭͱ͸Կ͔ʯͱ͍͏େ͖ͳओޠͰষ΄Ͳʂ
    ೥ .7$
    ʙ͔Β࿈໖ͱଓ͘
    ΞʔΩςΫνϟύλʔϯͷྺ࢙ͷ੔ཧʂ
    ϚαΧϦඞࢸͷϏοάΠγϡʔʹՌ׶ʹ௅Έ·ͨ͠ʂ
    એ఻

    View full-size slide

  4. !4
    ຊ೔ͷ͓୊
    ʮΫϥΠΞϯτɾαʔόؒͷ
    ίϯςΩετڥքΛͲ͜ʹஔ͔͘ʯ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  7. !7
    BFF
    BFF
    (Backends
    For
    Frontends)
    micro-
    services
    Repository
    UseCase
    Domain
    ViewModel
    View
    Server side
    Client side

    View full-size slide

  8. !8
    BFFʁ
    ΫϥΠΞϯτϩδοΫͷͨΊͷαʔό
    ● ௨৴ͷू໿
    ● ू໿ϩδοΫͷڞ༗
    Backends For Frontends

    View full-size slide

  9. !9
    Repository
    BFF
    (Backends
    For
    Frontends)
    micro-
    services
    Repository
    UseCase
    Domain
    ViewModel
    View
    Server side
    Client side

    View full-size slide

  10. !10
    Repositoryʁ
    σʔλΛͲ͔͜Βऔಘ͢ΔͲ͜ʹӬଓԽ͢Δ͔Λߟ͑ͳ͍
    ● ϝϞϦ
    ● ετϨʔδ
    ● ωοτϫʔΫ
    ● FUDʜ
    σʔλऔಘɾӬଓԽͷৄࡉΛӅṭ͢Δઃܭύλʔϯ

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  13. !13
    ू໿ʁ
    ● ෆม৚݅ʢৗʹ੔߹ੑΛอ͍ͬͯΔඞཁͷ͋ΔϏδωεϧʔϧʣΛ

    อূ͢Δ୯Ґ
    ● ू໿಺Ͱ͸੔߹ੑΛҡ࣋͢Δ

    View full-size slide

  14. !14
    UseCase
    BFF
    (Backends
    For
    Frontends)
    micro-
    services
    Repository
    UseCase
    Domain
    ViewModel
    View
    Server side
    Client side

    View full-size slide

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

    View full-size slide

  16. !16
    ViewModel, View
    BFF
    (Backends
    For
    Frontends)
    micro-
    services
    Repository
    UseCase
    Domain
    ViewModel
    View
    Server side
    Client side

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  22. !22
    BFFΛม׵૚ͱͯ͠ݟͳ͢
    ● ϝϦοτ
    ● ੔߹ੑʹ͍ͭͯͷ৺഑ࣄΛυϝΠϯ͔Βഉআ
    ● ϓϥοτϑΥʔϜ J04"OESPJE౳
    ͷॏෳ࣮૷Λഉআ
    ● σϝϦοτ
    ● #''ʹཔΓ͗͢Δʹ෼ࢄίϯϐϡʔςΟϯάͷݪଇ΁ͷ௅ઓ

    View full-size slide

  23. !23
    ෼ࢄίϯϐϡʔςΟϯάͷݪଇ
    ● ωοτϫʔΫ͸৴པͰ͖ͳ͍
    ● ʢ࣌ʹ͸͔ͳΓͷʣ஗Ԇ͕ৗʹൃੜ͢Δ
    ● ଳҬ෯ʹ͸ݶΓ͕͋Δ
    ● ωοτϫʔΫ͸ηΩϡΞͰ͸ͳ͍
    ● ؅ཧऀ͸ෳ਺Ͱ͋Δ
    ● సૹίετ͸θϩͰ͸ͳ͍
    ● ωοτϫʔΫ͸Ұ༷Ͱ͸ͳ͍
    - ࣮ફυϝΠϯۦಈઃܭ ΑΓ

    View full-size slide

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

    View full-size slide

  25. !25
    RepositoryΛม׵૚ͱͯ͠ݟͳ͢
    ● ϝϦοτ
    ● ੔߹ੑʹ͍ͭͯͷ৺഑ࣄΛυϝΠϯ͔ΒഉআͰ͖Δ
    ● σϝϦοτ
    ● ͜Ε͸΋͸΍ϏδωεϩδοΫͳͷͰ͸ʜʁ
    ● ϓϥοτϑΥʔϜ J04"OESPJE౳
    ͷॏෳ࣮૷

    View full-size slide

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

    View full-size slide

  27. !27
    UseCaseΛม׵૚ͱͯ͠ݟͳ͢
    ● ϝϦοτ
    ● ʮαʔόͷίϯςΩετΛΫϥΠΞϯτͰͲͷΑ͏ʹѻ͏͔ʯ

    ʹϏδωεϩδοΫͰ͋Δɺͱ͍͏ೝࣝ
    ● ΫϥΠΞϯτ։ൃͰ͸ɺࣗવʹ͜͜ʹམͪண͘͜ͱ͕ଟͦ͏
    ● σϝϦοτ
    ● ϓϥοτϑΥʔϜ J04"OESPJE౳
    ͷॏෳ࣮૷

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  31. !31
    ViewModelΛม׵૚ͱͯ͠ݟͳ͢
    ● ΞϯνύλʔϯͰ͸ʁ

    View full-size slide

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

    View full-size slide

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

    7JFX͸ϚΠΫϩαʔϏεʢಠཱͯ͠ϏϧυՄೳͳ୯ҐʣͰ͸ͳ͍
    ● ΍͸Γը໘ίϯϙʔωϯτؒͷ੔߹ੑΛؾʹ͠ͳ͚Ε͹ͳΒͳ͍
    ● ͦΕ͸7JFXͷ੹຿ͩΖ͏͔ʁ

    View full-size slide

  34. !34
    ΫϥΠΞϯτ͕୲อ͢΂͖੔߹ੑ
    ● .PEFMͱ7JFXͷؒͷ੔߹ੑ
    ● 6*ૢ࡞Λ.PEFMʹ఻ୡ
    ● .PEFMͷঢ়ଶมߋΛ7JFXʹ൓ө
    ● ڞ௨͢Δ.PEFMʹؔ৺ͷ͋Δ͢΂ͯͷ7JFXʹมߋ͕ಉظ͞ΕΔ
    ● .PEFMͱ.PEFMͷ੔߹ੑ
    ● αʔϏε"͔ΒͷϨεϙϯεͱ

    αʔϏε#͔ΒͷϨεϙϯεΛͻͱͭͷ.PEFMʹ݁߹͢Δ
    ● αʔϏε"Λߋ৽ͨ͠ΒɺαʔϏε#ʹ΋มԽ͕ੜ͍ͯ͡Δ͔΋͠Εͳ͍

    View full-size slide

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

    ໌ࣔతʹαʔϏε#ͷऔಘ"1*Λୟ͘ඞཁ͕͋Δ
    ● αʔϏε͕ؒ݁Ռ੔߹ੑΛલఏʹ͍ͯ͠Δ৔߹ɺ

    ͞ΒʹʮͲͷ͘Β͍Ͱ൓ө͞Ε͏Δ͔ʯʮϦτϥΠΛͲ͏͢Δ͔ʯ΋ߟྀ
    ● ΫϥΠΞϯτ͕࣋ͭαʔϏε#ͷঢ়ଶ͸εφοϓγϣοτͰ͔͠ͳ͍
    ● ΫϥΠΞϯτ͸ϚΠΫϩαʔϏεؒͷؔ܎ੑʹ͍ͭͯͷ஌ࣝΛ࣋ͨ͟ΔΛಘͳ͍

    View full-size slide

  36. !36
    ໰୊ͷয఺
    ● αʔόϨεϙϯεͷ੔ܗ6*ૢ࡞ͷαʔό΁ͷ఻ୡʁ
    ● αʔϏεؒͷϋϒͱͯ͠ɺදࣔ಺༰ͷ੔߹ੑΛҡ࣋͢Δʁ
    ● ෼ࢄίϯϐϡʔςΟϯάΛආ͚ΔͨΊͷϩʔΧϧͳΠϯλϑΣʔεʁ
    ● ෳ਺ͷը໘ؒͰͷ੔߹ੑͷҡ࣋ʁ
    ● ΫϥΠΞϯτͱαʔόͷίϯςΩετ͕Ͳ͜·Ͱ౷߹Մೳ͔͸ɺ

    ʮϏδωεϩδοΫʯͷް͞ͰมΘΓ͏Δ
    ΫϥΠΞϯτʹ͓͚ΔʮϏδωεϩδοΫʯͱ͸Կ͔

    View full-size slide

  37. ʮϏδωεϩδοΫʯͷఆٛ͸
    ΞϓϦʹΑͬͯɺ
    αʔϏεʹΑͬͯҧ͏͸ͣ

    View full-size slide

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

    View full-size slide