Slide 1

Slide 1 text

Yuya Okuyama gRPC at OA Dev LINE Developer Meetup @ 2020/7/29

Slide 2

Slide 2 text

About me • Yuya Okuyama • 2019೥4݄ೖࣾ • Official Account ։ൃࣨ • LINEެࣜΞΧ΢ϯτؔ࿈ͷ৽نαʔϏε ( ) • line-bot-sdk-python ϝϯς 2

Slide 3

Slide 3 text

Outline • What’s gRPC? • gRPC at OA Dev • Our system overview • gRPC server built with Armeria • Error handling • Documentation • Summary 3

Slide 4

Slide 4 text

What’s gRPC?

Slide 5

Slide 5 text

What’s gRPC • Google ͕։ൃͨ͠ RPC ϑϨʔϜϫʔΫ. ݱࡏ͸, ͷϓϩδΣΫτ. • Protocol Buffers (ΠϯλʔϑΣΠεఆٛݴޠ) • εΩʔϚϑΝʔετͳ։ൃ • ಛఆͷݴޠʹґଘ͠ͳ͍ϝοηʔδ΍αʔϏεͷఆٛ • JSON ͱͷ૬ޓม׵ • લํ/ޙํޓ׵ੑΛอͭมߋ • ίϯύΫτ͔ͭޮ཰తͳΤϯίʔσΟϯά • HTTP/2 ͰσʔλΛૹड৴͢Δ • ૒ํ޲௨৴ 5

Slide 6

Slide 6 text

gRPC at LINE 6 • Our service • LINE Official Account • LINE LIVE Commerce • LINE MUSIC • LINE Financial • etc. • Java, Kotlin, Scala • Go • Python • JavaScript (gRPC-Web) Services Languages Thrift http://thrift.apache.org/ Facebook ੡ͷ RPC ϑϨʔϜϫʔΫ. ࣾ಺ͷଟ͘ͷՕॴͰར༻͞Ε͍ͯΔ.

Slide 7

Slide 7 text

What should we do to deploy gRPC app? • Logging • Metrics • Distributed tracing • Circuit breaker • Retry • Load balancing • Debug tool • Error handling • Documentation 7

Slide 8

Slide 8 text

gRPC at OA Dev

Slide 9

Slide 9 text

Our system overview 9 #SPXTFS 1BSUOFS4ZTUFN 0UIFS5FBN 4FSWJDF 4FSWJDF 4FSWJDF --# REST gRPC gRPC 3&45H31$ 1SPYZ gRPC REST Our service 1SPYZ gRPC

Slide 10

Slide 10 text

Our system overview 10 #SPXTFS 1BSUOFS4ZTUFN 0UIFS5FBN 4FSWJDF 4FSWJDF 4FSWJDF --# REST gRPC gRPC 3&45H31$ 1SPYZ gRPC REST Our service 1SPYZ gRPC 1SPYZͰMPBECBMBODJOH

Slide 11

Slide 11 text

Our system overview 11 #SPXTFS 1BSUOFS4ZTUFN 0UIFS5FBN 4FSWJDF 4FSWJDF 4FSWJDF --# REST gRPC gRPC 3&45H31$ 1SPYZ gRPC REST &OWPZ΍HSQDHBUFXBZ (P ͸࢖Θͣ 4QSJOHͰखॻ͖ ࣾ֎αʔόʔ͔Βݺ͹ΕΔͷͰ ॊೈͰӡ༻ίετͷͳ͍ํ๏ʹ Our service 1SPYZ gRPC 1SPYZͰMPBECBMBODJOH

Slide 12

Slide 12 text

gRPC server built with 12 • gRPC ϑϨʔϜϫʔΫͱͯ͠, LINE ੡ϚΠΫϩαʔϏεϑϨʔϜϫʔΫ Armeria Λ࠾༻. • Reasons: • LogNet/grpc-spring-boot-starter, yidongnan/grpc-spring-boot-starter ΑΓ׆ൃ • ࣾ಺੡ͳͷͰ feature request ͠΍͍͢ • ࣾ֎ͷํͰ΋ line-armeria.slack.com Ͱؾܰʹ • grpc/grpc-java ͷ interface Λ࢖͍ͬͯΔͷͰ, gRPC ΤίγεςϜ͔Βҳ୤͠ͳ͍ • ศརͰଟ࠼ͳػೳ: • ϚΠΫϩαʔϏεͰఆ൪ͳػೳ͕؆୯ʹ࢖͑Δ • Client-side load balancing and service discovery • Circuit breaker • Retry • Distributed tracing (Zipkin) • DocService (Swagger UI తͳը໘)

Slide 13

Slide 13 text

Armeria: Very easy to use many features 13 gRPC server H31$TFSWJDFͷ࣮૷Λ౉͢ $POUFOUUZQFʹԠͯ͡ +40/ͰγϦΞϥΠζ͢Δઃఆ΋ %JTUSJCVUFEUSBDJOH ;JQLJO

Slide 14

Slide 14 text

Armeria: Very easy to use many features 14 gRPC client $MJFOUTJEFMPBECBMBODJOH %/4CBTFETFSWJDFEJTDPWFSZ

Slide 15

Slide 15 text

Armeria: DocService • Protocol Buffers Ͱఆٛͨ͠ service, message ͷҰཡ΍ gRPC ͷݺͼग़͕͠Ͱ͖Δ 15

Slide 16

Slide 16 text

Armeria: DocService 16

Slide 17

Slide 17 text

What should we do to deploy gRPC app? (reappeared) • Logging • Metrics • Distributed tracing • Circuit breaker • Retry • Load balancing • Debug tool • Error handling • Documentation 17 }

Slide 18

Slide 18 text

Error handling • REST ͱҧͬͯ, ΤϥʔϖΠϩʔυΛ HTTP Body Ͱฦͤͳ͍ • ํ๏ • grpc-status, grpc-message ͷΈΛฦ͢ • શͯͷϨεϙϯεఆٛʹΤϥʔ༻ͷϑΟʔϧυΛ௥Ճ͢Δ • google/rpc/error_details.proto Λ Metadata (http header) ʹؚΊͯฦ͢ • ࣗ෼Ͱఆٛͨ͠ϝοηʔδΛ Metadata (http header) ʹؚΊͯฦ͢ 18

Slide 19

Slide 19 text

Error handling • REST ͱҧͬͯ, ΤϥʔϖΠϩʔυΛ HTTP Body Ͱฦͤͳ͍ • ํ๏ • grpc-status, grpc-message ͷΈΛฦ͢ • શͯͷϨεϙϯεఆٛʹΤϥʔ༻ͷϑΟʔϧυΛ௥Ճ͢Δ • google/rpc/error_details.proto Λ Metadata (http header) ʹؚΊͯฦ͢ • ࣗ෼Ͱఆٛͨ͠ϝοηʔδΛ Metadata (http header) ʹؚΊͯฦ͢ 19

Slide 20

Slide 20 text

Error handling: Returning custom error message 20 proto Server Client

Slide 21

Slide 21 text

Error handling: Returning custom error message 21 proto Server Client ϖΠϩʔυΛ ProtoBuf ͰόΠφϦΤϯίʔυͯ͠, Metadata (http header) ܦ༝ͰૹΔ

Slide 22

Slide 22 text

Error handling: Returning custom error message 22 proto Server Client ϖΠϩʔυΛ ProtoBuf ͰόΠφϦΤϯίʔυͯ͠, Metadata (http header) ܦ༝ͰૹΔ ड͚औΓख͕ࣗ෼ͰσγϦΞϥΠζ͢Δ

Slide 23

Slide 23 text

Documentation • protoc-gen-docs ͱ͍͏υΩϡϝϯτੜ੒ثΛ࢖ͬͯ, proto ϑΝΠϧͷίϝϯτ΍
 Φϓγϣϯ͔ΒଞνʔϜʹڞ༗͢ΔυΩϡϝϯτΛੜ੒. 23

Slide 24

Slide 24 text

What should we do to deploy gRPC app? (reappeared) • Logging • Metrics • Distributed tracing • Circuit breaker • Retry • Load balancing • Debug tool • Error handling • Documentation 24 } Metadata ʹΤϥʔϖΠϩʔυΛؚΊΔ protoc-gen-docs

Slide 25

Slide 25 text

How was gRPC? • εΩʔϚϑΝʔετ • ࣮૷Ͱ͸ͳ͘εΩʔϚ(࢓༷)͕͋ΔͷͰ, ίʔυϨϏϡʔ͕͠΍͍͢ • proto ϑΝΠϧͰؔ਺໊΍ϑΟʔϧυ໊ͷมߋΛιʔείʔυ΁มߋ͢Δͷ͕πϥ͍ • HTTP/2 • ࣾ಺LB, Nginx Ͱ͸ଟগ໘౗͕ͩͬͨ, େͨ͠໰୊͸ͳ͔ͬͨ • ΤίγεςϜ • CLI ͔ΒϦΫΤετ͢ΔͨΊͷ gRPCurl,υΩϡϝϯτΛੜ੒͢Δ protoc-gen-docs
 ͳͲ, ศརͳπʔϧ͸ͦͦ͋͜͜Δ • GUI Client ΋͍͔ͭ͋͘Δ͕, Ϧονͳػೳ͸ͳ͍ 25

Slide 26

Slide 26 text

Summary

Slide 27

Slide 27 text

Takeaways • LINE ࣾͰ΋গͣͭ͠ gRPC ͕ϓϩμΫγϣϯͰ࢖ΘΕ͍ͩͯ͠Δ • (For Java,) Armeria Λ࢖͑͹, production ready ͳ gRPC αʔόʔΛ؆୯ʹߏஙͰ͖Δ • gRPC Ͱͷ error handling ͸ REST ΑΓͪΐͬͱ໘౗ • εΩʔϚϑΝʔετͩͱ, ϨϏϡʔ΋υΩϡϝϯτੜ੒΋͠΍͍͢ 27

Slide 28

Slide 28 text

Thank you! Any questions?