Real World Migration from HTTP to gRPC #CNDT2020

2b4f9f20b554d4c77c46fe6a9930d6fe?s=47 Nao Minami
September 08, 2020

Real World Migration from HTTP to gRPC #CNDT2020

CloudNative Days Tokyo 2020 の発表資料です。Wantedly での gRPC 導入の取り組みについて話しました。

gRPC という通信技術についての詳細な説明から、gPRC を利用することによるメリット、gRPC を利用することで実際に得られたパフォーマンス改善、gRPC への移行を行うための実践的な Tips について話しました。移行の際にはツールやライブラリの開発や開発フローの整備など技術的、組織的な挑戦を行なっており、その詳細についても話しました。

https://event.cloudnativedays.jp/cndt2020/talks/14

2b4f9f20b554d4c77c46fe6a9930d6fe?s=128

Nao Minami

September 08, 2020
Tweet

Transcript

  1. ©2020 Wantedly, Inc. Real World Migration from HTTP to gRPC

    08.Sep.2020 - Nao Minami (@south37) Wantedly, Inc. CloudNative Days Tokyo 2020
  2. ©2019 Wantedly, Inc. /BP.JOBNJ *OGSBTUSVDUVSF5FBN 8BOUFEMZ *OD (JU)VCTPVUI 5XJUUFSTPVUI ϚΠΫϩαʔϏεؒ௨৴΁ͷH31$ಋೖʹऔΓ૊Ή

     43&ͱͯ͠ͷ໾ׂʢαʔϏεͷ৴པੑʹ੹೚ʣ  ։ൃج൫ͱͯ͠ͷ໾ׂʢΤϯδχΞͷੜ࢈ੑʹ੹೚ʣ
  3. ©2020 Wantedly, Inc. 1. gRPC Λͳͥར༻͢Δͷ͔ 2. gRPC ΛͲ͏ར༻࢝͠Ί͔ͨ 3.

    gRPC Λࣾ಺ʹͲ͏޿Ί͔ͨ Agenda
  4. ©2020 Wantedly, Inc. 1. gRPC Λͳͥར༻͢Δͷ͔ 2. gRPC ΛͲ͏ར༻࢝͠Ί͔ͨ 3.

    gRPC Λࣾ಺ʹͲ͏޿Ί͔ͨ Agenda
  5. ©2020 Wantedly, Inc. gRPC ͱ͸

  6. ©2020 Wantedly, Inc. gRPC ͱ͸ Google ੡ͷ high performance ͳ

    RPC framework w 3FNPUF1SPDFEVSF$BMM 31$  w DMJFOU͕ؔ਺ݺͼग़͠SFNPUFTFSWFS্Ͱؔ਺ݺͼग़͕͠ॲཧ͞Εͯ݁Ռ͕ฦ͞ΕΔ w )551Λ௨৴ϓϩτίϧͱͯ͠ར༻ w 1SPUPDPM#V⒎FSTΛαʔϏεఆٛʢTFSWFSͰ࣮૷͞Εͨ ؔ਺ͷܕʣͷهड़ʹར༻ H31$ͷެࣜEPDVNFOUΑΓҾ༻
  7. ©2020 Wantedly, Inc. HTTP/2 ͱ͸ ޮ཰తͳ Hypertext Transfer Protocol (HTTP)

    w (PPHMF੡41%:QSPUPDPM͕ݩʹͳͬͯඪ४Խ w 5SBOTQPSUΛޮ཰Խ͢Δ͍ͭ͘΋ͷ༏ΕͨػೳଟॏԽɺϔομѹॖɺFUD H31$ͷIJHIQFSGPSNBODFʹߩݙ IUUQTEFWFMPQFSTHPPHMFDPNXFCGVOEBNFOUBMTQFSGPSNBODFIUUQΑΓҾ༻
  8. ©2020 Wantedly, Inc. Protocol Buffers ͱ͸ Google ੡ IDL +

    ίϯύΠϥ + serialization library w *OUFSGBDF%FpOJUJPO-BOHVBHF *%- αʔϏεఆٛΛهड़͢ΔͨΊͷಠࣗݴޠ w *%-ͰαʔϏεఆٛΛهड़͢Δͱɺ1SPUPDPM#V⒎FSTίϯύΠϥʢQSPUPDʣ͕ ޮ཰తͳTFSJBMJ[BUJPOͷҝͷίʔυΛࣗಈੜ੒ w αʔϏεఆٛ͸"1*4DIFNBͱͯ͠ͷ໾ׂΛՌͨ͢ 4DIFNB%SJWFO%FWFMPQNFOUͰߴ͍ੜ࢈ੑΛ࣮ݱՄೳ API Schema = proto ϑΝΠϧ 4FSWFS։ൃ $MJFOU։ൃ
  9. ©2020 Wantedly, Inc. gRPC ͸ HTTP/2 ͱ Protocol Buffers Λར༻͢Δ

    ༏Εͨ RPC framework
  10. ©2020 Wantedly, Inc. gRPC Λͳͥར༻͢Δͷ͔

  11. ©2018 Wantedly, Inc. 8BOUFEMZͰ͸ 8BOUFEMZ7JTJUɺ8BOUFEMZ1FPQMFΛ ϚΠΫϩαʔϏεͰ։ൃ

  12. ©2018 Wantedly, Inc. ͸ͨΒ͘Λ໘ന͘ ༗໊اۀ΍ϕϯνϟʔɺελʔτΞοϓاۀɺؾʹͳΔ ΦϑΟεʹ࿩Λฉ͖ʹ͍͜͏ɻ
 ΩϥͬͱޫΔγΰτ΍ϓϩδΣΫτɺձࣾΛݟ͚ͭͯ ΤϯτϦʔ͠·͠ΐ͏ɻ஌Γ߹͍ͷͭͳ͕Γ͕෼͔ͬͯ ҆৺Ͱ͢ɻ

  13. ©2018 Wantedly, Inc. ड͚औ໊ͬͨࢗશͯΛɺճͷࡱӨͰಉ࣌ ʹಡΈࠐΈɻ
 ಡΈࠐΜ໊ͩࢗ͸ਓ޻஌ೳ͕ଈ࣌σʔλԽ ͠ɺ࿈བྷாʹ௥Ճ͞Ε·͢ɻ ݡ໊ࢗ͘؅ཧ

  14. ©2020 Wantedly, Inc. എܠ: Wantedly Visit ͱ Wantedly People ͷΞʔΩςΫνϟ

    ໿ 100 ͷϚΠΫϩαʔϏεΛ૊Έ߹Θͤͨ ΞʔΩςΫνϟ w 3VCZ (P 1ZUIPO /PEFKTͳͲ༷ʑͳݴޠͰϚΠΫϩαʔϏεΛ࣮૷ w ݩʑϚΠΫϩαʔϏεؒ௨৴ʹ͸)551Λར༻ LTDMVTUFS $PSF4FSWJDFT
  15. ©2018 Wantedly, Inc. ϚΠΫϩαʔϏε։ൃΛਐΊΔ্Ͱ ͍͔ͭ͘՝୊͕ଘࡏͨ͠

  16. ©2020 Wantedly, Inc. HTTP/1.1 Λར༻͢ΔࣄͰੜ͡Δ௨৴ latency ͕໰୊ w ,FFQBMJWFແ͠ͷૉ๿ͳ)551͸༷ʑͳཁҼͰ஗͘ͳΔ w

    FH%/4MPPLVQ 5$1XBZIBOETIBLF 5$1TMPXTUBSU FUD ՝୊1 ϚΠΫϩαʔϏε -BUFODZDBVTFECZVTJOH)551
  17. ©2020 Wantedly, Inc. ϚΠΫϩαʔϏεͰ͸௨৴ latency ͷӨڹ͕େ͖͍ w ௨৴૬ख͕૿͑Δ΄Ͳɺ௨৴MBUFODZʢಛʹUBJMMBUFODZʣͷӨڹΛड͚΍͘͢ͳΔ w ྫϚΠΫϩαʔϏεؒ௨৴͕ͷ֬཰Ͱ஗͘ͳΔέʔεΛߟ͑Δ

    w ݸͷϚΠΫϩαʔϏεͱ௨৴͢Δ৔߹શମͱͯ͠͸ͷ֬཰Ͱ஗͍ w ݸͷϚΠΫϩαʔϏεͱ௨৴͢Δ৔߹શମͱͯ͠͸ͷ֬཰Ͱ஗͍ w ࣮ࡍʹUBJMMBUFODZͷد༩Ͱ஗͘ͳͬͯΔϚΠΫϩαʔϏε͕ଘࡏͨ͠ w ྫଞͷϚΠΫϩαʔϏεͱͷ௨৴MBUFODZ͕ࢧ഑తͳϚΠΫϩαʔϏεͰ BWFSBHFSFTQPOTFUJNFNTʹରͯ͠UJMFSFTQPOTFUJNF͕ NT ϚΠΫϩαʔϏεؒ௨৴ͷUBJMMBUFODZվળ͕ඞཁͱ͞Ε͍ͯͨ ϚΠΫϩαʔϏεʹ͓͚Δ௨৴ latency ͷ໰୊
  18. ©2020 Wantedly, Inc. Protocol Buffers ͷԸܙΛҰ෦ͷνʔϜͷΈ͕ڗड w ݩʑɺҰ෦νʔϜͰ͸1SPUPDPM#V⒎FSTΛϚΠΫϩαʔϏεͷ"1*4DIFNBͱͯ͠ར༻ 4DIFNB%SJWFO%FWFMPQNFOUͰߴ͍ੜ࢈ੑΛ࣮ݱ ՝୊2

    CVJMEFSTDPOUPLZPl8FC"1*ʹடংΛ༩͑Δ1SPUPDPM#V⒎FSTl w ͔͠͠ɺ1SPUPDPM#V⒎FSTPWFS)551Ͱ͸ʮQBZMPBEΛMJCSBSZ͔Βར༻ͮ͠Β͍ʯ ͳͲ͍͔ͭ͘໰୊͋Γ ࣾ಺શମʹ͸1SPUPDPM#V⒎FSTΛ޿͛ͮΒ͍ঢ়گͩͬͨ
  19. ©2020 Wantedly, Inc.

  20. ©2020 Wantedly, Inc. gRPC ʹظ଴ͨ͜͠ͱ 1. ϚΠΫϩαʔϏεͷύϑΥʔϚϯεվળ 2. Protocol Buffers

    ͷࣾ಺શମͰͷར༻ʹΑΔɹɹɹ ։ൃੜ࢈ੑ޲্
  21. ©2020 Wantedly, Inc. gRPC ͕՝୊Λղܾͯ͘͠ΕΔ͜ͱΛظ଴ͯ͠ ಋೖΛܾΊͨ

  22. ©2020 Wantedly, Inc. 1. gRPC Λͳͥར༻͢Δͷ͔ 2. gRPC ΛͲ͏ར༻࢝͠Ί͔ͨ 3.

    gRPC Λࣾ಺ʹͲ͏޿Ί͔ͨ Agenda
  23. ©2020 Wantedly, Inc. 2-1. ݕূ 2-2. Πϯϑϥ੔උ 2-3. খ͘͞ಋೖ &

    ޮՌଌఆ 2. gRPC ΛͲ͏ར༻࢝͠Ί͔ͨ
  24. ©2020 Wantedly, Inc. 2-1. ݕূ 2-2. Πϯϑϥ੔උ 2-3. খ͘͞ಋೖ &

    ޮՌଌఆ 2. gRPC ΛͲ͏ར༻࢝͠Ί͔ͨ
  25. ©2020 Wantedly, Inc. gRPC ͷύϑΥʔϚϯεΛ։ൃ༻ k8s cluster Ͱݕূ w ݩʑɺຊ൪LTDMVTUFSͱ΄΅ಉ͡ߏ੒ͷLTDMVTUFS͕։ൃ༻్ͱͯ͠ଘࡏ

    w ϚΠΫϩαʔϏεͷίʔυΛH31$Λར༻͢Δ΋ͷ΁ͱॻ͖׵͑ͯ-BUFODZΛܭଌ 2-1. ݕূ ຊ൪LTDMVTUFS )551ϚΠΫϩαʔϏε )551 H31$ϚΠΫϩαʔϏε ։ൃ༻LTDMVTUFS 5SZH31$
  26. ©2020 Wantedly, Inc. gRPC ͷݕূ݁Ռ͸ʁ

  27. ©2020 Wantedly, Inc. ௨৴෦෼ͷ latency ͷܶతͳվળΛ؍ଌ w "WFSBHFMBUFODZഒߴ଎Խ NTNT 

    w 5BJMMBUFODZ UJMF ഒߴ଎Խ NTNT Latency [ms] percentile gRPC ։ൃ༻ k8s cluster Ͱͷ Benchmark ݁Ռ HTTP/1.1 20 40 60 80 100 100 150 50 0
  28. ©2020 Wantedly, Inc. ݕূ݁ՌΛड͚ͯ gRPC ΁ͷظ଴͕ߴ·ͬͨ

  29. ©2020 Wantedly, Inc. 2-1. ݕূ 2-2. Πϯϑϥ੔උ 2-3. খ͘͞ಋೖ &

    ޮՌଌఆ 2. gRPC ΛͲ͏ར༻࢝͠Ί͔ͨ
  30. ©2020 Wantedly, Inc. gRPC Λ Production Ͱར༻͢ΔͨΊͷΠϯϑϥ w -PBE#BMBODJOHɺ.POJUPSJOHͳͲͷΠϯϑϥ੔උ͕ඞཁ 2-2.

    Πϯϑϥ੔උ
  31. ©2020 Wantedly, Inc. gRPC Λ Production Ͱར༻͢ΔͨΊͷΠϯϑϥ w-PBE#BMBODJOH w .POJUPSJOH

    2-2. Πϯϑϥ੔උ
  32. ©2020 Wantedly, Inc. gRPC ʹ͓͍ͯ͸ɺL4 load-balancer ͸ෆద੾ w H31$͸)551Λ׆༻ͯ͠ʮҰ౓ཱ֬ͨ͠MPOHMJWFEͳ5$1DPOOFDUJPOΛԿ౓΋ SFRVFTUʹར༻͢Δʯલఏͷઃܭ

    w -MPBECBMBODFS͸5$1DPOOFDUJPOཱ֬ͷෛՙ෼ࢄ͔͠ߦΘͳ͍ͨΊɺH31$Ͱ͸ USB⒏Dͷෛՙ෼ࢄ͕͏·͘ߦΘΕͳ͍ Load Balancing ௨৴૬ख͕ݻఆ͞ΕΔ
  33. ©2020 Wantedly, Inc. ղܾࡦ: Istio Λ L7 load-balancing ʹར༻ w

    *TUJP͸ɺ,VCFSOFUFTͳͲͰར༻Ͱ͖ΔαʔϏεϝογϡɾϓϥοτϑΥʔϜ w *TUJPʹΑͬͯDPOpHVSF͞Εͨ&OWPZΛTJEFDBSQSPYZͱͯ͠JOKFDUͯ͠ɺ -MPBECBMBODJOHʹར༻ͨ͠ Load Balancing &OWPZ
  34. ©2020 Wantedly, Inc. gRPC Λ Production Ͱར༻͢ΔͨΊͷΠϯϑϥ w -PBE#BMBODJOH w.POJUPSJOH

    2-2. Πϯϑϥ੔උ
  35. ©2020 Wantedly, Inc. ຊ൪؀ڥͷΞϓϦέʔγϣϯ͸ϞχλϦϯά͕ඞཁ w ໰୊ͷݕ஌΍ύϑΥʔϚϯεͷܭଌͳͲ༷ʑͳ໨తͰϞχλϦϯάΛߦ͏ w )551Ͱ͸ͲͷϚΠΫϩαʔϏε΋%BUBEPH /FX3FMJD )POFZCBEHFSͳͲͰ

    SFRVFTU͝ͱͷNFUSJDTΛϞχλϦϯάಉ͡ঢ়گΛH31$Ͱ΋࡞Γ͍ͨ Monitoring
  36. ©2020 Wantedly, Inc. Monitoring gRPC server ͷϞχλϦϯάΛͲ͏࣮ݱ͢Δ͔ʁ => gRPC interceptor

    Λར༻ w H31$JOUFSDFQUPSΛར༻͢ΔࣄͰɺʮH31$SFRVFTUSFTQPOTFͷϥΠϑαΠΫϧʹ NFUSJDTૹ৴ͳͲͷ೚ҙͷॲཧΛࠩ͠ࠐΉʯ͜ͱ͕Մೳ $MJFOUH31$JOUFSDFQUPST $MJFOU 4FSWFSH31$JOUFSDFQUPST 4FSWFS 3FRVFTU 3FTQPOTF
  37. ©2020 Wantedly, Inc. Monitoring gRPC interceptor Λ༻ҙ w ֤छ4BB4޲͚ͷH31$JOUFSDFQUPSΛ࣮૷ͨ͠ w

    3VCZ࣮૷ͷҰ෦͸044ͱͯ͠ެ։
  38. ©2020 Wantedly, Inc. 2-1. ݕূ 2-2. Πϯϑϥ੔උ 2-3. খ͘͞ಋೖ &

    ޮՌଌఆ 2. gRPC ΛͲ͏ར༻࢝͠Ί͔ͨ
  39. ©2020 Wantedly, Inc. Ұ෦ͷϚΠΫϩαʔϏεͰ gRPC Λಋೖ w H31$ಋೖΛૉૣ͘ਐΊΔͨΊʹɺ࠷ॳ͸Ұ෦ͷϚΠΫϩαʔϏεͰಋೖ w ର৅ͱͯ͠lϢʔβʔαʔϏεzΛબΜͩ

    2-3. খ͘͞ಋೖ & ޮՌଌఆ LTDMVTUFS $PSF4FSWJDFT ϢʔβʔαʔϏε
  40. ©2020 Wantedly, Inc. ͳͥϢʔβʔαʔϏεΛબΜͩͷ͔ʁ ಛ௃: traffic ͕ଟ͘ low latency ͕ඞཁ

    w ଟ͘ͷϚΠΫϩαʔϏε͔Βར༻͍ͯ͠ΔͨΊUSB⒏D͕ଟ͍ w Ϣʔβʔ͔ΒͷSFRVFTUॲཧͰಉظతʹSFRVFTU͞ΕΔέʔεଟ਺MPXMBUFODZ͕ඞཁ H31$ಋೖʹΑΔΠϯύΫτ͕ݦஶʹݱΕΔ͜ͱ͕ظ଴ग़དྷΔ ϢʔβʔαʔϏε Ϣʔβʔͷઃఆ஋΍ϓϩϑΟʔϧͷऔಘɾߋ৽
  41. ©2020 Wantedly, Inc. gRPC ಋೖΛͲ͏ਐΊ͔ͨʁ

  42. ©2020 Wantedly, Inc. k8s objects Λ 2 ηοτ༻ҙ w ύϑΥʔϚϯεಛੑͳͲ͕ҧ͏ͷͰɺ%FQMPZNFOUͱ)1"Λݸผʹ༻ҙ

    w )5513VCZPO3BJMTTFSWFS͕ىಈ͢Δ%FQMPZNFOU )1" 4FSWJDF w H31$H31$TFSWFS͕ىಈ͢Δ%FQMPZNFOU )1" 4FSWJDF w $MJFOUଆͰ௨৴ઌIPTU໊ LT4FSWJDF Λ੾Γସ͑ͯ௨৴खஈΛ੍ޚ gRPC ಋೖͷਐΊํ H31$ H31$TFSWFS $MJFOUϚΠΫϩαʔϏε )551 3VCZPO3BJMT
  43. ©2020 Wantedly, Inc. Client ϚΠΫϩαʔϏεͰ gRPC ͷར༻Λ૿΍͢ w Ұ෦ϦΫΤετʹH31$Λಋೖ༷ͯ͠ࢠΛݟͳ͕Βɺঃʑʹׂ߹Λ૿Ճ׬શʹҠߦ gRPC

    ಋೖͷਐΊํ ϢʔβʔαʔϏε ϢʔβʔαʔϏε )551  H31$  H31$ͷׂ߹Λ૿Ճ )551  H31$  $MJFOU $MJFOU
  44. ©2020 Wantedly, Inc. gRPC Λಋೖͨ݁͠Ռ͸ʁ

  45. ©2020 Wantedly, Inc. ϚΠΫϩαʔϏεؒ௨৴ͷύϑΥʔϚϯε͕ ܶతʹվળͨ͠

  46. ©2020 Wantedly, Inc. gRPC ΛҰ෦ϚΠΫϩαʔϏεʹಋೖͨ݁͠Ռ ௨৴෦෼ͷ Latency ͕ܶతʹվળ w ϢʔβʔαʔϏεͱͷ௨৴ͷBWFSBHFMBUFODZ͕SFRVFTU͋ͨΓ໿NTվળ

    w ౓ͷSFRVFTUॲཧͷதͰϢʔβʔαʔϏε΁Կ౓΋SFRVFTU͢Δέʔε͕ଘࡏ ௨৴ͷBWFSBHFMBUFODZ͕਺े਺ඦͷܶతվળ e.g. ϢʔβʔαʔϏε௨৴෦෼ͷ average latency ͕ 153ms ͔Β 45ms ʹ 240% վળͨ͠ྫ HTTP/1.1 gRPC
  47. ©2020 Wantedly, Inc. gRPC ΛҰ෦ϚΠΫϩαʔϏεʹಋೖͨ݁͠Ռ શͯͷॲཧΛؚΉ response time ΋ݦஶʹվળ w

    ϢʔβʔαʔϏεͱͷ௨৴͕ଟ͍FOEQPJOU͸ɺશମͷSFTQPOTFUJNF΋ܶతʹվળ w શମͱͯ͠ૣ͘ͳ͚ͬͨͩͰͳ͘ɺʮۃ୺ʹ஗͘ͳΔέʔεʯ͕ܹݮͨ͠ 5BJMMBUFODZվળͷޮՌΛ࣮ײ UJMFSFTQPOTFUJNF HTTP/1.1 gRPC e.g. 99%tile response time ͷϐʔΫ͕ 5,000ms ͔Β 1,900ms ʹ 3,000ms Ҏ্վળͨ͠ྫ
  48. ©2020 Wantedly, Inc. gRPC Λຊ൪ k8s cluster ʹಋೖͯ͠ ύϑΥʔϚϯεվળ͕ग़དྷΔͱ֬ೝͰ͖ͨ

  49. ©2020 Wantedly, Inc. 1. gRPC Λͳͥར༻͢Δͷ͔ 2. gRPC ΛͲ͏ར༻࢝͠Ί͔ͨ 3.

    gRPC Λࣾ಺ʹͲ͏޿Ί͔ͨ Agenda
  50. ©2020 Wantedly, Inc. ՝୊: gRPC ͷར༻͕Ұ෦ʹݶΒΕ͍ͯͨ w H31$͕Ұ෦Ͱ͔͠ར༻͞Εͯͳ͍ͱɺԸܙΛड͚ΒΕΔͷ͸Ұ෦ͷFOEQPJOUͱ Ұ෦ͷ։ൃऀʹݶΒΕͯ͠·͏ 3.

    gRPC Λࣾ಺ʹͲ͏޿Ί͔ͨ Ұ෦ͷH31$ϚΠΫϩαʔϏε ଟ͘ͷ)551ϚΠΫϩαʔϏε
  51. ©2020 Wantedly, Inc. ΰʔϧ: gRPC ͷར༻Λ޿͛ͯԸܙΛ޿͘ड͚Δ w ଟ͘ͷFOEQPJOUͰH31$Λར༻༏ΕͨύϑΥʔϚϯεʹΑͬͯϢʔβʔମݧΛվળ w ଟ͘ͷ։ൃऀ͕H31$Λར༻1SPUPDPM#V⒎FSTʹΑΓ։ൃੜ࢈ੑΛ޲্

    3. gRPC Λࣾ಺ʹͲ͏޿Ί͔ͨ ଟ͘ͷH31$ϚΠΫϩαʔϏε Ұ෦ͷ)551ϚΠΫϩαʔϏε
  52. ©2020 Wantedly, Inc. gRPC Λར༻ͨ͠։ൃΛ޿͛Δ͜ͱΛ໨ࢦͨ͠

  53. ©2020 Wantedly, Inc. 3-1. ։ൃ؀ڥ੔උ 3-2. ࣾ಺΁એ఻ͯ͠޿͍͛ͯ͘ 3. gRPC Λࣾ಺ʹͲ͏޿Ί͔ͨ

  54. ©2020 Wantedly, Inc. 3-1. ։ൃ؀ڥ੔උ 3-2. ࣾ಺΁એ఻ͯ͠޿͍͛ͯ͘ 3. gRPC Λࣾ಺ʹͲ͏޿Ί͔ͨ

  55. ©2020 Wantedly, Inc. ੜ࢈ੑͷߴ͍։ൃ؀ڥΛߏங w εΩʔϚ؅ཧϫʔΫϑϩʔɺϥΠϒϥϦ੔උʹΑͬͯ։ൃ؀ڥΛ੔͑Δ 3-1. ։ൃ؀ڥ੔උ

  56. ©2020 Wantedly, Inc. ੜ࢈ੑͷߴ͍։ൃ؀ڥΛߏங wεΩʔϚ؅ཧ w ϥΠϒϥϦ੔උ 3-1. ։ൃ؀ڥ੔උ

  57. ©2020 Wantedly, Inc. Monorepo Λ࠾༻͠ͳ͍৔߹͸ɺͲ͏΍ͬͯಉ͡ proto ϑΝΠϧΛڞ༗͢Δ͔ߟ͑Δඞཁ͕͋Δ ಉ͡QSPUPϑΝΠϧ 3FQPTJUPSZ" 3FQPTJUPSZ#

    3FQPTJUPSZ$ εΩʔϚ؅ཧ = proto ϑΝΠϧ؅ཧ
  58. ©2020 Wantedly, Inc. Ͳ͏΍ͬͯ proto ϑΝΠϧΛڞ༗͢Δ͔ʁ w खಈ$PQZ1BTUFʁ ෳ਺SFQPTJUPSZΛ੔߹ੑΛอͬͯߋ৽͠ଓ͚Δͷ͕೉͍͠ w

    QSPUPϑΝΠϧΛࣗಈμ΢ϯϩʔυ͢ΔػߏΛ༻ҙ͢Δʁ ֤ϨϙδτϦͷ։ൃऀ͕ίʔυੜ੒Λߦ͏ඞཁ͕͋ΓɺQSPUPDWFSTJPO΍ QMVHJOͷ༗ແͳͲɺ։ൃऀؒͷ؀ڥͷҧ͍ʹۤ͠Ή ͦ͜Ͱɺcentral repository Λ༻ҙͨ͠ εΩʔϚ؅ཧ = proto ϑΝΠϧ؅ཧ
  59. ©2020 Wantedly, Inc. apis: εΩʔϚ؅ཧͷͨΊͷ central repository w lBQJTz͸8BOUFEMZͷ͢΂ͯͷQSPUPϑΝΠϧΛ؅ཧ εΩʔϚ؅ཧ

    = proto ϑΝΠϧ؅ཧ
  60. ©2020 Wantedly, Inc. “apis” repository ΛͲ͏ར༻͢Δͷ͔ʁ “apis” ͷ CI ύΠϓϥΠϯͰίʔυੜ੒͕ߦΘΕΔ

    w 3VCZ (P 1ZUIPO /PEFKTͦΕͧΕͷݴޠ޲͚ͷίʔυΛQSPUPϑΝΠϧ͔Βੜ੒ w ੜ੒͞Εͨίʔυ͸֤ݴޠͷ1BDLBHF.BOBHFSͰ഑৴ FH#VOEMFS (P.PEVMFT FUD  w ։ൃऀ͕ࣗ෼Ͱίʔυੜ੒Λߦ͏ඞཁ͕ͳ͍ঢ়ଶΛ࣮ݱ
  61. ©2020 Wantedly, Inc. # Gemfile gem 'apis', git: 'git@github.com:wantedly/apis-ruby.git', tag:

    'xxx.yyy.zzz' 3VCZXJUI#VOEMFS
  62. ©2020 Wantedly, Inc. ੜ࢈ੑͷߴ͍։ൃ؀ڥΛߏங w εΩʔϚ؅ཧ wϥΠϒϥϦ੔උ 3-1. ։ൃ؀ڥ੔උ

  63. ©2020 Wantedly, Inc. ֤ݴޠ޲͚ʹϥΠϒϥϦͰ֤छػೳΛఏڙ w ݴޠ w 3VCZ (P 1ZUIPO

    /PEFKT w ػೳ w H31$4FSWFS $MJFOU։ൃ༻VUJMJUZ w H31$JOUFSDFQUPST w 1SPUPDPM#V⒎FSTར༻ͷͨΊͷVUJMJUZ ϥΠϒϥϦ੔උ
  64. ©2020 Wantedly, Inc. ϥΠϒϥϦ͸Ͳ͏͍ͬͨܗͰ੔උͨ͠ͷ͔ʁ

  65. ©2020 Wantedly, Inc. “servicex” ͱݺ͹ΕΔࣾ಺ڞ௨ library Λར༻ w ݩʑɺ)551ͷ࣌୅͔ΒʮͲͷϚΠΫϩαʔϏε͔Β΋ڞ௨Ͱ࢖ΘΕΔػೳʯΛ TFSWJDFYͰఏڙ͖ͯͨ͠H31$։ൃΛศརʹ͢ΔMJCSBSZ΋TFSWJDFYͰఏڙ

    w TFSWJDFY͸֤ݴޠ޲͚ʹଘࡏ w 3VCZ (P 1ZUIPO ϥΠϒϥϦ͸Ͳ͏͍ͬͨܗͰ੔උͨ͠ͷ͔ʁ ϚΠΫϩαʔϏε" ϚΠΫϩαʔϏε# ϚΠΫϩαʔϏε$ lTFSWJDFYz
  66. ©2020 Wantedly, Inc. servicex-ruby Ͱ࣮૷ͨ͠ػೳΛҰ෦঺հ

  67. ©2020 Wantedly, Inc. gRPC server ։ൃͷͨΊͷ grpc-server ίϚϯυ w H31$TFSWJDFDMBTT͸ࣗಈͰIBOEMFSͱͯ͠ొ࿥

    w H31$JOUFSDFQUPS΋ඞཁͳ΋ͷ͸ࣗಈͰઃఆ w 3VCZPO3BJMTͷΑ͏ͳ)PUSFMPBEJOHػೳΛఏڙ w ։ൃऀ͸ɺH31$TFSWJDFDMBTTͷ࣮૷ʹूதߴ͍ੜ࢈ੑΛ࣮ݱ “servicex-ruby” ͷػೳ $ bundle exec grpc-server handling /grpc.health.v1.Health/Check with #<Method: Grpc::Health::Checker#check> handling /grpc.health.v1.Health/Watch with #<Method: Grpc::Health::Checker(Grpc::Health::V1::Health::Service)#watch> handling /wantedly.users.UserService/ListUsers with #<Method: UsersGrpcService#list_users> . . . gRPC server starting... * Listening on tcp://0.0.0.0:6046 * Environment: development
  68. ©2020 Wantedly, Inc. gRPC client ͷͨΊͷ Servicex::Grpc.stub_for w H31$JOUFSDFQUPSͱͯ͠ඞཁͳ΋ͷ͸ࣗಈͰઃఆ w

    6TFS"HFOU΋ࣗಈͰઃఆ w ։ൃऀ͸ʮH31$ͷ࢖͍ํʯΛؾʹ͢Δࣄͳ͘ɺϩδοΫͷ࣮૷ʹूதߴ͍ੜ࢈ੑ # NOTE: Load UsersPb::UserService from apis require "wantedly/users/users_services_pb" grpc_server_url = “xxx” client = Servicex::Grpc.stub_for( UsersPb::UserService, grpc_server_url, ) client.get_user(UsersPb::GetUserRequest.new(…)) “servicex-ruby” ͷػೳ
  69. ©2020 Wantedly, Inc. Pb: Protocol Buffers ͷར༻Λ؆୯ʹ͢Δ utility w 1CΛར༻͢ΔࣄͰQSPUPCVGPCKFDUΛ؆୯ʹ࡞੒Մೳ

    w ྫ͑͹ɺ4USJOH͔ΒUJNFTUBNQΦϒδΣΫτΛ࡞੒͢Δ͜ͱ͕Մೳ [1] pry(main)> Pb.to_timestamp("2019-05-15T00:00:00+09:00") => <Google::Protobuf::Timestamp: seconds: 1557846000, nanos: 0> 8JUIl1Cz [1] pry(main)> Google::Protobuf::Timestamp.new( [1] pry(main)* seconds: Time.parse("2019-05-15T00:00:00+09:00").to_i [1] pry(main)* ) => <Google::Protobuf::Timestamp: seconds: 1557846000, nanos: 0> 8JUIPVUl1Cz “servicex-ruby” ͷػೳ
  70. ©2020 Wantedly, Inc. servicex-ruby ͷػೳͷҰ෦͸ OSS Խ w 044ԽΛ௨ͯ͠ɺH31$ͷΤίγεςϜ੒ख़ʹߩݙ “servicex-ruby”

    ͱ OSS
  71. ©2020 Wantedly, Inc. Ruby Ͱͷ gRPC ։ൃΛखް͘αϙʔτͨ͠

  72. ©2020 Wantedly, Inc. Go, Python, Node.js ͳͲଞͷݴޠͰ͸ʁ

  73. ©2020 Wantedly, Inc. “grapi” + “servicex-go” Λར༻ w HSBQJH31$ HSQDHBUFXBZߏ੒ͷ"1*TFSWFS޲͚DPEFHFOFSBUPS

    MJCSBSZ 044  w H31$TFSWFS୯ಠར༻΋Մೳ w TFSWJDFYHPHSBQJͷਪ঑ઃఆ H31$JOUFSDFQUPS౳Λఏڙ͢Δࣾ಺ڞ௨MJCSBSZ Go ͷ gRPC ։ൃ؀ڥ (P$POGFSFODF4QSJOH lHSBQJ#VMEJOH+40/"1*TFSWFSXJUIHSQDHBUFXBZGPSNJDSPTFSWJDFTz
  74. ©2020 Wantedly, Inc. Go ͷ gRPC ։ൃ؀ڥ package main import

    ( ... "github.com/izumin5210/grapi/pkg/grapiserver" "github.com/wantedly/servicex-go/v2/pkg/servicex" "github.com/wantedly/servicex-go/v2/pkg/grpcx" "github.com/wantedly/spath/to/server" ) func InitializeGrapiServerEngine(ctx context.Context) (*grapiserver.Engine, error) { userServiceServer := server.NewUserServiceServer(ctx) engine := grapiserver.New( grpcx.WithDefault(), grapiserver.WithServers(userServiceServer), ) return engine, nil } func run() error { ctx := context.Background() defer servicex.Close() s, err := InitializeGrapiServerEngine(ctx) if err != nil { return fail.Wrap(err) } return s.ServeContext(ctx) }
  75. ©2020 Wantedly, Inc. “grapi” ͱ “servicex-go” ͕ࣾ಺ڞ௨ͷػೳ͸ఏڙ w ։ൃऀ͸H31$TFSWFSͷϩδοΫ࣮૷ʹूதͰ͖Δߴ͍ੜ࢈ੑΛ࣮ݱ Go

    ͷ gRPC ։ൃ؀ڥ
  76. ©2020 Wantedly, Inc. Python ͷ gRPC ։ൃ؀ڥ

  77. ©2020 Wantedly, Inc. “servicex-python” ͱ͍͏ࣾ಺ڞ௨ library Λར༻ w lHSQDYzQBDLBHFͱͯ͠HSQDY4FSWFSDMBTTͳͲͷVUJMJUZΛ༻ҙ w

    ։ൃऀ͸ɺH31$TFSWJDFDMBTTͷ࣮૷ʹूதߴ͍ੜ࢈ੑΛ࣮ݱ Python ͷ gRPC ։ൃ؀ڥ import servicex.grpcx as grpcx class UserService(users_pb2_grpc.UserServiceServicer): ... server = grpcx.Server( port=os.getenv("APP_GRPC_PORT", "3000"), max_workers=10, grpc_services=[ grpcx.ServiceInfo( name=users_pb2.DESCRIPTOR.services_by_name['UserService'].full_name, adder=users_pb2_grpc.add_UserServiceServicer_to_server, servicer=UserService(), ) ] ) server.run()
  78. ©2020 Wantedly, Inc. gRPC client ։ൃʹ͸ grpc package Λ௚઀ར༻ w

    1ZUIPO͸.-ϚΠΫϩαʔϏεͱͯ͠຤୺Ͱͷར༻͕ଟ͍ H31$DMJFOUར༻͸গͳ͘VUJMJUZͷχʔζ͸গͳ͍ w χʔζ͕૿͑ͨλΠϛϯάͰࣾ಺ڞ௨MJCSBSZԽͷ༧ఆ Python ͷ gRPC ։ൃ؀ڥ from grpc.experimental import aio class UsersService: def __init__(self) -> None: self.base_url = ... async def get(self, user_id: int) -> users_pb2.User: async with aio.insecure_channel(target=self.base_url) as channel: stub = users_pb2_grpc.UserServiceStub(channel) req = users_pb2.GetUserRequest(...) res = await stub.GetUser(req, timeout=2) return res.user #SPXTFS H31$ 1ZUIPO.-ϚΠΫϩαʔϏε
  79. ©2020 Wantedly, Inc. Node.js ͷ gRPC ։ൃ؀ڥ

  80. ©2020 Wantedly, Inc. Node.js ੡ Backend for Frontend (BFF) Ͱ

    gRPC client Λར༻ w 6UJMJUZMJCSBSZΛར༻͢ΔࣄͰɺH31$DMJFOUΛར༻ͨ͠։ൃΛޮ཰Խ w lBQJTOPEFzͰܕఆٛϑΝΠϧΛੜ੒ͯ͠5ZQF4DSJQUͷ੩తܕݕࠪʹ׆༻ Node.js ͷ gRPC ։ൃ؀ڥ /PEFKT#'' (SBQI2- H31$ )551 #SPXTFS import { UserServiceClient, IUserServiceClient, } from "@wantedly_private/apis-node/path/to/users_pb"; import { serviceClientCreator } from "../../utils/grpc/"; export class UserService extends serviceClientCreator<IUserServiceClient>( UserServiceClient, “127.0.0.1:3000”, ) {}
  81. ©2020 Wantedly, Inc. ֤ݴޠͰ gRPC ։ൃ؀ڥΛ੔͑ͨ

  82. ©2020 Wantedly, Inc. 3-1. ։ൃ؀ڥ੔උ 3-2. ࣾ಺΁એ఻ͯ͠޿͍͛ͯ͘ 3. gRPC Λࣾ಺ʹͲ͏޿Ί͔ͨ

  83. ©2020 Wantedly, Inc. લఏ: ։ൃνʔϜʹ gRPC ͷར༻Λڧ੍͸ग़དྷͳ͍ w ։ൃνʔϜ͸ͦΕͧΕ͕ʮࣗ෼ͨͪͷ࠾༻͢Δٕज़ελοΫʯΛબఆ 3-2.

    ࣾ಺΁એ఻ͯ͠޿͍͛ͯ͘ Infra (k8s, gRPC, etc.) ։ൃ νʔϜ A w ج൫ΛUPPMMJCSBSZͱͯ͠ఏڙ w LTͷ֦ு౳ʢFHDVTUPNDPOUSPMMFSʣ w ϓϩμΫτΛ։ൃ w ࣗ෼ͨͪͰٕज़બఆ ։ൃ νʔϜ B ։ൃ νʔϜ C
  84. ©2020 Wantedly, Inc. Ξϓϩʔν: ϝϦοτΛૌٻͭͭࣾ͠಺ษڧձ w ʮH31$ͰύϑΥʔϚϯεվળͨ͠ྫʯΛఆظతʹࣾ಺Ͱએ఻ͯ͠ϝϦοτΛૌٻ w ʮࣾ಺ษڧձʯΛ։࠵ͯ͠ɺH31$TFSWFSDMJFOU։ൃͷ஌ࣝΛਁಁ 3-2.

    ࣾ಺΁એ఻ͯ͠޿͍͛ͯ͘
  85. ©2020 Wantedly, Inc.

  86. ©2020 Wantedly, Inc.

  87. ©2020 Wantedly, Inc. ΞϓϦέʔγϣϯίʔυॻ͖׵͑Λੵۃతʹࢧԉ w H31$ͷར༻ྫΛ૿΍͍ͯ͘͜͠ͱͰɺH31$ར༻ͷٕज़త৺ཧతϋʔυϧΛԼ͛Δ 3-2. ࣾ಺΁એ఻ͯ͠޿͍͛ͯ͘

  88. ©2020 Wantedly, Inc.

  89. ©2020 Wantedly, Inc. ϝϦοτૌٻɺࣾ಺ษڧձɺ஍ಓͳίʔυมߋΛ௨ͯ͠ ঃʑʹࣾ಺ʹ gRPC Λ޿͍͛ͯͬͨ

  90. ©2020 Wantedly, Inc. gRPC Λࣾ಺ʹ޿ΊΔऔΓ૊Έͷ݁Ռ͸ʁ

  91. ©2020 Wantedly, Inc. gRPC ͕ࣾ಺Ͱ޿͘ར༻͞ΕΔΑ͏ʹͳͬͨ w ΞΫςΟϒʹ։ൃ͞Ε͍ͯΔओཁͳϚΠΫϩαʔϏε͕H31$Խ w ৽نͷϚΠΫϩαʔϏε։ൃʹ͸΄΅H31$Λར༻ w

    όοΫΤϯυ։ൃऀͷ໿ׂ͕H31$Λར༻ͨ͠։ൃΛܦݧ gRPC Λࣾ಺ʹ޿ΊΔऔΓ૊Έͷ݁Ռ )551 H31$ ϢʔβʔαʔϏε $PSF4FSWJDFT
  92. ©2020 Wantedly, Inc. ࣾ಺ͷ։ൃऀ͔Βتͼͷ੠΋ฉ͍ͨ w lH31$͸͔ͳΓ։ൃମݧ͕ྑ͔ͬͨzͱ͍͏੠͕ಧ͍ͨ gRPC Λࣾ಺ʹ޿ΊΔऔΓ૊Έͷ݁Ռ

  93. ©2020 Wantedly, Inc. gRPC ͕ࣾ಺ελϯμʔυͱ ݴ͑Δͱ͜Ζ·Ͱ޿·ͬͨ

  94. ©2020 Wantedly, Inc. ͦͷ݁Ռ͞Βʹɻɻɻ

  95. ©2020 Wantedly, Inc. ϚΠΫϩαʔϏεͷύϑΥʔϚϯε͕վળग़དྷͨ w H31$͕޿͘ར༻͞ΕΔΑ͏ʹͳͬͨࣄͰɺଟ͘ͷFOEQPJOUͰԸܙΛड͚ΔΑ͏ʹͳͬͨ Protocol Buffers Λར༻ͨ͠։ൃ͕޿͕ͬͨ w

    H31$͕޿·ͬͨ݁Ռɺଟ͘ͷ։ൃऀ͕1SPUPDPM#V⒎FSTΛར༻͢ΔΑ͏ʹͳͬͨ εΩʔϚۦಈ։ൃͷԸܙΛड͚ΒΕΔػձ͕૿͑ͨ gRPC ͕޿·ͬͨ݁Ռ
  96. ©2020 Wantedly, Inc. ૊৫શମͱͯ͠ gRPC ͷԸܙΛ ड͚ΒΕΔΑ͏ʹͳͬͨ

  97. ©2020 Wantedly, Inc. ·ͱΊ

  98. ©2020 Wantedly, Inc. ύϑΥʔϚϯε΍։ൃੜ࢈ੑͷ؍఺Ͱ gRPC ʹண໨ w ՝୊)551ͷ௨৴MBUFODZ w ՝୊1SPUPDPM#V⒎FSTʹΑΔ։ൃੜ࢈ੑ޲্ͷԸܙ͕Ұ෦νʔϜʹݶఆ

    ૉૣ͘ಋೖ͠։ൃ؀ڥ੔උΛߦ্ͬͨͰར༻Λ޿͛ͨ w Ұ෦ͷϚΠΫϩαʔϏεͰH31$Λૉૣ͘ݕূɾಋೖ w ϝϦοτૌٻ΍ࣾ಺ษڧձͱͱ΋ʹ஍ಓʹίʔυΛมߋ͠ɺࣾ಺ʹ޿Ίͨ ͦͷ݁Ռ gRPC ͸޿͘࢖ΘΕΔΑ͏ʹͳͬͨ w ଟ਺ͷϚΠΫϩαʔϏεͰH31$͕ར༻͞ΕͯύϑΥʔϚϯε͕վળ w ଟ਺ͷ։ൃऀ͕H31$Λར༻͢ΔࣄͰɺ૊৫શମͱͯ͠։ൃੜ࢈ੑ͕޲্ ·ͱΊ
  99. ©2020 Wantedly, Inc. • Chris Briggs https://unsplash.com/photos/V72Hk6LjjjI Photo Credit