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

Scalable Architecture with RabbitMQ

nownabe
November 24, 2015

Scalable Architecture with RabbitMQ

IDCFクラウドのバックエンドをMicroservicesで作って、各コンポーネント間の通信にRabbitMQを使っているという話。

nownabe

November 24, 2015
Tweet

More Decks by nownabe

Other Decks in Technology

Transcript

  1. Scalable
    Architecture
    with RabbitMQ
    IDCϑϩϯςΟΞ UX։ൃ෦ ౉ᬑঘޗ
    2015/11/24

    View full-size slide

  2. Slides’ URI
    https://speakerdeck.com/nownabe/scalable-
    architecture-with-rabbitmq

    View full-size slide

  3. Who?
    ౉ᬑঘޗ
    @nownabe
    Programmer
    Drummer

    View full-size slide

  4. History
    2013೥4݄ IDCFೖࣾ
    2013೥7݄ ΧελϚʔαʔϏεຊ෦ϓϥοτϑΥʔϜαʔϏε෦Ϋϥ΢υάϧʔϓ
    • Ϋϥ΢υج൫ӡ༻ɾݕূ
    • αόϑΣε্ཱͪ͛
    • MBaaSαʔϏε։ൃ
    2014೥4݄ ٕज़։ൃຊ෦R&Dࣨ
    • MBaaSαʔϏε։ൃ
    • RDBαʔϏε։ൃ
    2015೥1݄ ٕज़։ൃຊ෦UX։ൃ෦
    • RDBαʔϏε։ൃ
    • ϩʔυόϥϯαʔαʔϏε։ൃ (now!)

    View full-size slide

  5. Favorites
    Ruby
    Itamae
    Ruboty
    React
    esa
    Daemon Chain Drive (double)
    Aquiles Priester

    View full-size slide

  6. Scalable Architecture
    with RabbitMQ

    View full-size slide

  7. ͸΍Γͷ
    Publish / Subscribe
    ͱ
    Microservices
    ΍ͬͯΈͨ

    View full-size slide

  8. Which service?
    ݱࡏ։ൃத
    IDCF Cloudͷ৽αʔϏε
    ϩʔυόϥϯαʔαʔϏεͷόοΫΤϯυ
    ͦΖͦΖʁϦϦʔε༧ఆ

    View full-size slide

  9. What service?
    7. 7. 7.

    4DBMBCMF
    #BDLFOE -# -#

    *%$'$MPVE $MPVE4UBDL

    ࡞ͬͨΓফͨ͠Γ
    ૿΍ͨ͠ΓݮΒͨ͠Γ
    ؂ࢹͨ͠Γम෮ͨ͠Γ

    View full-size slide

  10. 8PSLFS …
    $POUSPMMFS …
    "1*

    .POJUPS

    -#OPEF
    -#OPEF
    ………
    Scalable architecture

    View full-size slide

  11. 8PSLFS …
    $POUSPMMFS …
    "1*

    .POJUPS

    -#OPEF
    -#OPEF
    ………
    Scalable architecture
    3&45"1*ड͚Δ΍ͭ
    ؂ࢹɾ՝ۚ͢Δ΍ͭ
    ࡞ͬͨΓফͨ͠Γ͢Δ΍ͭ
    ϩʔυόϥϯαʔຊମ
    ͍Ζ͍Ζ΍Δ΍ͭ

    View full-size slide

  12. Development style
    Ruby
    Github
    Qiita:Team
    Slack

    View full-size slide

  13. Today’s topics
    ࿩͢
    RabbitMQ (Publish / Subscribe)
    Microservices
    ࿩͞ͳ͍
    RabbitMQͷෛՙ෼ࢄ/৑௕Խ
    Monitoring (Sensu)

    View full-size slide

  14. What is RabbitMQ?
    ϝοηʔδͷड৴ͱ഑৴
    Advanced Message Queuing Protocol
    OSS࣮૷
    Erlang

    View full-size slide

  15. Why RabbitMQ?
    MicroservicesԽͰશ෦REST API͸͖͍ͭ
    ߴػೳ
    ୯ମͰಈ࡞͢Δ
    υΩϡϝϯτ͕ॆ࣮ͯͨ͠

    View full-size slide

  16. Publish / Subscribe



    Producer (Publisher)
    Queueʹ഑৴
    Consumer (Subscriber)
    Queue͔Βߪಡ
    Queue
    ✉ ✉ ✉
    ✉ ✉





    View full-size slide

  17. Exchange
    ϝοηʔδΛQueueʹ഑ୡ͢Δਓ
    ͍ͭ͜ͷ͓͔͛Ͱ഑৴ܦ࿏͕ॊೈ

    View full-size slide

  18. Example: Fanout



    ✉ ✉ ✉


    &YDIBOHF

    ඥͮ͘͢΂ͯͷ
    Queueʹ഑ୡ

    View full-size slide

  19. Example: Roundrobin




    &YDIBOHF

    ✉ ✉


    ʮՋͳਓʹ഑৴ʯ΋Մ

    View full-size slide

  20. Example: RPC




    Request/Response
    (Exchange͸লུ)
    ฦ৴༻Queue

    View full-size slide

  21. More complecated routings
    ͔ͳΓෳࡶͳϧʔςΟϯά΋Մೳ

    View full-size slide

  22. Microservices

    View full-size slide

  23. 8PSLFS …
    $POUSPMMFS …
    "1*

    .POJUPS

    -#OPEF
    -#OPEF
    ………
    Components
    3&45"1*ड͚Δ΍ͭ
    ؂ࢹɾ՝ۚ͢Δ΍ͭ
    ࡞ͬͨΓফͨ͠Γ͢Δ΍ͭ
    ϩʔυόϥϯαʔຊମ
    ͍Ζ͍Ζ΍Δ΍ͭ

    View full-size slide

  24. Why microservices?
    ScalableͳઃܭΛٻΊΒΕͨ
    • CloudStack͕ҰຕؠͰεέʔϧ͠ʹ͍͘ઃܭ
    ֤ίϯϙʔωϯτͷ໾ׂ෼ׂ͕໌֬ͩͬͨ
    • ͋Δఔ౓Ͳ͏෼͚Ε͹͏·͍͖ͦ͘͏͔෼͔͍ͬͯͨ
    ΞδϟΠϧʹ׳Ε͍ͯͳ͍
    • ΢ΥʔλʔϑΥʔϧͬΆ͘ॎׂΓ։ൃ

    View full-size slide

  25. Our
    Microservices

    View full-size slide

  26. API gateway
    ֎෦ϦΫΤετΛ࠷ॳʹॲཧ͢Δड෇৖
    REST APIΛఏڙ
    Ϣʔβͷೝূ౳
    ControllerʹϦΫΤετΛ఻͑Δ

    View full-size slide

  27. Controller
    ͍Ζ͍Ζ൑அͯ͠ࢦࣔΛग़͢Ϙε
    ϝΠϯDBͱ΍ΓͱΓͰ͖Δ

    View full-size slide

  28. Worker
    ࣮ࡍʹಇ͘࿑ಇऀ
    Controller͔ΒͷࢦࣔͰಇ͘
    ඇಉظͰ͕͔͔࣌ؒΔॲཧΛ͜ͳ͢
    ऴΘͬͨΒControllerʹใࠂ

    View full-size slide

  29. Node agent
    LB nodeʹજΉΤʔδΣϯτ
    LB nodeͷॳظઃఆ
    Worker͔ΒͷࢦࣔͰίϚϯυΛ࣮ߦ
    ֤छϝτϦΫεΛMonitorʹใࠂ

    View full-size slide

  30. Monitor
    ؂ࢹ΍՝ۚॲཧΛߦ͏ݟுΓ໾
    Agent͔ΒͷϝτϦΫεΛूܭ
    Կ͔͋Ε͹Controllerʹใࠂ

    View full-size slide

  31. Via RabbitMQ
    શίϯϙʔωϯτ͕RabbitMQܦ༝Ͱ΍ΓͱΓ
    8PSLFS
    $POUSPMMFS /PEFBHFOU
    ࢦࣔ
    ࢦࣔ/ใࠂ
    ใࠂ
    ඇಉظ ಉظ

    View full-size slide

  32. Scalable!
    εέʔϧΞ΢τ͕؆୯
    • ৽͍͠ίϯϙʔωϯτ͕ͭͳ͗ʹ͍͚ͩ͘
    RabbitMQ͕ϘτϧωοΫʹͳΓಘΔʁ
    • ͠͹Β͘৺഑ͳͦ͞͏

    View full-size slide

  33. RabbitMQ is nice
    ϧʔςΟϯά͕ॊೈ
    ͱͯ΋ָ: Pub/Sub΍ඇಉظॲཧ
    ͱͯ΋ָ: ෛՙ෼ࢄ
    • Producer/Consumer͸ࣗ෼Ͱͭͳ͗ʹ͘Δ
    • LBͰ෼ࢄ͠Α͏ͱ͢Δͱ…

    View full-size slide

  34. Nice microservices
    ྑ͍ײ͡ʹίϯϙʔωϯτ෼ׂͰ͖ͨ
    • ໾ׂ΍ෛՙ
    ֤୲౰ऀͰҰؾʹฒߦ։ൃͰ͖ͨ
    1୆ڞ௨ͷRabbitMQ͕͋Ε͹݁߹ςετ΋؆୯
    • ϩʔΧϧͱϩʔΧϧΛ؆୯ʹͭͳ͛Δ

    View full-size slide

  35. Sensu
    ·͞ʹΫϥ΢υ࣌୅ͷ؂ࢹπʔϧ
    ͍ͭ͜΋RabbitMQΛ࢖͏
    Pub/SubͰ؂ࢹ

    View full-size slide

  36. Bad microservices
    ͏·͘Θ͚ΒΕͳ͔ͬͨ෦෼΋
    • MonitorͱControllerͰಉ͡DBΈͯΔ
    ίϯϙʔωϯτԣஅͰΈΔͱDRY͡Όͳ͍
    ΠϯϑϥίετͰ͔͍
    • ࣍͸ίϯςφԽ͍ͨ͠

    View full-size slide

  37. RPC is not good
    RPC͍ͬͺ͍࢖ͬͯΔ
    RabbitMQ͸ຊདྷRPC͢Δ΋ͷ͡Όͳ͍
    ͦΕREST APIͰͰ͖ͳ͍ͷʁ
    • ͸͍ɺͰ͖·͢

    View full-size slide

  38. Insufficient information
    ৘ใ͕গͳ͍
    ެࣜυΩϡϝϯτ͸ॆ࣮
    • ӳޠΦϯϦʔ

    View full-size slide

  39. Summary
    MicroservicesͱPub/SubͰScalableʹʂ✨
    MicroservicesͱPub/Subͷ૬ੑ͸ΠΠʂ
    શ෦RabbitMQܦ༝Ͱ͸ͳ͘దࡐదॴʹʂʂ

    View full-size slide

  40. Thank you
    for your attention
    MicroservicesͱPub/SubͰScalableʹʂ✨
    MicroservicesͱPub/Subͷ૬ੑ͸ΠΠʂ
    શ෦RabbitMQܦ༝Ͱ͸ͳ͘దࡐదॴʹʂʂ

    View full-size slide