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

Microservices Maturity Model on Rails

qsona
March 24, 2018

Microservices Maturity Model on Rails

2018/3/24 Rails Developers Meetup Day 1 / 引用資料のリンクまとめ http://qsona.hatenablog.com/entry/2018/03/26/034451

qsona

March 24, 2018
Tweet

More Decks by qsona

Other Decks in Technology

Transcript

  1. whoami • @qsona • גࣜձࣾFiNC • Microservices Meetup Λओ࠵͠ ͍ͯ·͢

    • Railsྺ3೥໨ʹಥೖ • ϚΠΫϩαʔϏεͱ͍͏બ୒͸ج ຊతʹ͸࠷ߴͱ͍͏ελϯε
  2. Maturity Modelͱ͸ • ੒ख़౓ΛϨϕϧผʹఆٛ ͢Δ • ݱࡏͷঢ়ଶΛධՁ͢Δ
 ΋ͷ͞͠ • ʮ࣍ʹԿΛվળ͢΂͖

    ͔ʯΛཧղ͢Δख͕͔Γ MaturityModel - 
 Martin Fowler
 https://martinfowler.com/bliki/MaturityModel.html
  3. ͜ͷޙͷষߏ੒ • 1.upto(3) do |n| • Lv.n ͷఆٛ (࠶ܝ) •

    Lv.n-1 => Lv.n ʹਐΉͨΊʹ΍Δ͜ͱ (ٕज़࣠/૊৫࣠) • ͜ͷϑΣʔζͰ࣮ࡍʹ͋ͬͨྫ • ͜ͷϑΣʔζʹ͓͢͢Ίͷࢀߟจݙ • end
  4. "தن໛" RailsΛͪΌΜͱ࡞Ε Δ͜ͱ • MVCͷ੹຿Λ෼ׂͰ͖Δ • PORO (PlainͳRubyΫϥε) Λ׆༻Ͱ͖Δ •

    RESTfulΛकΕΔ • ਖ਼نԽͨ͠DBઃܭ͕Ͱ͖Δ • ୯ମςετ͕ॻ͚Δ
  5. ৬ೳΛӽ͑ͯڠྗ͍ͯ͠ͳ͍ྫ • DevͱOpsͷ෼཭ • CSରԠ΁ͷΤϯδχΞ ͷԹ౓ײ͕௿͍ • Ӧۀͱٕज़ऀͷରཱ • ج൫։ൃνʔϜͱݱ৔

    ͱͷߔ • ΫϥΠΞϯτνʔϜͱ APIνʔϜͷ෼཭ • ඼࣭؅ཧνʔϜ΁ͷ
 ؙ౤͛ • ݚڀ։ൃ͕͍ͭʹͳͬ ͯ΋Ϣʔβ΁ͷՁ஋Λ ࢈Έग़͞ͳ͍
  6. API͸ϚΠΫϩαʔϏεͷ໋ • APIΛ௨ͯ͠࿈ܞ͢Δ͜ͱʹΑΓɺαʔϏεͷࣗ཯ੑ͕ੜ·ΕΔ • Jeff Bezosͷݴ༿ • શͯͷνʔϜ͸αʔϏεΠϯλʔϑΣΠεΛ௨ͯ͠ػೳΛެ։͠ɺ
 ࿈ܞͤΑ •

    ͦΕҎ֎ͷϓϩηεؒ௨৴ͷํ๏(DB௚ಡΈ, ڞ༗ϝϞϦ, etc)͸ېࢭͰ͋Δ • ͜ΕΛकΒͳ͍ऀ͸ղޏͩ ग़య: The Secret to Amazons Success Internal APIs
 https://apievangelist.com/2012/01/12/the-secret-to-amazons-success-internal-apis/
  7. Rails ͱ API • Rails, RESTfulͷࢦ਑ʹ৐͍ͬͯ͘ͷ͕ྑ͍ • ͜ͷςʔϚͰ͸Ұ౓࿩͍ͯ͠ΔͷͰɺࠓճ͸ ׂѪ͠·͢ ࢀߟ:

    ϚΠΫϩαʔϏεࢦ޲ Rails API ։ൃΨΠυ
 (@qsona, ͗Μ͟Rubyձٞ01)
 https://medium.com/finc-engineering/ginzaruby01-rails-api-guide-168fe9cf5b4d
  8. APIΫϥΠΞϯτͷબఆ • ੜ͖ͯΕ͹ͳΜͰ΋ྑ͍ • Faraday ͕͓͢͢Ί • ෳ਺ͷAPIΛฒྻʹୟ͘༨஍Λ࢒͢ • όοΫΤϯυʹTyphoeusΛར༻

    • cookpadͷࣄྫ͸͓͓͑ͯ͜͞͏ RESTful Web API ։ൃΛ͑͞͞Δ Garage - ΫοΫύου։ൃऀϒϩά
 http://techlife.cookpad.com/entry/2014/11/06/100000
  9. ৽͍͠૚Λ࡞Δ: Repository • ͓͢͢Ί: app/repositories • app/models ҎԼ͸ආ͚Δ • ωοτϫʔΫӽ͠ͷΞΫηε͸ɺ


    DBΞΫηεͱ͸શ͘ผ෺ • ActiveRecordͱಉ͡งғؾͰݺͼग़ͤͳ͍΄͏͕Α͍ • (ActiveResource͸๨ΕΑ͏)
  10. ͩΊͳྫ class User include ActiveModel::Model attr_accessor :id, :name, :age end

    class UserRepository def self.get(id) response = api_client.get("/v1/users/#{id}") return nil if response.status == 404 raise 'Error' unless response.success? # response.body # => { 'id' => 1, 'name' => 'qsona', 'age' => 17 } User.new(response.body) end end
  11. ͩΊͳཧ༝ • APIͷϨεϙϯεʹ৽͘͠ gender Ωʔ͕௥Ճ ͞ΕΔͱ? # response.body # =>

    { 'id' => 1, 'name' => 'qsona', 'age' => 17, 'gender' => female } User.new(response.body) #=> ActiveModel::UnknownAttributeError: unknown attribute 'gender' for User.
  12. मਖ਼ͨ͠ྫ # response.body # => { 'id' => 1, 'name'

    => 'qsona', 'age' => 17 } # User.new(response.body) # => ͜͜Λमਖ਼ body = response.body User.new(id: body['id'], name: body['name'], age: body['age'])
  13. Repositoryͷςετ • Repositoryࣗମͷςετ • ྫ: bblimke/webmock Λར༻͢Δ • ͜ΕΛॻ͍͓ͯ͘ͱɺܨ͗ࠐΈͷ֬౓͕͙ͬͱ্͕Δ •

    RepositoryΛར༻͢Δίʔυͷςετ • webmock Λ࢖͏ͷͰ͸ͳ͘ɺ
 RepositoryΛmock/stub͢ΔͷΛਪ঑
  14. ϚΠΫϩαʔϏεͱΦʔφʔγοϓ • ࠷ॳ͸1νʔϜͰෳ਺ͷαʔϏεΛ؅ཧͯ͠΋Α͍ • খͯ͘͞΋ࣗ཯ͨ͠ʮαʔϏεʯͰ͋Δ • αʔϏεͷΦʔφʔΛܾΊ͓͍ͯͨ΄͏͕Α͍ • ੹೚ͱݖݶͷ໌֬Խ •

    ٕज़ऀͷ੒௕ʹͭͳ͕ΔϝϦοτ "ϚΠΫϩαʔϏεͰ͸ͦΕͧΕಠཱͨ͠ϥΠϑαΠΫϧΛ࣋ͭෳ਺ͷࣗ཯తͳίʔυϕʔε͕͋Γ· ͢ɻଟ͘ͷ੹೚ΛҾ͖ड͚ΔલʹݸʑͷαʔϏεΛॴ༗ͤ͞Δ͜ͱͰ։ൃऀͨͪΛ޲্ͤ͞Δ͜ͱ͸ɺ ֤ࣗͷΩϟϦΞ໨ඪΛ࣮ݱͤ͞ΔͨΊͷ༏Εͨํ๏Ͱ͋Γɺಉ࣌ʹ੹೚ऀͷෛՙΛܰݮ͠·͢ɻ" - ϚΠΫϩαʔϏεΞʔΩςΫνϟ 2.10 νʔϜͷߏங
  15. ػցֶशαʔϏεͷۙگ • طଘͷ "ػցֶशαʔϏε" ͸ɺঃʑʹղମ • ػցֶशͷεΫϦϓτ͸ɺঃʑʹҠߦ/࡟আ • ࡞Γ௚͠΋͍ͯ͠Δ (߲࣍)

    • νϟοτϘοτ͸ɺϝΠϯͷϏδωεͱͯ͠ӡ༻த • ࣦഊ͸ඞͣ͋Δ • ݁Ռ͚ͩΛݟͯݴ͏ͷ͸؆୯ • ͭΒ͍͜ͱ΋͋Δ͚Ͳ΍͍͖ͬͯ
  16. ػցֶशΛ৽͘͠ϓϩμΫτʹ ಋೖ͢Δͱ͖͸ • ػցֶश͸ɺαʔϏεͷҰ෦ͱͱΒ͑Δ • ػցֶश୯ମͰͷϚΠΫϩαʔϏεԽ͸ߦΘͳ͍ • ن໛ײɾಈ࡞ͷॏ͞ʹΑΓɺ݁߹౓Λௐ੔͢Δ • খ͍͞

    => RailsͷαʔϏεʹεΫϦϓτΛಉډ • େ͖͍ => αʔϏεͷࢠϓϩμΫτͱͯ͠ಠཱ • αʔϏεͷΤϯδχΞͱػցֶशͷΤϯδχΞ͕ີʹ࿈ܞͯ͠ɺ ϓϩδΣΫτΛਐΊ͍ͯΔ
  17. E2Eςετ͸ෆཁ͔? • ޡղΛڪΕͣʹݴ͑͹... ͜ͷϑΣʔζͰ͸ʮෆཁʯ • ҎԼΛ͖ͪΜͱߦ͑͹ɺܨ͗ࠐΈ͸΄΅ҰൃͰ׬ྃ͢Δ • APIઃܭɺαʔϏεؒ࿈ܞͷઃܭ • (Provider)

    APIܕఆٛ/υΩϡϝϯτੜ੒/αʔϏε୯ମͷςετ • (Consumer) Repositoryͷςετ • E2Eςετʹ͸σϝϦοτ͕ଟ͍
  18. ࣾ಺Gemʹؔ͢Δ͍͍࿩2ͭ • Ϋϩʔζυιʔε͔Β࢝ΊΔΦʔϓϯιʔε
 2017-05-23 Speee Cafe Meetup #07 େ஥ ೳ࢙

    a.k.a. @onk
 https://www.slideshare.net/takafumionaka/ss-76268823 • ApplicationTemplateͷεεϝ
 2017-08-06 ͗Μ͟ Ruby ձٞ 01 େ஥ ೳ࢙ a.k.a. @onk
 https://www.slideshare.net/takafumionaka/applicationtemplate
  19. ࠓճ͸2Λબ୒ (͢Δ༧ఆ) • UI͸ɺ͋Δఔ౓੾Γ཭͞Ε͍ͯͯ΋໰୊ͳ͍ • ผͷURLυϝΠϯͰఏڙ • Single Sign-onͰମݧΛγʔϜϨεʹ͢Δ •

    ϚΠΫϩαʔϏεͷϝϦοτΛ༏ઌ • ஫: ϢʔβମݧΑΓٕज़Λ༏ઌ͍ͯ͠Δɺͱ͍͏Θ͚Ͱ͸ͳ͍ • γʔϜϨεͳϢʔβମݧΑΓ΋ɺߴ଎ʹPDCAΛճͯ͠Ձ஋Λఏڙ͠ ͍ͯ͘ํʹॏ͖Λ͓͍͍ͯΔ