Ruby gRPCを使って「ちゃんと」サービスを作る / Make a service properly using Ruby gRPC

Ruby gRPCを使って「ちゃんと」サービスを作る / Make a service properly using Ruby gRPC

D7b086b9c6bb828f15cd7a9ff9b8c688?s=128

Shintani Teppei

December 18, 2019
Tweet

Transcript

  1. ©2019 Wantedly, Inc. Ruby gRPC Λ࢖ͬͯ ʮͪΌΜͱʯαʔϏεΛ࡞Δ Scramble Tech ৽ଔLT

    Dec 18, 2019 - Teppei Shintani
  2. ©2019 Wantedly, Inc. About me Teppei Shintani @euglena1215 • ’19

    Wantedly new grads • Server side engineer • Wantedly Visit ืूػೳͷϚΠΫϩαʔϏεԽ • Ruby ❤ • ϚΠΫϩαʔϏεԽ΍͍͖ͬͯ
  3. ©2019 Wantedly, Inc. gRPCͱ͸ʁ ͱ͸ʁ

  4. ©2019 Wantedly, Inc. Google ͕࡞ͬͨ ݴޠඇґଘͷ௨৴ϓϩτίϧ gRPCͱ͸ʁ

  5. ©2019 Wantedly, Inc.

  6. ©2019 Wantedly, Inc. gRPC library ͸ Google ͕ ϝΠϯͰ։ൃΛߦ͍ͬͯΔ

  7. ©2019 Wantedly, Inc. ֤ݴޠͷ੒ख़౓͸ GoogleͷϞνϕʔγϣϯ࣍ୈ

  8. ©2019 Wantedly, Inc. Ruby gRPC ͷ੒ख़౓্͕͕Βͳ͍ Ruby gRPC ͷपลϥΠϒϥϦ͕ू·Βͳ͍

  9. ©2019 Wantedly, Inc. ݫ͍͠؀ڥͷ Ruby gRPC Λ࢖ͬͯ αʔϏεΛ࡞͍ͬͯͨ͘Ίʹ

  10. ©2019 Wantedly, Inc. •൚༻తͳ grpc interceptor •։ൃੜ࢈ੑ্͛ΔϥΠϒϥϦ •Ruby gRPC best

    practice ͷ໛ࡧ ΍͍ͬͯΔ͜ͱ
  11. ©2019 Wantedly, Inc. grpc interceptorͱ͸ʁ ൚༻తͳgrpc interceptor grpc interceptor ͱ͸௨৴(rpcݺͼ

    ग़͠)ͷલޙͰಛఆͷॲཧΛ૊ΈࠐΊ Δػߏɻ express, rack middleware ͱ͍ͩ ͍ͨಉ͡ͱ͍͑͹఻ΘΔਓ͸఻ΘΔ ͔΋
  12. ©2019 Wantedly, Inc. ࡞ͬͨ grpc interceptor ൚༻తͳgrpc interceptor • ΤϥʔΛ؂ࢹαʔϏεʹૹͬͯ͘ΕΔ͘Μ

    • Ruby/Rails ґଘͷΤϥʔΛ gRPC Τϥʔʹม׵͢Δ͘Μ • activerecord ͷ connection Λྑ͍ײ͡ʹ࢖͍ճ͘͢Μ •ΞΫηεϩάΛͱͬͯ೚ҙͷprovider΁ૹ৴͢Δ͘Μ by @south37 • newrelic ʹ metrics Λૹ৴ͯ͘͠ΕΔ͘Μ by @south37
  13. ©2019 Wantedly, Inc. Protocol Buffersͷੑ࣭ ։ൃੜ࢈ੑ্͛ΔϥΠϒϥϦ • field ͸શͯ optional

    • proto2 Ͱ͸ required field ͕ଘࡏ͕ͨ͠ɺproto3Ͱ͸શͯ optional ʹͳͬͨ • required ͳ field Λഇࢭͨ͘͠ͳͬͨͱ͖ʹޙํޓ׵Λҡ࣋͢Δͷ͕೉͍͠ ΞϓϦέʔγϣϯଆͷϩδοΫͰ null ͔Ͳ͏͔ΛνΣοΫ͢Δඞཁ͕͋Δ ΊͪΌͪ͘Ό໘౗
  14. ©2019 Wantedly, Inc. grpc_required_annotator ։ൃੜ࢈ੑ্͛ΔϥΠϒϥϦ https://github.com/euglena1215/grpc_required_annotator

  15. ©2019 Wantedly, Inc. Ruby gRPC best practice ͷ໛ࡧ • Rails

    ͷ஌ݟΛ Ruby gRPC ʹͲ͏ྲྀ༻͢Δ͔ • Rails controller ʹґଘ͍ͯ͠Δ gem ͸Ұ௨Γ࢖͑ͳ͍ • ͲΜͳઃܭʹ͢Δͱ͍͍ͷ͔ʁ • Rails Έ͍ͨʹ DB table ͱ API interface Λີ݁߹ͤͨ͘͞ͳ͍ • MVVM? Ͳ͜·Ͱ΍Δʁ
  16. ©2019 Wantedly, Inc. Ruby gRPC best practice ͷ໛ࡧ • Rails

    ͷ஌ݟΛ Ruby gRPC ʹͲ͏ྲྀ༻͢Δ͔ • Rails controller ʹґଘ͍ͯ͠Δ gem ͸Ұ௨Γ࢖͑ͳ͍ • ͲΜͳઃܭʹ͢Δͱ͍͍ͷ͔ʁ • Rails Έ͍ͨʹ DB table ͱ API interface Λີ݁߹ͤͨ͘͞ͳ͍ • MVVM? Ͳ͜·Ͱ΍Δʁ ͜͜ͷ݁࿦͸·ͩग़͍ͯͳ͍ɺɺɺ
  17. ©2019 Wantedly, Inc. Ruby gRPC ͕ී௨ʹ࢖͑Δ ঢ়ଶʹͳΔ·Ͱ΍͍͖ͬͯ