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

共通基盤システムの開発について

 共通基盤システムの開発について

http://aiming.connpass.com/event/25004/ での発表資料です

Tsukuru Tanimichi

January 27, 2016
Tweet

More Decks by Tsukuru Tanimichi

Other Decks in Technology

Transcript

  1. ڞ௨ج൫γεςϜͷ։ൃʹ͍ͭͯ
    גࣜձࣾ Aiming
    ιϑτ΢ΣΞΤϯδχΞ
    ୩ಓ ૑
    2016/01/27 Aiming Study #8

    View full-size slide

  2. ࣗݾ঺հ
    • ୩ಓ ૑ (Tsukuru Tanimichi)
    • @ttanimichi
    • Ruby, Java, DevOps
    • 2014/06 ೖࣾ
    • ౷߹ KPI γεςϜͷ։ൃ
    • ڞ௨ج൫γεςϜͷ։ൃ
    • ήʔϜλΠτϧͷ API ։ൃ
    • https://github.com/ttanimichi
    • https://twitter.com/ttanimichi

    View full-size slide

  3. Aiming ͷήʔϜλΠτϧ
    10 λΠτϧ͋Γ·͢

    View full-size slide

  4. ͦΕͧΕͷήʔϜλΠτϧ͕

    View full-size slide

  5. ·ͬͨ͘ผݸͷγεςϜ
    ҟͳΔωοτϫʔΫ

    View full-size slide

  6. ݸʑͷήʔϜ͸ಠཱͨ͠γεςϜ
    ྫ) ͙Δ͙ΔΠʔάϧͷωοτϫʔΫ
    ී௨ͷ Web ΞϓϦέʔγϣϯʹ͔ͳΓ͍ۙߏ੒
    ϩʔυόϥϯα
    app app app
    MySQL Redis

    View full-size slide

  7. ήʔϜλΠτϧΛ࡞Δͨͼʹ
    ຖճඞཁʹͳΔ΍ͭ

    View full-size slide

  8. • ೝূ
    • ՝ۚॲཧ
    • νϟοτ
    • Push ௨஌
    • ૬ޓૹ٬
    • ͳͲͳͲ

    View full-size slide

  9. ॎׂΓͰͦΕͧΕ࣮૷͍ͯͨ͠ɾɾɾ
    • ೝূ
    • ՝ۚॲཧ
    • νϟοτ
    • Push ௨஌
    • ೝূ
    • ՝ۚॲཧ
    • Push ௨஌
    • ೝূ
    • ՝ۚॲཧ
    • νϟοτ
    • Push ௨஌

    View full-size slide

  10. ʊਓਓਓਓਓਓਓਓʊ
    ʼɹंྠͷ࠶ൃ໌ɹʻ
    ʉY^Y^Y^Y^Y^Y^Yʉ

    View full-size slide

  11. • ଞͷήʔϜλΠτϧͷϞδϡʔϧΛίϐϖ
    ͯ͠࡞ͬͯ͠·͍ͬͯΔ৔߹΋͋Δ
    • ιʔείʔυΛಡΜͰ͍ΔͱଞͷήʔϜλ
    ΠτϧͷλΠτϧ໊͕ಥવग़͖ͯͨΓ
    • ͋·Γग़དྷͷྑ͘ͳ͍Ϟδϡʔϧ΍ઃܭ͕
    ίϐϖͰൟ৩͢Δ

    View full-size slide

  12. ͦΕʹՃ͑ͯɺ

    View full-size slide

  13. • ϩετϨΨϦΞ
    • 2015೥10݄22೔ϦϦʔε
    • ӡӦݩ: גࣜձࣾ Aiming
    • ։ൃݩ: Perfect World Co.,Ltd

    View full-size slide

  14. • ϩετϨΨϦΞ
    • 2015೥10݄22೔ϦϦʔε
    • ӡӦݩ: גࣜձࣾ Aiming
    • ։ൃݩ: Perfect World Co.,Ltd

    View full-size slide

  15. • ϩετϨΨϦΞ
    • 2015೥10݄22೔ϦϦʔε
    • ӡӦݩ: גࣜձࣾ Aiming
    • ։ൃݩ: Perfect World Co.,Ltd
    ։ൃݩ͸தࠃͷ Perfect World ࣾ

    View full-size slide

  16. தࠃͷήʔϜλΠτϧΛ
    ೔ຊͰϦϦʔε͢Δ৔߹ɺ
    ೝূͱ՝ۚͷॲཧʹ͍ͭͯ͸
    ͪ͜ΒͰ༻ҙ͢Δඞཁ͕͋Δ

    View full-size slide

  17. Ͳ͏͍͏͜ͱʁ
    • தࠃ͸ GooglePlay Store ͡Όͳ͍
    • தࠃಠࣗͷετΞʹܨ͕ΔΑ͏ʹͳ͍ͬͯΔ
    • ͦͷลͷ࢓૊Έ͸ӡӦݩ͕༻ҙ͢ΔจԽ
    • SNS ΞΧ΢ϯτͱͷඥ෇͚ʢޙड़ʣ
    • Facebook, Twitter ͸தࠃ͔Βܨ͕Βͳ͍
    • άϨʔτϑΝΠΞ΢Υʔϧ

    View full-size slide

  18. ڞ௨ج൫γεςϜ࡞Δͧʂʂ

    View full-size slide

  19. ڞ௨ج൫γεςϜΛ࡞ͬͨܦҢ·ͱΊ
    • ήʔϜλΠτϧؒͰॏෳ͢ΔϞδϡʔϧͷ
    ଟॏ։ൃΛ΍Ί͔ͨͬͨ
    • தࠃͷήʔϜλΠτϧΛ೔ຊͰϦϦʔε

    ͢ΔͨΊʹೝূͱ՝ۚͷॲཧΛ༻ҙ͢Δ

    ඞཁ͕͋ͬͨ

    View full-size slide

  20. ࠓճͷ Scope

    View full-size slide

  21. • ೝূ
    • ՝ۚ
    • νϟοτ
    • Push ௨஌
    • ૬ޓૹ٬
    • ͳͲͳͲ

    View full-size slide

  22. • ೝূ
    • ՝ۚ
    • νϟοτ
    • Push ௨஌
    • ૬ޓૹ٬
    • ͳͲͳͲ
    ← ࡞Γ·ͨ͠
    ← ࡞Γ·ͨ͠

    View full-size slide

  23. ೝূ
    • ΞΧ΢ϯτΛൃߦͰ͖Δ
    • SNS ΞΧ΢ϯτͱඥ෇͚Ͱ͖Δ
    • ػछมߋͳͲΛͨ͠ͱ͖ʹ SNS ΞΧ΢ϯ
    τ͔ΒήʔϜσʔλΛ෮ݩͰ͖Δ

    View full-size slide

  24. ՝ۚ
    • Ϣʔβʔʹੜ೥݄Λೖྗ͍ͤͨ͞
    • ະ੒೥͕՝ۚ͠Α͏ͱͨ͠ͱ͖ʹ͸อޢऀ
    ͷ͓ΏΔ͠ΛಘΔΑ͏ද͍ࣔͨ͠
    • Ϩγʔτͷ verify ͳͲνʔτରࡦ͕͍ͨ͠
    ʢ͍͕ͭ͜Ұ൪େมʂʣ

    View full-size slide

  25. ڞ௨ج൫γεςϜͷ։ൃ

    View full-size slide

  26. ϝϯόʔߏ੒
    • औΓ·ͱΊʢ1໊ʣ
    • αʔόʔʢ1໊ʣ← ࢲ͕୲౰
    • iOSΤϯδχΞʢ1໊ʣ
    • Android ΤϯδχΞʢ1໊ʣ
    ͳͷͰࠓ೔͸αʔόʔͷ࿩Λ͠·͢

    View full-size slide

  27. ։ൃظؒ
    • 7,8 ϲ݄ؒ͘Β͍
    • 2015೥9݄ v1.0 ϦϦʔε

    View full-size slide

  28. νʔϜϏϧσΟϯά
    • ࣾ಺ͷΫϥΠΞϯταΠυͷΤϯδχΞʹ͸
    Unity(C#) ͕ଟ͍ɻiOS(Objective-C) ΍
    Android(Java) Λॻ͚Δਓ͕গͳ͍
    • ۀ຿ҕୗͷ iOS, Android ΤϯδχΞΛޏͬͨ
    • ۀ຿ҕୗͷΤϯδχΞʹ GitHub ͷ࢖͍ํ΍
    ΞδϟΠϧ։ൃͷϑϩʔΛ·֮ͣ͑ͯ΋Β͏

    View full-size slide

  29. • Ruby 2.2
    • Ruby on Rails 4.2
    • MySQL
    • nginx

    View full-size slide

  30. • CircleCI
    • Slack
    • GitHub
    • Ansible
    • serverspec

    View full-size slide

  31. iOS
    • CocoaPods
    • Objective-C
    Android
    • Gradle
    • Android Studio

    View full-size slide

  32. Ͳ͏͍͏࡞Γʹ͔ͨ͠

    View full-size slide

  33. Α͋͘Δڞ௨ج൫γεςϜͷ࡞Γ
    • αʔϏεͱڞ௨ج൫Λͻͱͭͷ mBaaS ͱͯ͠࡞Δ
    • ڞ௨ج൫γεςϜ্ʹ֤αʔϏεΛ૊ΈࠐΉ
    ໰୊఺
    • ڞ௨ج൫γεςϜͱήʔϜλΠτϧͷґଘؔ܎
    • ಛఆͷϓϩάϥϛϯάݴޠʹશαʔϏε͕ϩοΫΠϯ
    • ݹ͍όʔδϣϯͷݴޠॲཧܥͷར༻Λڧ੍͞ΕΔ

    View full-size slide

  34. ࣌୅͸ Microservices

    View full-size slide

  35. Network
    ڞ௨ج൫
    γεςϜ
    ήʔϜ
    αʔόʔ
    HTTPS
    (JSON)

    View full-size slide

  36. • ֤ήʔϜλΠτϧͷωοτϫʔΫ಺ʹ

    ڞ௨ج൫γεςϜΛσϓϩΠ
    • HTTPS (JSON)Ͱ΍ΓͱΓ͢Δ෼ࢄγεςϜ
    • ήʔϜαʔόʔ͸ڞ௨ج൫γεςϜͷ

    ϚχϡΞϧʹै͍ϦΫΤετΛૹड৴
    Network
    ڞ௨ج൫
    γεςϜ
    ήʔϜ
    αʔόʔ
    HTTPS
    (JSON)

    View full-size slide

  37. • Objective-C, Java Ͱ 

    ࡞ͬͨڞ௨ج൫

    ϥΠϒϥϦΛϥοϓͯ͠
    Unity Plugin ʹ͢Δ
    • ΫϥΠΞϯτଆʹ͸

    ڞ௨ج൫γεςϜ༻ͷ
    Unity Plugin Λ૊ΈࠐΉ
    • αʔόʔͱ HTTPS Ͱ௨৴
    ڞ௨ج൫
    γεςϜ
    HTTPS
    (JSON)
    Client
    Unity Plugin

    View full-size slide

  38. Network
    ήʔϜ
    αʔόʔ
    ڞ௨ج൫
    γεςϜ
    • ڞ௨ج൫ͱήʔϜ͸

    ผʑͷݴޠͰ΋͍͍
    • IaaS ͷো֐ͰҰํ͚ͩ

    མͪΔ͜ͱ͕ͳ͍Α͏ಉҰ
    ͷωοτϫʔΫ಺ʹஔ͘
    Client
    Unity Plugin

    View full-size slide

  39. ৽نొ࿥
    ᶃ ΞΧ΢ϯτൃߦ
    Client
    Unity Plugin
    ڞ௨ج൫
    γεςϜ
    ήʔϜ
    αʔόʔ

    View full-size slide

  40. ϩάΠϯ
    ήʔϜ
    αʔόʔ
    ᶄ ΞΧ΢ϯτΛ໰͍߹ΘͤΔ
    ᶃϩάΠϯΛϦΫΤετ
    ᶅ Ϩεϙϯε
    Client
    Unity Plugin
    ڞ௨ج൫
    γεςϜ

    View full-size slide

  41. SNS ΞΧ΢ϯτͱͷඥ෇͚
    ڞ௨ج൫
    γεςϜ
    ᶄ αʔόʔʹૹΔ
    Twitter
    Facebook
    google+
    ᶃ access_token Λऔಘ
    ᶅ SNS ͷ uid Λऔಘ
    ΞΧ΢ϯτͱ uid Λඥ͚ͮΔ
    Client
    Unity Plugin

    View full-size slide

  42. ػछมߋ࣌ͳͲͷҾ͖ܧ͗
    ᶅ SNS ͷ uid Λऔಘ
    SNS ͷ uid ͔ΒΞΧ΢ϯτΛऔಘ
    → ͦͷΞΧ΢ϯτΛ࢖͏
    ڞ௨ج൫
    γεςϜ
    ᶄ αʔόʔʹૹΔ
    Twitter
    Facebook
    google+
    ᶃ access_token Λऔಘ
    Client
    Unity Plugin

    View full-size slide

  43. # app/models/account.rb
    class Account < ActiveRecord::Base
    has_many :connections, dependent: :destroy
    has_many :orders, class_name: 'Purchase::Order'
    before_create do
    self.auth_id = SecureRandom.uuid
    self.auth_token = SecureRandom.hex
    end
    def already_connected_with?(provider)
    connections.find_by(provider: provider).present?
    end
    def overwrite_connection(provider:, provider_uid:)
    connections.find_by!(provider: provider).update!(provider_uid: provider_uid)
    end
    def register_birth_date(year, month)
    update!(birth_date: build_birth_date(year, month))
    end
    def child?
    become_adult_day.future?
    end
    private
    def become_adult_day
    birth_date + 20.years + 1.month
    end

    View full-size slide

  44. ՝ۚͷϑϩʔ

    View full-size slide

  45. τϥϯβΫγϣϯIDൃߦ
    ήʔϜ
    αʔόʔ
    ڞ௨ج൫
    γεςϜ
    ᶃ τϥϯβΫγϣϯIDൃߦ
    Client
    Unity Plugin

    View full-size slide

  46. ߪೖͱϨγʔτͷडཧ
    Client
    Unity Plugin
    ڞ௨ج൫
    γεςϜ
    ᶄϨγʔτૹ৴
    AppStore
    GooglePlay
    τϥϯβΫγϣϯID Λ

    ɾapplicationUsername (iOS)

    ɾdeveloper payload (Android)
    ʹ٧ΊͯɺߪೖΛ࣮ߦ

    ͜͏͓ͯ͘͠ͱϨγʔτͱҰॹʹ
    τϥϯβΫγϣϯ ID ͕ฦͬͯ͘Δ
    → ࠶Πϯετʔϧͯ͠΋อ࣋͞ΕΔ
    ᶃ ߪೖ

    View full-size slide

  47. Verify ͱৼΓࠐΈ
    ήʔϜ
    αʔόʔ
    ڞ௨ج൫
    γεςϜ
    AppStore
    ᶃ Ϩγʔτͷݕূ
    ᶄৼࠐ
    iOS ͸ Apple ͷαʔόʔͰ verify

    Android ͸खݩͰ verify Ͱ͖Δ
    verify Ͱ͖ͨΒΞΠςϜΛৼࠐΉ

    View full-size slide

  48. ՝ۚͷνʔτରࡦ
    աڈʹฐ͕ࣾܦݧͨ͠νʔτํ๏͢΂ͯʹରࡦ
    • ِ෺ͷϨγʔτΛૹΓ͚ͭͯ͘Δ
    • ຊ෺ͷϨγʔτ͚ͩͲطʹৼࠐࡁΈͷϨγʔτ
    • ຊ෺ͷϨγʔτ͚ͩͲଞͷΞϓϦͷϨγʔτ
    ΛϚϧνϓϩηεલఏͰରࡦ
    • τϥϯβΫγϣϯΛऔͬͯߦϩοΫͰഉଞ੍ޚ

    ʢActiveRecord ͷ `#with_lock` Λ࢖ͬͨʣ

    View full-size slide

  49. ݁ߏ͠ΜͲ͔ͬͨ͆

    View full-size slide

  50. • ͍͕ͭ͜όάͬͯͨΓରࡦ͕͋·͔ͬͨΓ
    ͢Δͱ࠾༻͍ͯ͠Δࣾ಺ͷશήʔϜλΠτ
    ϧ͕νʔτ͞ΕΔ
    • νʔτରࡦɺ࣮ࡍʹίʔσΟϯάͯ͠ΈΔ
    ͱ͚ͬ͜͏ߟ͑ͳ͍ͱ͍͚ͳ͍͜ͱ͕ଟ͍
    • Ϛϧνϓϩηεલఏ
    • ฒྻॲཧͬͯͦ΋ͦ΋೉͗͢͠ΔΑͶ

    View full-size slide

  51. Gemfile ެ։ͪ͠Ό͍·͢
    https://gist.github.com/ttanimichi/5f63897d746b7491fbf7

    View full-size slide

  52. • gem “venice”
    • iOS Ϩγʔτͷ verify Λ΍ͬͯ͘ΕΔ gem
    • iOS 7ͷ৽ϨγʔτܗࣜʹରԠ͔ͨͬͨ͠

    ͷͰ fork ൛ͷ “amoslanka/venice” Λ࢖ͬͨ
    • ສ͕Ұফ͞ΕΔͱࠔΔͷͰ fork ͠ͱ͍ͨ
    ศརͩͬͨ gem

    View full-size slide

  53. # app/models/purchase/receipt/app_store.rb
    module Purchase
    module Receipt
    class AppStore
    def initialize(raw_receipt:, bundle_id:, store_transaction_id:)
    @raw_receipt = raw_receipt
    @bundle_id = bundle_id
    @store_transaction_id = store_transaction_id
    end
    def verify
    verify_receipt
    fail_unless_correct_bundle_id
    build_result
    end
    private
    def verify_receipt
    begin
    @receipt ||= Venice::Receipt.verify!(@raw_receipt).to_h
    rescue Venice::Receipt::VerificationError => e
    handle_error(e.code, e.message)
    end
    end
    def fail_unless_correct_bundle_id
    unless @bundle_id == receipt[:bundle_id]
    fail Incorrect, "bundle_id is incorrect"
    end
    end

    View full-size slide

  54. ։ൃ্ͷϙΠϯτ

    View full-size slide

  55. ΞϓϦέʔγϣϯαʔόʔͷબఆ
    ΞʔΩςΫνϟ
    unicorn
    ϓϩηεϕʔε
    fork Λ࢖ͬͨ master-slave
    Puma ϚϧνεϨου
    Thin
    Πϕϯτۦಈ
    EventMachine ʹґଘ

    View full-size slide

  56. ΞϓϦέʔγϣϯαʔόʔͷબఆ
    • ࠷ॳ͸Կ΋ߟ͑ͣʹ unicorn Λ࢖͍ͬͯͨ
    • ՝ۚͷΤϯυϙΠϯτʹͪΐͬͱෛՙΛ͔͚
    ͯΈΔͱ٧·Δ
    • ਺ेඵ΄Ͳ଴ͭͱϨεϙϯε͕ฦͬͯ͘Δ

    View full-size slide

  57. verify ͷͨΊʹ Apple ͷαʔόʔʹϦΫΤετΛ
    ౤͍͛ͯͯɺ600ms ΄ͲϒϩοΫ͞Εͯ͠·͏

    → ෛՙ͕͔͔Δͱ͢΂ͯͷ Worker ͕٧·Δ

    View full-size slide

  58. ΞϓϦέʔγϣϯαʔόʔͷબఆ
    iOS ͷϨγʔτΛ verify ͢ΔαʔόʔͷΑ͏
    ͳ஗͍ॲཧ (ϦϞʔτHTTP ϦΫΤετͱ͔)
    ΛؚΉΤϯυϙΠϯτͷ৔߹ɺunicorn ͷΑ͏
    ͳϓϩηεϕʔεͷΞϓϦέʔγϣϯαʔόʔ
    Λ࢖͏΂͖Ͱ͸ͳ͍

    View full-size slide

  59. ΞϓϦέʔγϣϯαʔόʔͷબఆ
    • unicorn ͸ߴ଎͕ͩɺϓϩηεϕʔεͷͨΊ

    ಉ͡ϝϞϦʔྔͰ༻ҙͰ͖Δ Worker ਺͸

    εϨουϕʔεͷ Puma ͷ΄͏͕ଟ͍
    • Puma ʹมߋ
    • ຊ౰͸Πϕϯτۦಈͷ Thin ͕ϕετͩͬͨ
    ͷ͔΋ɻPuma Ͱे෼ͳੑೳ͕ग़͔ͨΒ Thin
    ͸ݕূ͠ͳ͔ͬͨ

    View full-size slide

  60. iOS ͷ applicationUsername
    • ࠶Πϯετʔϧͨ͠৔߹Ͱ΋τϥϯβΫγϣ
    ϯIDΛอ࣋Ͱ͖ΔΑ͏ɺ঎඼ͷߪೖ࣌ʹ
    applicationUsername ʹڞ௨ج൫γεςϜͷ
    τϥϯβΫγϣϯID Λ٧Ίͨ
    • ͕ɺͳ͔ͥ production ͩͱ100 ݅ʹ1݅͘Β
    ͍ applicationUsername ʹ٧Ίͨσʔλ͕
    ਧͬඈΜͰ Null Ͱฦͬͯ͘Δɻɻ

    View full-size slide

  61. Apple ༷…

    View full-size slide

  62. ϦϦʔεͯ͠Έͯࢥͬͨ͜ͱ

    View full-size slide

  63. ಛʹ՝ۚ·ΘΓͷॲཧΛ
    ڞ௨ԽͰ͖ͨͷ͸ྑ͔ͬͨ
    • νʔτରࡦͱ͔
    • όά͕ͳ͍Α͏ʹ࡞Δͷ͸ਆܦΛ࢖͏
    • ݸผʹ࣮૷ͨ͘͠ͳ͍
    • ձࣾͱͯ͠౷Ұ͞Ε͍ͯΔ΂͖

    View full-size slide

  64. Կ΋ߟ͑ͳͯ͘΋ձࣾͱͯ͠ͷ
    ΨΠυϥΠϯʹै͑Δͷ͸ྑ͍
    • ೥ྸ֬ೝ·ΘΓͱ͔
    • ੜ೥݄Λೖྗͤͯ͞ɺະ੒೥ʹ͸֬ೝ
    • ͜͏͍͏ͷ͸ձࣾͱͯ͠ͷΨΠυϥΠϯ͕
    ༻ҙ͞Ε͍ͯΔ
    • ڞ௨ج൫γεςϜΛ࢖͏͚ͩͰΨΠυϥΠ
    ϯʹଇͬͱΕΔ

    View full-size slide

  65. SNS ΞΧ΢ϯτͰҾ͖ܧ͗
    • ࠓճɺҾ͖ܧ͗ͷཧ૝ܗΛݕ౼ͨ͠
    • ڞ௨ج൫γεςϜΛ࢖͏͚ͩͰձࣾͱͯ͠
    ཧ૝ܗͱߟ͑ΔҾ͖ܧ͗ॲཧΛಋೖͰ͖Δ
    • ௿ίετͰߴ͍ϢʔβʔମݧΛఏڙͰ͖Δ

    View full-size slide

  66. ࠓޙʹ͍ͭͯ

    View full-size slide

  67. • ೝূ
    • ՝ۚ
    • νϟοτ
    • Push ௨஌
    • ૬ޓૹ٬
    • ͳͲͳͲ
    ͜ͷลΛਐΊ͍͖͍ͯͨ

    View full-size slide

  68. • ೝূ
    • ՝ۚ
    • νϟοτ
    • Push ௨஌
    • ૬ޓૹ٬
    • ͳͲͳͲ
    ͪ͜Βʹؔͯ͠΋
    ػೳ௥Ճͷ
    ཁ๬͕Ͱ͍ͯΔ

    View full-size slide

  69. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View full-size slide