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

事業のスケールアウトを支える PHPで作る分散アーキテクチャ

yuuki takezawa
December 11, 2020

事業のスケールアウトを支える PHPで作る分散アーキテクチャ

事業の成長と、それにともなうアプリケーションの課題、
発生しがちな問題を追いながら、
解決策の一つであるCQRS導入について解説します。
分散システムで発生する問題についても軽く触れていきます。

yuuki takezawa

December 11, 2020
Tweet

More Decks by yuuki takezawa

Other Decks in Technology

Transcript

  1. ࣄۀͷεέʔϧΞ΢τΛࢧ͑Δ


    PHPͰ࡞Δ෼ࢄΞʔΩςΫνϟ
    Yuuki Takezawa / ytake

    View full-size slide

  2. Pro
    f
    i
    le
    • ஛ᖒ ༗و / ytake


    • ελʔϑΣεςΟόϧגࣜձࣾ


    • PHP, Hack, Go, Scala


    • Apache Hadoop, Apache Spark, Apache Kafka

    • twitter https://twitter.com/ex_takezawa


    • facebook https://www.facebook.com/yuuki.takezawa


    • github https://github.com/ytake

    View full-size slide

  3. ελʔϑΣεςΟόϧגࣜձࣾ

    View full-size slide

  4. ͦΜͳελʔϑΣεςΟόϧͰ͸


    ΤϯδχΞืूதʂʂʂ

    View full-size slide

  5. Caution
    • ࠓճͷ಺༰͸શͯͷΞϓϦέʔγϣϯͰ

    ద༻Ͱ͖Δ΋ͷͰ͸͋Γ·ͤΜ


    • ࣮ࡍʹຊਓ͕࠾༻͍ͯ͠Δ΋ͷ

    ϕʔεͷ಺༰Ͱ͢

    View full-size slide

  6. Agenda
    • ΞϓϦέʔγϣϯͷ੒௕ͱ

    λʔχϯάϙΠϯτ

    • ղܾ͢ΔͨΊͷ஌ࣝ


    • ෼ࢄτϥϯβΫγϣϯରࡦ

    View full-size slide

  7. Ϗδωεͷ੒௕ͱ૊৫

    View full-size slide

  8. খ͞ͳνʔϜ
    • σʔλϕʔεઃܭ + ORM etc

    ϑϨʔϜϫʔΫͰߏங͞ΕΔ

    ΞϓϦέʔγϣϯ

    • গਓ਺ͷ։ൃऀͰߏ੒͞ΕΔ։ൃ૊৫

    View full-size slide

  9. ෳ਺ͷνʔϜ
    • ૿͑ΔΞϓϦέʔγϣϯػೳ

    • ։ൃνʔϜͷ૿һ

    εΩϧ͸༷ʑ

    View full-size slide

  10. ΞϓϦέʔγϣϯͱσʔλϕʔε
    • ORMͰN+1͕૿͑Δέʔε

    ൃߦͨ͠SQL͸

    ΞϓϦέʔγϣϯʹ߹͍ͬͯΔ͔ʁ


    • ϝϞϦɺCPUͳͲͷ૿ڧͰ৐Γ੾Δ

    ໰୊͕ޙճ͠ʹͳΔ͜ͱ΋

    View full-size slide

  11. ΍ͬͯ͠·͍͕ͪͳରԠ
    • σʔλऔಘ؆ུԽͷͨΊͷ

    σʔλϕʔεઃܭ(;͑Δඇਖ਼نԽ)

    • ͱΓ͋͑ͣϦετͰશ෦औಘ

    ͦΕ͔Β1ϨίʔυͣͭৄࡉΛऔಘ͠Α͏

    View full-size slide

  12. ΞϓϦέʔγϣϯͱσʔλϕʔε
    • SELECT * FROM articles;

    SELECT * FROM users WHERE user_id = ?;

    • ͜Ε͕΋͠10000݅औಘͰ

    ൃߦ͞Ε͍ͯͨΒʁ

    • ORM͕ѱ͍ͷͰ͸ͳ͘

    ద੾ʹར༻Ͱ͖͍ͯͳ͍έʔε

    View full-size slide

  13. େ͖͘νʔϜͱࣄۀͷ੒௕
    • ૿͑ଓ͚ΔΞϓϦέʔγϣϯػೳ

    • ։ൃνʔϜͷڊେԽ

    ෳ਺ͷνʔϜߏ੒ͱ

    ෳ਺ͷεςʔΫϗϧμ

    View full-size slide

  14. ෆ҆ఆͳΞϓϦέʔγϣϯ΁
    • Ϩίʔυ૿Ճɾ࣮૷ίʔυ૿ՃʹΑΔ

    ͞ΒͳΔύϑΥʔϚϯε௿Լ


    • ͍͡ΊΒΕଓ͚Δσʔλϕʔε


    • ͋ͪͪ͜Ͱى͜Γ࢝ΊΔো֐

    View full-size slide

  15. ࠔ೉ͳཁ݅ͷ࣮ݱ
    • ϦΫΤετ͝ͱʹϨεϙϯεΛ૊Έཱͯ

    ΞϓϦέʔγϣϯͷύϑΥʔϚϯεѱԽ

    • ਖ਼نԽͨ͠͸͍͍΋ͷͷɺཁ݅ʹ߹Θͤ
    ͨσʔλऔಘίετ૿

    View full-size slide

  16. ΍ͬͯ͠·͍͕ͪͳରԠ
    • ݪҼ͸Θ͔Γ·ͤΜ͕஗͘ͳ͖ͬͯͨͷͰ
    Ωϟογϡ͠·͢

    -> ෳࡶԽ͢ΔΩϟογϡαʔόʔ


    • ݪҼ͸Θ͔Γ·ͤΜ͕஗͘ͳ͖ͬͯͨͷͰ
    Ωϟογϡ͠·͢

    -> ΩϟογϡαʔόʹՃ͑ͯCDN΋௥Ճ

    View full-size slide

  17. ΋͏खஈ͕ͳ͍ɾɾɾʂ

    View full-size slide

  18. ڊେͳΞϓϦέʔγϣϯ΁

    View full-size slide

  19. σʔλॲཧͷෳࡶԽ
    Ϣʔβʔ৘ใมߋ Ϣʔβʔ৘ใ࡟আ
    Ϣʔβʔ৘ใ͕ݟ͔ͭΒͳ͍ͨΊ

    σʔλॲཧ͝ͱʹ"1*ΞΫηε
    ͋ͦ͜ͱͦ͜Ͱ৘ใ͕ҧ͏ʂ

    Ͳͷσʔλ͕ຊ෺ʁ
    શͯͷΞϓϦέʔγϣϯ͔Β

    Ωϟογϡͳ͠ͰΞΫηε

    ৗʹߴෛՙঢ়ଶʹ

    View full-size slide

  20. ࢭΊΒΕͳ͍


    ϏδωεͷՃ଎

    View full-size slide

  21. ฐ֐
    • ϦϦʔε༏ઌͷͨΊɺ

    ܧ͗଍͠ͷΞϓϦέʔγϣϯ

    • εςʔΫϗϧμ૿Ճʹ൐͏

    ΞϓϦέʔγϣϯͷෳࡶԽ


    • খதن໛ͷΞϓϦέʔγϣϯ࣌୅ͷ

    ઃܭͱ࣮૷༝དྷͷෆ۩߹͕૿Ճ

    View full-size slide

  22. σʔλઃܭ༝དྷͷ໰୊
    • େྔσʔλͷϑϧεΩϟϯ

    • INDEXෆ଍ͷͨΊͷύϑΥʔϚϯε௿Լ


    • γϯϓϧͳߏ੒ނͷػೳ௥Ճ࣌ͷ

    ΫΤϦෳࡶԽ

    View full-size slide

  23. ࣮૷ίʔυ༝དྷͷฐ֐
    • ػೳ௥ՃͷͨΊͷௐࠪʹ2ϲ݄

    • ͞·͟·ͳཁҼͷੵΈॏͶʹΑΓ

    བྷΈ߹ͬͨίʔυͰϞνϕʔγϣϯμ΢ϯ


    • ͕͔͔࣌ؒͬͯ͠·͏͕ނɺ

    ϏδωενʔϜʹ·ͣҰݴ

    ʮ͕͔͔࣌ؒΔͷͰͰ͖·ͤΜʯ

    View full-size slide

  24. ͦͷ݁Ռ
    • Ϗδωεͷ੒௕ػձଛࣦ


    • γϡϦϯΫ࢝͠ΊΔࣄۀ


    • ଞࣾʹෛ͚ͯ͠·͏ࣄۀ


    • څ༩্͕͕Βͳ͍ɾɾ

    View full-size slide

  25. ͜ΕͰ͸ࣄۀ͕εέʔϧ͠ͳ͍ʂ

    View full-size slide

  26. ࣄۀ͸੒௕͢Δ΋ͷ
    • ΞϓϦέʔγϣϯ͸ϦϦʔε͔ͯ͠Β੒௕


    • ૝ఆ֎ͷ੒௕Λ਱͛Δ

    WebΞϓϦέʔγϣϯ


    • ͞·͟·ͳϏδωεͷՄೳੑΛߟྀͨ͠

    σʔλઃܭ

    View full-size slide

  27. ੒௕Λࢧ͑Δʹ͸ʁ
    • ఆظతͳσʔλϕʔεϦϑΝΫλϦϯάɺ
    ΞϓϦέʔγϣϯͷϦϑΝΫλϦϯά

    ͕࣮ࢪͰ͖Δ͔


    • ͋Γͱ͋ΒΏΔՄೳੑΛ૝ఆͨ͠σʔλ
    ઃܭ͸ෆՄೳ
    27

    View full-size slide

  28. ΞϓϦέʔγϣϯͰى͜Δ໰୊
    • ਖ਼نԽ͞Εͨςʔϒϧͱ

    ඇਖ਼نԽςʔϒϧͷઓ͍


    • ෳࡶԽ͢Δॻ͖ࠐΈॲཧͱଟൃ͢ΔN+1


    • σʔλϞσϧͱυϝΠϯϞσϧ͕ҟͳΔ

    View full-size slide

  29. Α͋͘ΔN+1
    • ঎඼Λऔಘ͠ ஍ҬɾΩονϯ৘ใΛऔಘ

    • ΠΠωɺΫνίϛ਺΋औಘ͠ͳ͚Ε͹...

    View full-size slide

  30. public function run(): \Generato
    r


    {
    foreach ($repository->findAll() as $row)
    {


    yield new ReadProductTransfer
    (


    $row
    ,


    $this->kitchenRepository->find($row->getId())
    ,


    $this->areaRepository->find($row->getId()
    )


    )
    ;

    }

    }


    View full-size slide

  31. ͜Μͳςʔϒϧઃܭͨ͠هԱ͸͋Γ·ͤΜ͔ʁ
    • UIΛߏ੒͢Δཁૉ͕औಘ͠΍͍͢

    ςʔϒϧઃܭ


    • JOIN͢Δͱ஗͘ͳΔʁ

    ͳΒ͹௒ϫΠυΧϥϜઃܭͩ

    View full-size slide

  32. ͜Μͳςʔϒϧ͋Γ·ͤΜ͔ʁ
    • ͳʹ͔ͷεςʔλεΛฦ͢ʹ͸

    ͋ͷΧϥϜͱ͜ͷΧϥϜͱ͋ΕΛɾɾɾɻ


    • ϏδωεϩδοΫ͕ςʔϒϧʹ͋Δ


    • ΧϥϜ໊ͱ༻్͕શ͘ผ

    View full-size slide

  33. ΞϓϦέʔγϣϯͰى͜Δ໰୊
    • ඇਖ਼نԽςʔϒϧ͸ಛఆͷཁ݅Ͱ͸ղܾ
    Ͱ͖Δ͕ɺͦΕҎ֎ʹ͸೉͍͠ɻ

    σʔλநग़ܥ΍ɺ

    αʔϏε֦େɺ࢓༷มߋͳͲʹ͸ແཧ͕
    ͋Δ

    View full-size slide

  34. ཁ݅ͱσʔλߏ଄ͷࠩ෼͸


    ඞͣ͋Δ

    View full-size slide

  35. ॻ͖ࠐΈͱಡΈࠐΈͷҧ͍
    ॻ͖ࠐΈ ಡΈࠐΈ
    Ұ؏ੑɾՄ༻ੑ
    τϥϯβΫγϣϯΛ༻
    ͍ͯॻ͖ࠐΈΛߦ͏
    Ұ؏ੑॏࢹ
    ݁Ռ੔߹ੑͱՄ༻ੑ
    σʔλ ਖ਼نԽ ඇਖ਼نԽ
    εέʔϥϏϦςΟ
    Ұൠతʹ
    εέʔϥϏϦςΟ͸

    ॏཁͰ͸ͳ͍
    ଟ͘ൺॏΛ઎Ί͓ͯΓ

    εέʔϥϏϦςΟ͸
    ॏཁ

    View full-size slide

  36. ߟ͑ΔϙΠϯτ
    • ॻ͖ࠐΈॲཧͰɺಡΈࠐΈཁ݅ʹରԠ͢Δ
    ͨΊͷॲཧ͕ଟ͍


    • ಡΈࠐΈཁ݅Λ஌Βͳ͚Ε͹ॻ͖ࠐΊͳ͍


    • Ϩεϙϯεͱσʔλߏ଄͕͋·Γʹ΋ҧ͍
    ͗͢Δ

    View full-size slide

  37. ߟ͑ΔϙΠϯτ
    • σʔλͷਖ਼͠͞ͱཁ݅Ϩϕϧͷਖ਼͠͞͸
    ҧ͏΋ͷ


    • ͲͪΒ͔ʹدͤͨઃܭʹ͢Δɺ

    Ͱ͸ͳ྆͘ํΛ෼཭Ͱ͖Ε͹γϯϓϧʹ

    View full-size slide

  38. ϛυϧ΢ΣΞϨϕϧͰ͸

    View full-size slide

  39. ॻ͖ࠐΈଟ਺ͷΞϓϦέʔγϣϯ
    • ॻ͖ࠐΈʹڧ͘ɺ

    εέʔϧ͕༰қͳσʔλϕʔε΁

    Cassandra, DynamoDB etc

    View full-size slide

  40. ಡΈࠐΈଟ਺ͷΞϓϦέʔγϣϯ
    • RDBMSͷΈͰ΋े෼

    • LIKEݕࡧͳͲ͸Elasticsearch, Solr΁

    View full-size slide

  41. ղܾɺͰ͖ͳ͍ɾɾ
    • ϛυϧ΢ΣΞϨϕϧͰͷղܾํ๏Ͱɺ

    ΞϓϦέʔγϣϯࣗମ͕࣋ͭ

    ෳࡶ͞͸ղܾͰ͖ͳ͍ɻ


    • ύϑΥʔϚϯε໘Ͱͷվળ͸Ͱ͖Δ͕ɺ

    ࣄۀͷ੒௕Λࢧ͑ΔεϐʔσΟ͞͸ͳ͍

    View full-size slide

  42. ΞϓϦέʔγϣϯϨϕϧͷ՝୊

    View full-size slide

  43. ΞϓϦέʔγϣϯϨϕϧͰͷ՝୊
    • ෼ੳΛߦΘͳ͍͜ͱʹΑΔޡͬͨ൚༻Խ


    • ෳ਺ͷίϯςΩετ͕ࠞࡏ


    • ͳΜͰ΋͠Α͏ͱ͢Δॲཧ

    View full-size slide

  44. ڥք෇͚ΒΕͨίϯςΩετ
    ঎඼͸

    ঎඼໊

    ѻ͍ͬͯΔΩονϯళฮ
    ஋ஈ

    ൢചظؒͰ͢

    View full-size slide

  45. ڥք෇͚ΒΕͨίϯςΩετ
    QSPEVDU/BNF

    LJUDIFO/BNF
    QSJDF
    TBMFT1FSJPE

    View full-size slide

  46. ڥք෇͚ΒΕͨίϯςΩετ
    ঎඼͸

    ঎඼໊

    ݸ਺
    ഑ૹઌͰ͢

    View full-size slide

  47. ڥք෇͚ΒΕͨίϯςΩετ
    QSPEVDU/BNF

    LJUDIFO/BNF
    QSJDF
    TBMFT1FSJPE
    RVBOUJUZ
    TJQQJOH"EESFTT

    View full-size slide

  48. ڥք෇͚ΒΕͨίϯςΩετ
    ঎඼͸

    ঎඼໊

    ஋ஈͰ͢

    View full-size slide

  49. ڥք෇͚ΒΕͨίϯςΩετ
    QSPEVDU/BNF

    LJUDIFO/BNF
    QSJDF
    TBMFT1FSJPE
    RVBOUJUZ
    TJQQJOH"EESFTT

    View full-size slide

  50. ڥք෇͚ΒΕͨίϯςΩετ
    • ঎඼ͱ͍͏ݴ༿Ͱ΋಺༰͕ҟͳΔ


    • ΞϓϦέʔγϣϯ಺Ͱ΋ଟʑ


    • ڞ௨ԽͰ͖Δ΋ͷͰ͸ͳ͍

    View full-size slide

  51. ڥք෇͚ΒΕͨίϯςΩετ
    • ྫ͑͹ɺ঎඼Λࢦ͢ݴ༿ͱ

    DB্ͷproductsςʔϒϧ͸Ұக͠ͳ͍
    έʔε͕ଟ͍

    • ͲͪΒ͔ʹ߹ΘͤΒΕΔ΋ͷͰ͸ͳ͍ͱ

    ೝࣝ͢Δ͜ͱ

    View full-size slide

  52. ॻ͖ࠐΈͱಡΈࠐΈΛ


    ෼཭ͯ͠Έͯ͸Ͳ͏͔

    View full-size slide

  53. CQRS
    • ॻ͖ࠐΈϞσϧͱಡΈࠐΈϞσϧΛִ཭


    • υϝΠϯϞσϧͷ෼཭͚ͩͰͳ͘

    σʔλετΞ͢Β΋෺ཧతʹผ෺ʹ෼཭Մೳ

    ؔ৺ࣄͷ෼཭Λపఈ

    • DDDʹ͓͚ΔಡΈࠐΈͱॻ͖ࠐΈͷࠩ෼Λղܾ͢Δ
    ύλʔϯ

    View full-size slide

  54. CQRS
    ͳΜΒ͔ͷม׵ॲཧΛ௨ͯ͡

    3FBEͷσʔλΛߋ৽

    View full-size slide

  55. CQRS
    • CommandͱReadʹڥքઢ͕͋Δ


    • CommandͱRead͸

    ಉ͡ϦϙδτϦɺϢʔεέʔεͱ͠ͳ͍


    • ಉ͡ςʔϒϧ͸ࢀর͠ͳ͍

    View full-size slide

  56. σʔλϕʔε΋෼཭Ͱ͖Ε͹ʁ

    View full-size slide

  57. େ͖͘ͳͬͨαʔϏεͰղܾ͞ΕΔ໰୊
    • ෳࡶԽ͍ͯͨ͠ಡΈࠐΈϞσϧͷ

    ύϑΥʔϚϯεΛվળ


    • ಡΈࠐΈϞσϧʹؔ͢Δ

    εέʔϥϏϦςΟ޲্

    View full-size slide

  58. ஫ҙ఺
    • CQRS͸ಛఆͷػೳʹͷΈద༻Մೳ

    ΞϓϦέʔγϣϯશͯʹద༻͢Δ΋ͷͰ͸
    ͳ͍


    • ॻ͖ࠐΈϞσϧͱಡΈࠐΈϞσϧͷࠩ෼͕Α
    ͘Θ͔Βͳ͍

    -> ཁ݅ͷ෼ੳΛ·ͣ͠·͠ΐ͏

    View full-size slide

  59. CQRSʹΑͬͯղܾ͞ΕΔ໰୊
    • ॻ͖ࠐΈϞσϧ͸CUDΛ୲౰͠ɺ

    υϝΠϯϞσϧͷ࣮૷Λߦ͏


    • ಡΈࠐΈϞσϧͷ୯७Խ

    DTOͷΈ΁

    View full-size slide

  60. CQRSʹΑͬͯղܾ͞ΕΔ໰୊
    • ಡΈࠐΈϞσϧ͸ɺཁ݅ʹ߹Θͤͨ

    ͞·͟·ͳσʔλϕʔεΛར༻͠

    ಡΈࠐΈϞσϧͷύϑΥʔϚϯεΛվળ


    • ॻ͖ࠐΈϞσϧ΋ಉ༷ʹ

    ཁ݅ʹ߹ΘͤͨσʔλϕʔεΛར༻

    View full-size slide


  61. • ϥϯΩϯάॲཧ

    ͋Δظؒ·ͰͷσʔλΛ࢖ͬͨ

    ϥϯΩϯάΛੜ੒


    • ੥ٻσʔλͷੜ੒
    
 

    ͳͲ

    View full-size slide

  62. ϥϯΩϯά࡞੒໰୊
    • ϦΫΤετຖʹϥϯΩϯά࡞੒

    -> εέʔϧ͠ͳ͍

    • ྫ͑͹1ԯલޙͷશσʔλʹରͯ͠

    ౎౓ΫΤϦΛ౤͛ͯऔಘ͢Δ

    View full-size slide

  63. ঎඼ͷϥϯΩϯάྫ
    • ྫ͑͹

    ঎඼ͦͷ΋ͷΛѻ͏Ϟσϧͱ

    ϥϯΩϯάΛߏ੒͢Δ঎඼ͷϞσϧΛ

    ڞ௨Խͯ͠͠·͏

    View full-size slide

  64. ঎඼ͷϥϯΩϯάྫ
    • ྫ͑͹

    ঎඼ͦͷ΋ͷΛѻ͏Ϟσϧͱ

    ϥϯΩϯάΛߏ੒͢Δ঎඼ͷϞσϧΛ

    ڞ௨Խͯ͠͠·͏

    -> ౰વμϝ

    View full-size slide

  65. ϥϯΩϯά࡞੒໰୊ղܾ
    • લ೔·ͰͷσʔλΛ࢖ͬͯ

    ϥϯΩϯάΛ࡞Δཁ݅ͷ৔߹

    ʢཁ݅ʹΑͬͯมΘΓ·͢ʣ


    • σʔλͷߏ੒ཁૉ͸ෆมͰ

    ౎౓ੜ੒͢Δඞཁ͸ͳ͍

    ࣄલʹσʔλΛੜ੒͠ɺϦʔυΛ୲౰͢Δσʔλ
    ϕʔεʹอ࣋

    View full-size slide

  66. ϥϯΩϯά࡞੒໰୊ղܾ
    • ϥϯΩϯάʹ͍ͭͯͷ஌͕ࣝͳ͘ͱ΋

    ಘΒΕΔ͜ͱ͕Ͱ͖Δ


    • ElasticsearchͷΤΠϦΞεͳͲΛ

    ར༻͢Δ͜ͱͰ༰қʹରԠՄೳ

    View full-size slide

  67. ϥϯΩϯά࡞੒໰୊ղܾ
    • ϥϯΩϯάੜ੒ʹෆ۩߹͕͋ͬͨ৔߹ɺ

    ࠶౓ੜ੒͢Ε͹ྑ͍


    • ো֐͕͋ͬͯ΋࠶࣮ߦ͢Ε͹Α͍

    View full-size slide

  68. CQRS ར఺
    • ଱ো֐ੑͷ޲্


    • εέʔϥϏϦςΟ


    • ޮ཰ͷྑ͍σʔλϕʔεͷબ୒


    • పఈͨؔ͠৺ͷ෼཭

    View full-size slide

  69. CQRS ܽ఺
    • ҰͭҰͭͷػೳ͸γϯϓϧ

    ߏ੒͢Δཁૉ͕૿͑ΔͨΊશମͰݟΔͱ
    ෳࡶԽ

    • ϨϓϦέʔγϣϯͷλΠϜϥά

    View full-size slide

  70. ෳࡶԽ
    • CUDΞϓϦέʔγϣϯ

    • RΞϓϦέʔγϣϯ


    • ಡΈࠐΈϞσϧߋ৽ΞϓϦέʔγϣϯ

    View full-size slide

  71. ෳࡶԽ
    • ѻ͏σʔλϕʔε͕૿͑Ε͹ɺ

    ͦΕͧΕͷσʔλϕʔεʹ߹Θͤͨ

    ؅ཧɺӡ༻ํ๏͕ඞཁ


    • ։ൃ࣌ʹෳ਺ͷσʔλϕʔεͷ஌͕ࣝ

    ඞਢ

    View full-size slide

  72. ϨϓϦέʔγϣϯͷλΠϜϥά
    • γϯϓϧͳϥϯΩϯάͳͲ͸໰୊ͳ͠

    • ϦΞϧλΠϜੑ͕ཁٻ͞ΕΔॲཧ

    ྫ) ঎඼͕ొ࿥͞ΕͨΒଈ

    ݕࡧΫΤϦͰώοτͰ͖Δ༷ʹͯ͠ʂ

    View full-size slide

  73. ϨϓϦέʔγϣϯͷλΠϜϥά
    • ͍͍ͶϘλϯΛԡͨ͠ΒΠϯΫϦϝϯτ/
    σΫϦϝϯτͤͯ͞ɺ͍͍ͶॱͰιʔτ


    • ϝοηʔδ͕౤ߘ͞ΕͨΒɺ

    ϑΥϩϫʔશһʹϦΞϧλΠϜͰ௨஌

    View full-size slide

  74. CQRS͚ͩͰ͸ղܾ͕Ͱ͖ͳ͍
    • DBͷτϦΨʔͳͲΛ༻͍ͯมߋΛݕ஌

    ҟͳΔσʔλϕʔεΛબ୒͢Δͱ

    ରԠෆՄೳ


    • ϦʔυϞσϧߋ৽༻ϓϩηεΛ

    ༻ҙ͠ͳ͚Ε͹ͳΒͳ͍

    ͕ɺมߋͷݕ஌͕͏·͘Ͱ͖ͳ͍

    View full-size slide

  75. ྫ֎
    • Debezium


    • DynamoDB streams


    • LinkedIn Databus
    
 

    ͳͲ͸ॻ͖ࠐΈΛݕ஌ͯ͠௨஌Մೳ

    View full-size slide

  76. CQRS͚ͩͰ͸ղܾ͕Ͱ͖ͳ͍
    • ҟͳΔσʔλϕʔε΁ͷίϛοτ

    • 2ϑΣʔζίϛοτରԠ͸೉͍ͨ͠Ί

    ආ͚ͳ͚Ε͹ͳΒͳ͍

    View full-size slide

  77. ϑϨʔϜϫʔΫͰղܾͰ͖Δ͡ΌΜʂ
    • ྫ͑͹Laravel

    Queue͸ɺPHPͷΦϒδΣΫτΛ

    γϦΞϥΠζ͠QueueʹಥͬࠐΜͩ෺


    • पลγεςϜ͕PHPͩͱ͸ݶΒͳ͍

    View full-size slide

  78. Event Sourcing

    View full-size slide

  79. Event Sourcing
    • ΠϕϯτΛه࿥ͯ͠࠶ݱ͢Δύλʔϯ


    • ΠϕϯτΛΠϕϯτετΞʹอଘ͠ਅͷιʔεʹ


    • ه࿥͞ΕͨΠϕϯτ͔ΒΦϒδΣΫτΛ෮ݩ


    • Πϕϯτ͸ෆม

    View full-size slide

  80. Event Sourcing
    • ಡΈࠐΈ͕ར༻͢Δσʔλϕʔε΁ͷ

    ൓өʹඞਢ


    • ৴པͰ͖Δਅͷσʔλιʔεʹ

    ΠϕϯτετΞʹσʔλ͕͋Ε͹ྑ͍

    View full-size slide

  81. Message Brokerબఆ
    • PubSubͰشൃੑͷͳ͍΋ͷΛબ୒͢Δ


    • ϝοηʔδอ؅͕ՄೳͰɺ࠶ݱ͢Δ͜ͱ
    ͕Մೳͳ΋ͷΛ࠾༻͢Δͷ͕๬·͍͠


    • εέʔϥϒϧͰ͋Δ͜ͱ

    View full-size slide

  82. ͓͢͢Ί͸ʁ
    • Message Broker͸εέʔϥϏϦςΟॏࢹ


    • ௚ۙͷΠϕϯτΛ͙͢ʹऔಘͰ͖Δ΋ͷ


    • ۤ࿑ͨ͘͠ͳ͚Ε͹Apache Kafka

    (AWS MSK / Con
    f
    l
    uent ͳͲ)

    View full-size slide

  83. Event Sourcing


    CQRS

    View full-size slide

  84. CQRS
    σʔλߋ৽͕ൃੜʂ

    ৽͍͠σʔλૹΓ·͢Ͷ

    View full-size slide

  85. ղܾͰ͖Δ໰୊

    View full-size slide

  86. ෳࡶ͔ͭϋΠύϑΥʔϚϯεͳ

    ݕࡧ

    View full-size slide

  87. N+1ͳͲʹΑΔύϑΥʔϚϯεྼԽ
    εφοϓγϣοτతʹσʔλΛ

    ॻ͖ࠐΈ

    MBTUJOTFSU*%͕Ͳ͏ͯ͠΋࢖͍͍ͨ৔߹ͳͲ

    View full-size slide

  88. N+1ͳͲʹΑΔύϑΥʔϚϯεྼԽ
    %#ॻ͖ࠐΈ׬ྃޙɺ
    ಛఆͷΠϕϯτΛൃߦ

    View full-size slide

  89. N+1ͳͲʹΑΔύϑΥʔϚϯεྼԽ
    ಡΈࠐΈϞσϧߋ৽ϓϩηε͕
    ΠϕϯτΛফඅ

    View full-size slide

  90. N+1ͳͲʹΑΔύϑΥʔϚϯεྼԽ
    &MBTUJDTFBDI΁ॻ͖ࠐΈ

    ಛఆͷϨίʔυͷΈॻ͖׵͑Δ

    ྫ͑͹ϥΠΫ਺΍ɺίϝϯτ਺ͳͲ

    View full-size slide

  91. N+1ͳͲʹΑΔύϑΥʔϚϯεྼԽ
    ಡΈࠐΈ͸γϯϓϧʹ

    ΠϯσοΫεʹ໰͍߹ΘͤΔͷΈ

    ෳࡶͳܭࢉॲཧ͸ߦΘͳ͍

    View full-size slide

  92. ϝϦοτ
    • ॴҦεϚʔτUIύλʔϯΛ

    ଞʹӨڹΛ༩͑Δ͜ͱͳ࣮͘ݱ


    • ॻ͖ࠐΈͰඞཁͱ͞ΕΔਖ਼نԽΛ่͢͜ͱͳ͘

    ରԠՄೳ


    • ಡΈࠐΈΛεέʔϧͤ͞΍͍͢

    View full-size slide

  93. ϝϦοτ
    • ಡΈࠐΈϞσϧͷߋ৽ॲཧ΋ࢸͬͯ؆୯

    • ৔߹ʹΑͬͯ͸ϏδωεϩδοΫΛ࣮૷
    ͢Δ͜ͱ΋͋ΓɺෳࡶʹͳΒͳ͍Α͏ʹ
    ஫ҙ͢Δ

    View full-size slide

  94. ஫ҙ
    • Ϩίʔυʹߋ৽ɺ

    ࡟আ͕ൃੜ͢Δ৔߹

    μʔςΟϦʔυʹ஫ҙ

    View full-size slide

  95. ෼ࢄτϥϯβΫγϣϯ

    View full-size slide

  96. ෼ࢄτϥϯβΫγϣϯ
    • ಡΈࠐΈϞσϧߋ৽ϓϩηε͕

    ෳ਺ͷσʔλϕʔεʹ

    ॻ͖ࠐ·ͳ͚Ε͹͍͚ͳ͍έʔε


    • 2ϑΣʔζίϛοτ͸ίετ͕ߴ͍

    View full-size slide

  97. ෼ࢄτϥϯβΫγϣϯ͸೉͘͠ɺෳࡶ
    • ෺ཧతʹҟͳΔσʔλϕʔεͰ

    ॲཧ͕ࣦഊͨ͠৔߹

    • औΓফ͢ॲཧΛ૸Βͤͳ͚Ε͹ͳΒͳ͍


    • NoSQL΍KafkaͳͲʹ͸ͳ͍

    View full-size slide

  98. ෼ࢄτϥϯβΫγϣϯΛ࢖Θͳ͍
    • ҰͭͷϓϩηεͰ

    ෳ਺σʔλϕʔε΁ॻ͖ࠐΉͷΛආ͚Δ


    • Ͳ͏ͯ͠΋ආ͚ΒΕͳ͍৔߹͸

    ϚΠΫϩαʔϏεΞʔΩςΫνϟͷ

    τϥβΫγϣϯରࡦͷҰͭɺSagaΛར༻

    View full-size slide

  99. ίϨΦάϥϑΟͷαʔΨ
    ঎඼ड஫ΠϕϯτΛൃߦ

    View full-size slide

  100. ίϨΦάϥϑΟͷαʔΨ
    ΩονϯαʔϏε͕

    ঎඼ड஫ΠϕϯτΛফඅ
    1&/%*/(ঢ়ଶͱ͢Δ

    View full-size slide

  101. ίϨΦάϥϑΟͷαʔΨ
    ΩονϯαʔϏε͕

    ঎඼༻ҙΠϕϯτΛൃߦ

    View full-size slide

  102. ίϨΦάϥϑΟͷαʔΨ
    ঎඼༻ҙΠϕϯτΛফඅ
    ΫϨδοτܾࡁΛ࣮ߦ

    View full-size slide

  103. ίϨΦάϥϑΟͷαʔΨ
    ձܭαʔϏε͕

    ܾࡁ׬ྃΠϕϯτΛൃߦ

    View full-size slide

  104. ίϨΦάϥϑΟͷαʔΨ
    ΩονϯαʔϏε͕

    ܾࡁ׬ྃΠϕϯτΛফඅ

    ࠷ऴతͳΠϕϯτΛऔಘ͢Δ·Ͱ
    "8"*5*/(ঢ়ଶͱ͢Δ

    View full-size slide

  105. ίϨΦάϥϑΟͷαʔΨ
    ঎඼ड஫αʔϏε͕

    ܾࡁ׬ྃΠϕϯτΛফඅ

    View full-size slide

  106. ίϨΦάϥϑΟͷαʔΨ
    ঎඼ड஫αʔϏε͕

    ड஫Λਖ਼ৗऴྃͱݟ၏͠௨஌

    View full-size slide

  107. ίϨΦάϥϑΟͷαʔΨ
    ड஫ਖ਼ৗऴྃΛফඅ͠ɺ
    Φʔμʔ௨ΓͷྉཧΛ։࢝

    View full-size slide

  108. ίϨΦάϥϑΟͷαʔΨ ϝϦοτ
    • ର৅͕গͳ͘ɺγϯϓϧͳॲཧͷϑϩʔ
    ʹ࠷ద

    • ॲཧͷ੹຿͕෼ࢄ͍ͯ͠ΔͨΊ

    ୯Ұো֐఺ͳ͠

    View full-size slide

  109. ίϨΦάϥϑΟͷαʔΨ σϝϦοτ
    • ෼ࢄ͍ͯ͠Δ͕ނʹΘ͔Γʹ͍͘


    • ॥؀ґଘ


    • ݁߹ςετͷ೉қ౓͕ߴ͍


    • ؔ܎͢ΔαʔϏεͷΠϕϯτ͸શͯαϒεΫ
    ϥΠϒ͢Δඞཁ͕͋Δ

    View full-size slide

  110. ΦʔέετϨʔγϣϯͷαʔΨ
    ঎඼ड஫ΠϕϯτΛൃߦ

    View full-size slide

  111. ΦʔέετϨʔγϣϯͷαʔΨ
    ΩονϯαʔϏε͕

    ঎඼ड஫ΠϕϯτΛফඅ
    1&/%*/(ঢ়ଶͱ͢Δ

    View full-size slide

  112. ΦʔέετϨʔγϣϯͷαʔΨ
    ΩονϯαʔϏε͕

    ঎඼༻ҙΠϕϯτΛൃߦ

    View full-size slide

  113. ΦʔέετϨʔγϣϯͷαʔΨ
    ΦʔέετϨλʔͱͯ͠

    ঎඼༻ҙΠϕϯτΛফඅ

    View full-size slide

  114. ΦʔέετϨʔγϣϯͷαʔΨ
    ձܭαʔϏεʹ
    ΫϨδοτܾࡁґཔΠϕϯτΛ
    ൃߦ

    View full-size slide

  115. ΦʔέετϨʔγϣϯͷαʔΨ
    ΫϨδοτܾࡁґཔΠϕϯτΛ

    ফඅ

    ܾࡁΛߦ͏

    View full-size slide

  116. ΦʔέετϨʔγϣϯͷαʔΨ
    ΫϨδοτܾࡁ׬ྃΠϕϯτΛ

    ൃߦ

    View full-size slide

  117. ΦʔέετϨʔγϣϯͷαʔΨ
    ΫϨδοτܾࡁ׬ྃΠϕϯτফඅ
    ΩονϯαʔϏεʹܾࡁ׬ྃΠϕ
    ϯτΛൃߦ

    View full-size slide

  118. ΦʔέετϨʔγϣϯͷαʔΨ ϝϦοτ
    • ॥؀ґଘͳ͠


    • ؔ܎͢ΔαʔϏεͷΠϕϯτΛαϒεΫ
    ϥΠϒ͢Δඞཁ͕ͳ͍


    • ίϨΦάϥϑΟΑΓ΋εςʔλεΛ࣋ͨ
    ͳ͍ͨΊɺϩδοΫ͕୯७ʹ

    View full-size slide

  119. ΦʔέετϨʔγϣϯͷαʔΨ ϝϦοτ
    • ΦʔέετϨʔλʹϏδωεϩδοΫ͕

    ूத͠΍͘͢ͳΔ

    ίʔσΟωʔτ͚ͩΛߦ͏Α͏ʹ

    ϏδωεϩδοΫΛഉআ͢Δඞཁ͋Γ


    • ϫʔΫϑϩʔܗʹͳΔͨΊɺ

    ো֐఺ʹͳΔՄೳੑ͋Γ

    View full-size slide

  120. αʔΨͷ஫ҙ఺
    • ߋ৽σʔλͷ૕ࣦ


    • μʔςΟϦʔυ


    • ൓෮ෆೳಡΈऔΓ

    View full-size slide

  121. αʔΨͷ஫ҙ఺
    • ෼ࢄॲཧ͸Ԟ͕ਂ͘೉қ౓͕ߴ͍


    • PHPͰ࣮ݱͤ͞Δͷ͸͓͢͢Ί͠·ͤΜ


    • ಘҙͳݴޠɺ࢓૊Έʹ೚ͤΑ͏

    View full-size slide

  122. ES+CQRSͷ

    ΤοηϯεΛऔΓೖΕΔ

    View full-size slide

  123. ES+CQRSͷൃల
    • DDD޲͚ͷղܾύλʔϯͰ͸͋Δ͕ɺ

    ۙ೥Ͱ͸ΤοηϯεΛऔΓೖΕͨ

    LambdaɺKappaΞʔΩςΫνϟ͕͋Δ

    (େن໛σʔλॲཧ޲͚ not Web App)

    View full-size slide

  124. KappaΞʔΩςΫνϟ

    View full-size slide

  125. KappaΞʔΩςΫνϟ

    View full-size slide

  126. ·ͱΊ
    • Ϗδωεʹؔ৺Λ࣋ͭ͜ͱ͕ୈҰ


    • ن໛ʹ߹Θͤͨσʔλઃܭ

    ఆظతͳϦϑΝΫλϦϯά

    ཁ݅ͷ෼ੳͰϏδωεΛࢧ͑Δ


    • దࡐదॴΛݟۃΊΔٕज़

    View full-size slide

  127. ࣄۀΛࢧ͍͑ͯ͜͏

    View full-size slide