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

Event Sourcing,CQRS For PHP Application

Event Sourcing,CQRS For PHP Application

PHPアプリケーションでEvent Sourcing、CQRSを実践する場合の
ミドルウェアとの組み合わせ、基本的な考え方
実例を交えた資料です

yuuki takezawa

June 12, 2018
Tweet

More Decks by yuuki takezawa

Other Decks in Technology

Transcript

  1. Event Sourcing
    CQRS
    For PHP Application
    yuuki takezawa
    phpcon fuk 2018

    View full-size slide

  2. ͸ͳ͢͜ͱ
    • Event
    • CQRS
    • Event Sourcing + CQRS
    • Event Sourcing / Message Broker
    • ࣮ྫ

    View full-size slide

  3. ͸ͳ͞ͳ͍͜ͱ
    • DDD
    • Lambda Architecture
    • Kappa Architecture
    • Apache Sparkʹ͍ͭͯ

    View full-size slide

  4. DDDͱҰॹʹड़΂ΒΕΔ͜ͱ͕ଟ͍Ͱ͕͢ɺ
    େن໛ͳσʔλॲཧͰ΋׆༻Ͱ͖Δύλʔϯ

    View full-size slide

  5. όονॲཧ͕ଟ͍ΞϓϦέʔγϣϯ΍ɺ
    ෳ਺ͷσʔλϕʔεؒͰ
    σʔλಉظΛ͢ΔΞϓϦέʔγϣϯʹ΋

    View full-size slide

  6. Event / Application Side

    View full-size slide

  7. Event?
    • Observerύλʔϯ
    • ʙͨ࣌͠ʹɺʙ͢Δ Λදݱ͢Δ
    • PHPͷ༷ʑͳΞϓϦέʔγϣϯͰར༻͞Ε͍ͯΔ
    • \SplObserver, SplSubject

    View full-size slide

  8. Event / PHP
    • Symfony Event Dispatcher
    • Illuminate Events (Laravel)
    • Zend Event Manager
    • RxPHP
    • ReactPHP

    View full-size slide

  9. Event / PHP
    • γεςϜ౎߹ͰऔΓೖΕΔέʔε΋ଟ͍
    • Request͕དྷͨΒɺRouteΛىಈͤ͞Δ
    • ʙͷॲཧ͕׬ྃͨ͠Βɺϩάʹॻ͖ग़͢

    View full-size slide

  10. public function __invoke(
    FulltextRequest $request
    ): RedirectResponse {
    // ొ࿥ॲཧޙʹevent
    try {
    $entity = new Entity(1, ‘testing’);
    $this->dispatcher->dispatch(
    new SinkConnect($this->usecase->run($entity))
    );
    } catch(\RuntimeException $e) {
    // Կ͔errorॲཧ
    }
    return $this->redirector->route('fulltext.index');
    }

    View full-size slide

  11. Domain Event

    View full-size slide

  12. Event
    • υϝΠϯϞσϧ಺Ͱൃੜ͢Δग़དྷࣄ / υϝΠϯΠϕϯτ
    • ʙͨ࣌͠ʹɺʙ͢Δ Λදݱ͢Δ
    • υϝΠϯϞσϧΛލΔ΋ͷʹ஫໨͢Δ
    • ۀ຿తͳ؍఺͔ΒΠϕϯτͱͯ͠ѻ͏͔

    ܦաΛແࢹ͢΂͖͔Ͳ͏͔ͳͲ

    View full-size slide

  13. Domain Event + Observer in PHP

    View full-size slide

  14. ҰͭͷPHPΞϓϦέʔγϣϯͷ৔߹
    • υϝΠϯϞσϧ಺ͷग़དྷࣄΛ

    ObserverΛ࢖࣮ͬͯ૷͢Δ
    • ΞϓϦέʔγϣϯͷΫϥε͕ංେԽͨ࣌͠

    খ͞ͳΫϥεʹ෼ׂ͢Δ৔߹΍ɺ

    ϦϑΝΫλϦϯάʹར༻͢Δ͜ͱ΋

    • ୯ҰͷΞϓϦέʔγϣϯ಺Ͱ࣮૷͢Δ৔߹ʹ༗༻

    (1ϓϩηεΏ͑)

    View full-size slide

  15. ߟྀ͢Δ͜ͱ
    • ϚΠΫϩαʔϏεͰ࿈ܞ͢Δ৔߹͸Ͳ͏͢΂͖͔
    • ʙͨ࣌͠ʹɺʙ͢Δ

    ଞͷΞϓϦέʔγϣϯɾݴޠͰ࣮ߦ͞ΕΔ͔

    ੾Γग़͢ඞཁ͕͋Δ͔Ͳ͏͔

    View full-size slide

  16. ߟྀ͢Δ͜ͱ
    • ෳ਺ͷΞϓϦέʔγϣϯͱ࿈ܞͨ͠৔߹ͷো֐෮چ

    ϩάΛग़ྗ͍ͯ͠Δ͚ͩͰࡁΉ͔Ͳ͏͔
    • ݁ՌΛσʔλϕʔεʹอଘ͠ɺ

    ΞϓϦέʔγϣϯͷσʔλͱͯ͠׆༻

    ݁ՌʹࢸΔ·Ͱͷաఔ͸ඞཁ͔Ͳ͏͔
    • ཤྺσʔλอଘ͚ͩͰࡁΉ͔Ͳ͏͔

    View full-size slide

  17. ݎ͘ɺͦͯ͠ো֐ʹ΋ڧ͍
    ΞϓϦέʔγϣϯʹ͠ͳ͚Ε͹ͳΒͳ͍

    View full-size slide

  18. Event Sourcing

    View full-size slide

  19. Event Sourcing
    • ΠϕϯτΛه࿥ͯ͠࠶ݱ͢Δύλʔϯ
    • ΠϕϯτΛΠϕϯτετΞʹอଘ
    • ه࿥͞ΕͨΠϕϯτ͔ΒΦϒδΣΫτΛ෮ݩͰ͖Δ
    • ΠϕϯτʴϩάʴΦϒδΣΫτɺΠϕϯτ͸ෆม
    • ൃੜͨ͠ࣄ࣮Λ఻͑Δ

    View full-size slide

  20. Event SourcingΛಋೖ͢΂͖Ͱ͸ͳ͍৔߹
    • ΠϕϯτΛه࿥ͯ͠࠶ݱ͢Δඞཁ͕ͳ͍৔߹
    • ه࿥͞ΕͨΠϕϯτ͔Β

    ΦϒδΣΫτΛ෮ݩ͢Δ͜ͱ͕ͳ͍৔߹
    • খن໛ͳΞϓϦέʔγϣϯɺ

    γϯϓϧͳCRUD͔͠ͳ͍ΞϓϦέʔγϣϯ
    • ࢀরΑΓ΋ॻ͖ࠐΈ͕ϝΠϯͷΞϓϦέʔγϣϯ

    View full-size slide

  21. Event Sourcing
    • PHPͰͲ͏΍࣮ͬͯ૷͢Δ͔ʁ
    • RDBMSͱ૊Έ߹ΘͤͯશͯͷΠϕϯτ৘ใΛอ؅ʁ
    • େن໛ͳσʔλʹ͸ରԠͰ͖Δ͔ʁ
    • ר͖໭͠ͷॲཧ͸Ͳ͏͢Δ͔ʁ

    View full-size slide

  22. Asynchronous / Synchronous Event

    View full-size slide

  23. ಉظΠϕϯτ
    • Πϕϯτ͸ಉظॲཧͰ͋Δ΂͖͔Ͳ͏͔

    Πϕϯτൃੜ࣌ʹଈ࠲ʹଞΞϓϦέʔγϣϯʹ൓ө͢Δ
    ඞཁ͕͋Δ͔
    • ΠϕϯτൃߦɺΠϕϯτཤྺอ࣋ɺ

    αϒεΫϥΠόʹΑΔσʔλӬଓԽΛߦ͏

    View full-size slide

  24. ඇಉظΠϕϯτ
    • Πϕϯτ͸ඇಉظʹͰ͖Δ͔Ͳ͏͔

    Πϕϯτ͕ൃੜͨ͜͠ͱΛ୲อ͠ɺ

    ଞΞϓϦέʔγϣϯ΁ͷ൓ө͸஗Ԇͤͯ͞΋Α͍͔
    • ΠϕϯτൃߦɺΠϕϯτཤྺอ࣋·Ͱ

    σʔλӬଓԽ͸஗ԆͰ࣮ߦ͞ΕΔ

    (χΞϦΞϧλΠϜఔ౓)

    View full-size slide

  25. ΞϓϦέʔγϣϯͷ੒௕Ͱൃੜ͢Δ໰୊
    • σʔλϞσϧͱύϑΥʔϚϯε
    • αʔϏε੒௕ͱڞʹ૿͑ΔෳࡶͳΫΤϦͱ૿͑Δ༰ྔ
    • σʔλͷਖ਼͠͞(ਖ਼نԽ)͔ޮ཰Խ͔(ඇਖ਼نԽ)
    • RDBMSͷෆಘҙ෼໺ + NoSQLʹΑΔΧόʔ

    ಉظํ๏ͷෳࡶԽ

    View full-size slide

  26. σʔλϕʔεઃܭͷ೰Έ
    • ਖ਼نԽͱநग़͍ͨ͠σʔλͷΪϟοϓ
    • நग़͍ͨ͠σʔλʹ߹ΘͤͨઃܭΛ͢Δ͜ͱʹΑΔ

    ੍໿͕͔͚ΒΕͳ͍δϨϯϚ
    • ࣮૷ίʔυͰ୲อ͢ΔͨΊʹෳࡶԽ
    • ಛఆͷσʔλϕʔεʹରͯ͠ͷCRUDʹґଘͨ͠ߟ͑

    View full-size slide

  27. ਖ਼نԽ͸͢΂͖ʂ

    View full-size slide

  28. ϏδωεཁٻʹରԠ͢ΔͨΊʹ

    σʔλϕʔεͰશͯରԠ͢Δͷ͸ਖ਼͍͔͠
    ਖ਼نԽɺඇਖ਼نԽ͸

    ಉ࣠͡Ͱߟ͑Δ΂͖Ͱ͸ͳ͍

    View full-size slide

  29. Ϗδωεཁٻ
    γεςϜ౎߹(ϑϨʔϜϫʔΫͳͲ)
    Ϋϥεઃܭ
    γϯϓϧ͞
    ύϑΥʔϚϯε

    View full-size slide

  30. CQRS
    "A few myths about CQRS". Ouarzy's Blog. 

    http://www.ouarzy.com/2016/10/02/a-few-myths-about-cqrs/ ࢀর

    View full-size slide

  31. CQRSͱ͸Կ͔
    • ॻ͖ࠐΈ(෭࡞༻͋Γ)ͱ

    ಡΈࠐΈ(෭࡞༻ͳ͠)Λ෼཭͢Δ
    • ෭࡞༻͋Γ͸σʔλͳͲʹԿΒ͔ͷมߋΛ༩͑Δ΋ͷ

    • ॻ͖ࠐΈ => Command

    • ಡΈࠐΈ => Query

    View full-size slide

  32. CQRS
    • ͋ΒΏΔϝιου͸ɺΞΫγϣϯΛ࣮ߦ͢ΔίϚϯυ
    ͔ɺݺͼग़͠ݩʹσʔλΛฦ͢ΫΤϦ͔ͷ͍ͣΕ͔Ͱ
    ͋ͬͯɺ྆ํΛߦͬͯ͸ͳΒͳ͍ɻ͜Ε͸ɺ࣭໰Λ͢Δ
    ͜ͱͰճ౴ΛมԽͤͯ͞͸ͳΒͳ͍ͱ͍͏͜ͱͩɻ


    "Greg YoungྲྀCQRS - Mark Nijhof". Digital Romanticism. 

    http://d.hatena.ne.jp/digitalsoul/20100712/1278886009 ࢀর 


    View full-size slide

  33. Command
    • ੔߹ੑ

    ੍໿Λ͔͚ͯਖ਼͘͠ɺݎ͘
    • ॻ͖ࠐΈɺߋ৽ɺ࡟আॲཧ͸

    ಡΈࠐΈʹൺ΂ͯޮ཰ੑ΍଎౓ɺ

    εέʔϥϏϦςΟΛҙࣝ͢Δ͜ͱ͸͋·Γͳ͍

    View full-size slide

  34. Query
    • ੔߹ੑΑΓ΋ݕࡧޮ཰
    • ΄ͱΜͲͷΞϓϦέʔγϣϯʹ͓͍ͯɺ

    ॻ͖ࠐΈΑΓ΋ݕࡧͷൺॏ͕େ͖͍͜ͱ͕΄ͱΜͲ
    • εέʔϧ͕༰қͰ͋Δ͜ͱɺ

    ߴ଎ͳύϑΥʔϚϯεͰ͋Δ͜ͱ

    View full-size slide

  35. PHPΞϓϦέʔγϣϯ޲͚

    Command, Query෼཭࣌ͷσʔλϕʔε

    View full-size slide

  36. CQRS Application
    Application

    View full-size slide

  37. ཧ۶͸Θ͔Δ͚Ͳɺ
    Ͳ͏࣮૷͢Ε͹͍͍ͷ͔ʁ
    ಉظ͸Ͳ͏͢Δͷʁ

    View full-size slide

  38. Event Sourcing + CQRS

    View full-size slide

  39. Event Sourcing / Command
    Event
    Application
    Command
    RDBMS

    View full-size slide

  40. Event Sourcing / Command
    Event
    Application
    Command
    RDBMS
    ΞϓϦέʔγϣϯ͔Β
    ॻ͖ࠐΈࢦࣔ(class)

    View full-size slide

  41. Event Sourcing / Command
    Event
    Application
    Command
    RDBMS
    ΞϓϦέʔγϣϯ͔Β
    ॻ͖ࠐΈࢦࣔ(class)
    σʔλϕʔεʹinsert

    View full-size slide

  42. Event Sourcing / Command
    Event
    Application
    Command
    RDBMS
    ΞϓϦέʔγϣϯ͔Β
    ॻ͖ࠐΈࢦࣔ(class)
    σʔλϕʔεʹinsert
    ਖ਼ৗʹॻ͖ࠐ·Εͨ
    ࣄ࣮Λฦ٫

    View full-size slide

  43. Event Sourcing / Command
    Event
    Application
    Command
    RDBMS
    ΞϓϦέʔγϣϯ͔Β
    ॻ͖ࠐΈࢦࣔ(class)
    σʔλϕʔεʹinsert
    ਖ਼ৗʹॻ͖ࠐ·Εͨ
    ࣄ࣮Λฦ٫ ࣄ࣮ʹج͍ͮͨ

    ΠϕϯτΛൃߦ

    View full-size slide

  44. Event Sourcing / Command
    Event
    Application
    Command
    RDBMS
    Transaction

    View full-size slide

  45. Event Sourcing / Query
    Event / Listener
    Application
    NoSQL
    Query

    View full-size slide

  46. Event Sourcing / Query
    Event / Listener
    Application
    NoSQL
    Query
    EventͷൃߦΛݕ஌͠
    NoSQLʹσʔλΛૠೖ

    View full-size slide

  47. Event Sourcing / Queryྫ
    Event / Listener
    Application
    NoSQL
    Query
    EventͷൃߦΛݕ஌͠
    NoSQLʹσʔλΛૠೖ
    Application͔ΒQuery

    நग़໰͍߹Θͤ

    View full-size slide

  48. Event Sourcing / Query
    Event / Listener
    Application
    NoSQL
    Query
    EventͷൃߦΛݕ஌͠
    NoSQLʹσʔλΛૠೖ
    Application͔ΒQuery

    நग़໰͍߹Θͤ
    NoSQLʹ໰͍߹Θͤ
    υϝΠϯʹ࠷దԽ͞Εͨ΋ͷΛظ଴

    View full-size slide

  49. Event Sourcing / Query
    Event / Listener
    Application
    NoSQL
    Query
    EventͷൃߦΛݕ஌͠
    NoSQLʹσʔλΛૠೖ
    Application͔ΒQuery

    நग़໰͍߹Θͤ
    NoSQLʹ໰͍߹Θͤ
    υϝΠϯʹ࠷దԽ͞Εͨ΋ͷΛظ଴
    ݁ՌΛฦ͢ͷΈ

    View full-size slide

  50. Cache System
    σʔλϕʔεߋ৽

    $PNNBOE
    σʔλϕʔεߋ৽׬ྃΠϕϯτ

    &WFOU4PVSDJOH

    σʔλϕʔεߋ৽׬ྃݕ஌

    &WFOU-JTUFOFS

    Ωϟογϡ࡟আͳͲ

    View full-size slide

  51. Structure
    Event Publisher
    Command
    Query
    Event Subscriber

    View full-size slide

  52. Structure
    Event Publisher
    Command
    Query
    Event Subscriber
    ੹຿͸ॻ͖ࠐΈͷΈ

    View full-size slide

  53. Structure
    Event Publisher
    Command
    Query
    Event Subscriber
    ੹຿͸ॻ͖ࠐΈͷΈ
    ੹຿͸ಡΈࠐΈͷΈ

    View full-size slide

  54. Structure
    Event Publisher
    Command
    Query
    Event Subscriber
    ੹຿͸ॻ͖ࠐΈͷΈ
    ੹຿͸ಡΈࠐΈͷΈ
    ੹຿͸Eventૹ৴ͷΈ

    View full-size slide

  55. Structure
    Event Publisher
    Command
    Query
    Event Subscriber
    ੹຿͸ॻ͖ࠐΈͷΈ
    ੹຿͸ಡΈࠐΈͷΈ
    ੹຿͸Eventૹ৴ͷΈ
    ੹຿͸Eventड৴ͱ

    ॻ͖ࠐΈ

    View full-size slide

  56. Event Sourcing
    • CommandɺQueryɺEvent Sourcing͸

    ผΞϓϦέʔγϣϯɾݴޠͰ࣮૷Ͱ͖Δ͘Β͍ͷ

    γϯϓϧ͞
    • EventอଘͱυϝΠϯʹରԠͨ͠QueryΛͲ͏΍ͬͯ

    ޮ཰తʹ࣮૷͢Δ͔

    View full-size slide

  57. ΞϓϦέʔγϣϯ෼ׂྫ

    View full-size slide

  58. ΞϓϦέʔγϣϯ෼ׂྫ
    PHP WebΞϓϦέʔγϣϯ
    webΞϓϦ։ൃνʔϜ

    View full-size slide

  59. ΞϓϦέʔγϣϯ෼ׂྫ
    PHP WebΞϓϦέʔγϣϯ
    webΞϓϦ։ൃνʔϜ
    ूܭॲཧ push etc
    CLI։ൃνʔϜ / DWH etc

    View full-size slide

  60. ΞϓϦέʔγϣϯ෼ׂྫ
    PHP WebΞϓϦέʔγϣϯ
    webΞϓϦ։ൃνʔϜ
    ूܭॲཧ push etc
    CLI։ൃνʔϜ / DWH etc
    ޿ࠂ഑৴ܥAPI
    ޿ࠂ഑৴։ൃνʔϜ

    View full-size slide

  61. ΞϓϦέʔγϣϯ෼ׂྫ
    PHP WebΞϓϦέʔγϣϯ
    webΞϓϦ։ൃνʔϜ
    ूܭॲཧ push etc
    CLI։ൃνʔϜ / DWH etc
    ޿ࠂ഑৴ܥAPI
    ޿ࠂ഑৴։ൃνʔϜ
    ϢʔβʔͷӾཡ৘ใʹج͍ͮͨ
    ৘ใ͕ཉ͍͠Ͱ͢
    ϦΞϧλΠϜͰ

    View full-size slide

  62. Event Sourcing / Message Broker

    View full-size slide

  63. Event SourcingͱMiddlewareબఆ
    • PubSubͰشൃੑͷͳ͍΋ͷΛબ୒͢Δ
    • ϝοηʔδอ؅͕ՄೳͰɺ࠶ݱ͢Δ͜ͱ͕Մೳͳ΋ͷ
    Λ࠾༻͢Δͷ͕๬·͍͠
    • εέʔϥϒϧͰ͋Δ͜ͱ

    View full-size slide

  64. Event Sourcing / RDBMS
    • PubSubͰشൃੑͷͳ͍΋ͷΛબ୒͢Δ

    ͦΜͳػೳ͸ͳ͍ͷͰόονॲཧͳͲͰ

    ఆظతʹσʔλ௥Ճ͕͋Δ͔Ͳ͏͔Λݕࡧ͢Δ

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

    ಘҙ෼໺
    • εέʔϥϒϧͰ͋Δ͜ͱ

    SlaveͳͲΛ૿΍͢͜ͱͰରԠ͸Ͱ͖Δ

    View full-size slide

  65. Event Sourcing / Redis
    • PubSubͰشൃੑͷͳ͍΋ͷΛબ୒͢Δ

    PUBLISH SUBSCRIBEͳͲ͕͋ΔͷͰ࣮ݱ͸Ͱ͖Δ͕ɺ

    شൃੑʹ͍ͭͯ͸ઃఆͰؤுΔ

    • ϝοηʔδอ؅͕ՄೳͰɺ

    ࠶ݱ͢Δ͜ͱ͕Մೳͳ΋ͷΛ࠾༻͢Δͷ͕๬·͍͠

    ͋·ΓಘҙͰ͸ͳ͍(τϥϯβΫγϣϯͳ͠)
    • εέʔϥϒϧͰ͋Δ͜ͱ

    ༰қʹͰ͖Δ

    View full-size slide

  66. Message Broker

    View full-size slide

  67. Apache Kafka
    • ZookeeperΛར༻ͨ͠ΫϥελϦϯάʹΑΔߴՄ༻ੑ
    • ϝοηʔδͷӬଓԽɺϨϓϦέʔγϣϯɺ࠶औಘՄ
    • ϏοάσʔλରԠ
    • ετϦʔϜରԠͷϝοηʔδϯάϛυϧ΢ΣΞ
    • Kafka ConnectʹΑΔपลγεςϜͱͷߴ͍਌࿨ੑ

    (Amazon kinesisͱ΄΅ಉ͡)

    View full-size slide

  68. Event Sourcing
    • ΠϕϯτΛΠϕϯτετΞʹอଘ

    Kafkaࣗମʹอଘ͢Δ͜ͱ͕Ͱ͖ɺ

    σʔλϕʔεʹసૹՄೳ
    • ه࿥͞ΕͨΠϕϯτ͔ΒΦϒδΣΫτΛ෮ݩͰ͖Δ

    ॲཧ͞ΕͨΠϕϯτ͸࠶ൃߦՄೳ
    • ΠϕϯτʴϩάʴΦϒδΣΫτɺΠϕϯτ͸ෆม

    ൃߦޙͷΠϕϯτΛॻ͖׵͑Δ͜ͱ͸Ͱ͖ͳ͍
    • ൃੜͨ͠ࣄ࣮Λ఻͑Δ

    τϥϯβΫγϣϯ͋Γ

    View full-size slide

  69. ϝοηʔδͷܽଛʹ͍ͭͯ
    ૹ৴ࣦഊ
    BDLड৴ࣦഊ
    #SPLFSμ΢ϯ
    ϝοηʔδड৴ࣦഊ

    View full-size slide

  70. ϝοηʔδ఻ୡͷอূ
    • At least once semantics

    ॏෳΛڐՄ
    • At most once semantics

    ܽଛΛڐՄ
    • Exactly once semantics

    ॏෳɺ͓ΑͼܽଛΛڐՄ͠ͳ͍


    "Exactly-once Semantics are Possible: Here’s How Kafka Does it". Confluent APACHE KAFKA. 

    https://www.confluent.io/blog/exactly-once-semantics-are-possible-heres-how-apache-kafka-does-it/ ࢀর

    View full-size slide

  71. Performance?

    View full-size slide

  72. Apache Kafka֓ཁ
    • Partition

    ෛՙ෼ࢄ༻్ʹར༻

    ෳ਺ͷConsumer͕ͦΕͧΕͷPartitionΛࢀর͠ɺ

    ͦΕͧΕ͕ॲཧΛߦ͏

    ॲཧϑϩʔͷσβΠϯʹΑͬͯଟ༷ͳར༻ํ๏
    • librdkafka͕ඇৗʹߴ଎

    PHPͰ͸rdkafka(librdkafkaϥοϓ)

    View full-size slide

  73. Example Partition

    View full-size slide

  74. Performance
    • confluent: 250000 records, 34.84177593s
    • sarama-cluster: 250000 records, 2m20.614963038s

    • confluent was almost 5x faster on the read.

    View full-size slide

  75. Kafka Connect
    • Kafka Connectͱ͸ɺ

    पลγεςϜ͔ΒͷσʔλΛऔΓࠐΈ(Source)ɺ

    σʔλૹ৴(Sink)ͷೋछྨΛαϙʔτ͢Δػೳ
    • Amazon SQS΍MongoDBͷσʔλΛKafkaͰऔࠐΉɺ

    ϝοηʔδΛͦͷ··Elasticsearch΍RDBMSʹ֨ೲɺ

    ͕ߦ͑Δ
    • Connect͸ࣗ༝ʹ֦ுͯ͠ಠࣗConnectΛ࣮૷Մೳ

    View full-size slide

  76. Kafka Connect
    • γϯϓϧͳέʔεͰ͋Ε͹ɺ

    ಛʹ࣮૷͢Δ͜ͱͳ͘QueryΛαϙʔτ
    • Consumer͸ผΞϓϦέʔγϣϯͱͯ͠

    ෼ׂ͢Δͷ΋͍͍Ͱ͠ΐ͏
    • ෳࡶͳσʔλΛ࡞੒͢ΔͷͰ͋Ε͹

    ConsumerͰσʔλΛ૊Έ߹ΘͤΔ

    View full-size slide

  77. Structure
    Event Publisher
    Command
    Query
    Event Subscriber
    Application
    ੹຿͸ಡΈࠐΈͷΈ
    ੹຿͸Eventૹ৴ͷΈ
    WebΞϓϦέʔγϣϯ
    ͔Β੾Γग़͢

    View full-size slide

  78. Event Sourcing+ CQRS / Kafka
    • Command QueryΛ୲౰͢ΔWebΞϓϦέʔγϣϯΛ

    γϯϓϧʹ
    • Event SourcingʹΑͬͯɺΞϓϦέʔγϣϯʹՁ஋Λ௥
    Ճ͢Δ͜ͱ͕Ͱ͖Δ(෼ੳͳͲ)
    • Command QueryͷಉظΛαϙʔτ͠ɺ

    ΞϓϦέʔγϣϯʹ߹Θͤͯෛՙ෼ࢄ͕༰қ

    View full-size slide

  79. ఆظߋ৽ͤ͞Δόονॲཧͷߟ͑ํ΋มΘΔ

    View full-size slide

  80. Example: Produce
    Ϣʔβʔͷ࣌ܥྻߦಈϩά͕
    QIQSELBGLBܦ༝ͰૹΒΕͯ͘Δ

    View full-size slide

  81. Example: Kafka
    "QBDIF,BGLB
    "QBDIF;PPLFFQFS
    QBSUJUJPO
    ϲ݄͘Β͍Ͱԯ͘Β͍

    ΞϓϦέʔγϣϯ΁ͷো֐ɾऔΓ͜΅͠ͳ͠

    View full-size slide

  82. Example: Consume
    σʔλϕʔεΛ݁߹ͯ͠ϏδωεϩδοΫٵऩ
    QVTI௨஌ࢦࣔͳͲΠϕϯτΛૹ৴
    ଞαʔϏε͕SBCCJUNRΛ࢖͍ͬͯΔͨΊ

    View full-size slide

  83. Example: Cassandra
    $BTTBOESB$MVTUFS
    ԯͪΐͬͱ͘Β͍ 55-͋ΓͷͨΊ

    ো֐ͳ͠ɾίϯύΫγϣϯఆظ࣮ߦͰ
    τϥϒϧͳ͠

    View full-size slide

  84. Example: Cassandra
    ͜͜·Ͱ਺NTҎ಺Ͱऴྃ͢ΔͨΊɺ
    ΄΅ϦΞϧλΠϜͰ൓ө͞ΕΔ

    View full-size slide


  85. • ίϯςϯπͷσʔλΛKafkaܦ༝Ͱऩू͠HDFS֨ೲ

    SparkʹΑΔ෼ੳॲཧޙ Cassandra֨ೲ

    ΞϓϦέʔγϣϯ͔Β͸Cassandraʹ

    γϯϓϧͳΫΤϦΛ౤͛ΔͷΈʹ
    • Event Sourcing, CQRSͷ૊Έ߹ΘͤʹΑΓ

    Ωϟογϡੜ੒΍σʔλ࠷దԽʹΑΓߴ଎Խʹߩݙ


    View full-size slide

  86. େࡶ೺ͳαϯϓϧ͸ԼهΛࢀর͍ͩ͘͞

    https://github.com/ytake/laravel-presto-
    kafka-demo

    View full-size slide

  87. ·ͱΊ
    • େن໛ʹͳΔ͜ͱ͕༧ଌͰ͖ͨΒ

    ಋೖʹνϟϨϯδ
    • ҰͭͷϑϨʔϜϫʔΫ͚ͩͰ΍Ζ͏ͱ͠ͳ͍͜ͱ
    • ϛυϧ΢ΣΞͷ஌ࣝ͸ඞཁʹ
    • DDDͷ؍఺͚ͩͰ͸ͳ͘ɺ

    ෼ࢄॲཧ΍ෳࡶͳσʔλॲཧͷ

    ϦϑΝΫλϦϯάʹ΋׆͖Δύλʔϯ

    View full-size slide