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

Introduction gRPC

d-kuro
December 14, 2018

Introduction gRPC

18/12/14 - The World Café - Classmethod, Inc.
Lightning Talks

d-kuro

December 14, 2018
Tweet

More Decks by d-kuro

Other Decks in Programming

Transcript

  1. 5෼࿮ LT ͰΘ͔Δ(Θ͔Βͳ͍)
    18/12/14 - The World Café - Classmethod, Inc.
    Dai Kurosawa / @ponde_m

    View full-size slide

  2. What is gRPC ?
    • Google ͕ެ։ͨ͠ RPC ͷϑϨʔϜϫʔΫ
    • Protocol Buffers ͰαʔϏεͷΠϯλϑΣʔεΛఆ
    ٛͯ͠ Server, Client ͷίʔυΛࣗಈͰੜ੒Ͱ͖Δ
    • Protocol Buffers ͸σϑΥϧτͰͦΕҎ֎ͷσʔλϑΥʔϚοτ΋͋Δ
    • HTTP/2 Λ࢖༻ͯ͠௨৴, stream ͳͲ΋Ͱ͖Δ
    from: [What is gRPC?](https://grpc.io/docs/guides/index.html)

    View full-size slide

  3. What is gRPC ?
    • Google ͕ެ։ͨ͠ RPC ͷϑϨʔϜϫʔΫ
    • Protocol Buffers ͰαʔϏεͷΠϯλϑΣʔεΛఆ
    ٛͯ͠ Server, Client ͷίʔυΛࣗಈͰੜ੒Ͱ͖Δ
    • Protocol Buffers ͸σϑΥϧτͰͦΕҎ֎ͷσʔλϑΥʔϚοτ΋͋Δ
    • HTTP/2 Λ࢖༻ͯ͠௨৴, stream ͳͲ΋Ͱ͖Δ
    from: [What is gRPC?](https://grpc.io/docs/guides/index.html)

    View full-size slide

  4. Protocol Buffers ??


    View full-size slide

  5. (͕࣌ؒͳ͍ͷͰ)
    ோΊΔ͚ͩͰ
    ͳΜͱͳ͘Θ͔Δ
    Protocol Buffers
    ͷ࢖͍ํ

    View full-size slide

  6. How to use
    Protocol Buffers in gRPC
    from: [Go Quick Start](https://grpc.io/docs/quickstart/go.html)

    View full-size slide

  7. How to use
    Protocol Buffers in gRPC
    from: [Go Quick Start](https://grpc.io/docs/quickstart/go.html)
    • protoc ͱ͍͏ίϚϯυͰίϯύΠϧ͢Δͱ֤ݴޠ
    ͷίʔυΛδΣωϨʔτͰ͖Δ
    • ରԠݴޠ͸͍ͬͺ͍
    • from: [API Reference | Protocol Buffers]

    (https://developers.google.com/protocol-buffers/docs/reference/overview)

    View full-size slide

  8. How to use
    Protocol Buffers in gRPC
    from: [Go Quick Start](https://grpc.io/docs/quickstart/go.html)

    View full-size slide

  9. How to use
    Protocol Buffers in gRPC
    from: [Go Quick Start](https://grpc.io/docs/quickstart/go.html)

    View full-size slide

  10. What is gRPC ?
    from: [What is gRPC?](https://grpc.io/docs/guides/index.html)
    • ਤʹ͢Δͱ͜Μͳײ͡

    View full-size slide

  11. ׬શʹཧղͨ͠
    ʕ◔ϖ◔ʔ͜͜·Ͱ 2 ෼͘Β͍

    View full-size slide

  12. Λ࢖͏ͱԿ͕خ͍͠ͷ ?

    View full-size slide

  13. Advantage of gRPC
    • Single Source of Truth ͷ࣮ݱ
    • ΠϯλϑΣʔε͸શͯ protobufs ʹఆٛ͢Δ
    • protobufs = ׬શͳυΩϡϝϯτ
    • ܕ෇΋͞ΕΔ
    • ϧʔϧΛकΕ͹લํޓ׵, ޙํޓ׵ʹ΋ରԠͰ͖Δ

    (https://developers.google.com/protocol-buffers/docs/proto3#updating)
    • ͲͪΒ͔ͱ͍͑͹ protobufs Λ࢖͏͜ͱʹΑΔخ͠͞
    • Protobufs ͔ΒίʔυΛδΣωϨʔτͯ͠։ൃΛߦ͏
    • υΩϡϝϯτʹهࡌ࿙Ε͕͋ͬͯ…… Έ͍ͨͳͷ͔Βղ์͞ΕΔ
    • REST API ઃܭ͔Β΋ղ์

    View full-size slide

  14. Advantage of gRPC
    • HTTP/2 ͔ΒಘΒΕΔԸܙ
    • ߴύϑΥʔϚϯε
    • HTTP/1 ͷςΩετϓϩτίϧ͔ΒόΠφϦϓϩτίϧʹ
    • సૹ͢Δσʔλྔ͕খ͘͞ͳΔ
    • ߴ଎ͳσʔλղੳ
    • 1ͭͷ TCP ઀ଓʹରͯ͠ଟॏϦΫΤετΛૹΔ͜ͱ͕Ͱ͖Δ
    • ίωΫγϣϯཱ֬ͷΦʔόϔου͕খ͘͞ͳΔ
    • ૒ํ޲ετϦʔϛϯά
    • GCP ͷ API ͱ͔ͩͱ gRPC ͕׆༻͞Ε͍ͯͨΓ͢Δ
    • [gRPC Λհͨ͠ Cloud Pub/Sub: ֓ཁ]

    (https://cloud.google.com/pubsub/grpc-overview?hl=ja)

    View full-size slide

  15. Ͱ΋͍͍͜ͱ͹͔ΓͰ͸
    ͳ͍ΜͰ͠ΐ͏ʁ

    View full-size slide

  16. Disadvantage of gRPC
    • gRPC ͷ API ͸ REST ͷ API ͱͯ͠ίʔϧͰ͖ͳ͍
    • curl ͢ΒͰ͖ͳ͍
    • ϑϩϯτΤϯυ͔ΒݺͿʹ͸……?
    • gRPC ͸ HTTP/2 ͕લఏ
    • ϩʔυόϥϯγϯάͳͲΛߟ͑ͳ͍ͱ͍͚ͳ͍
    • ALB ͷ಺෦௨৴͸ HTTP/2 ඇରԠ
    • CLB ͩͱ L4 ϨΠϠͷϩʔυόϥϯγϯάʹͳͬͯ͠·͏

    View full-size slide

  17. grpc-gateway
    • HTTP/1.1 ͷ API ΛఏڙͰ͖ΔϦόʔεϓϩΩγ
    • protobufs ʹ option ΛՃ͑Δͱ REST ͱ gPRC ͷΫϥΠΞϯτΛ
    ஥հ͢Δ Golang ͷίʔυ͕ੜ੒͞ΕΔ
    • Swagger ΛδΣωϨʔτ͢Δ͜ͱ͕Ͱ͖Δ
    from: [grpc-ecosystem/grpc-gateway](https://github.com/grpc-ecosystem/grpc-gateway)

    View full-size slide

  18. gRPC-Web
    • gRPC ͷΫϥΠΞϯτ͕ϒϥ΢βͰಈ͘
    • protobufs ͔Β JavaScript ͷΫϥΠΞϯτΛδΣωϨʔτ
    • CNCF ͕ GA Λൃදͯͨ͠
    from: [gRPC-Web is going GA](https://www.cncf.io/blog/2018/10/24/grpc-web-is-going-ga/)

    View full-size slide

  19. gRPC-Web
    • ͓΍…… ʁ
    from: [gRPC-Web is going GA](https://www.cncf.io/blog/2018/10/24/grpc-web-is-going-ga/)

    View full-size slide

  20. service proxy …… ?

    View full-size slide

  21. gRPC-Web
    from: [Envoy and gRPC-Web: a fresh new alternative to REST]

    (https://blog.envoyproxy.io/envoy-and-grpc-web-a-fresh-new-alternative-to-rest-6504ce7eb880)
    • ݱ࣮͸͜͏
    • Local Proxy ΛࠓޙͷϩʔυϚοϓͱͯ͠ݕ౼தΒ͍͠

    View full-size slide

  22. gRPC-Web
    from: [ϑϩϯτΤϯυΤϯδχΞ΋஌͓͖͍ͬͯͨgRPC]

    (https://speakerdeck.com/suusan2go/hurontoendoenziniamozhi-tuteokitaigrpc?slide=25)
    • ͜ͷੈքʹͳͬͯ΄͍͠

    View full-size slide

  23. gRPC Load Balancing
    • HTTP/2 ͸1ͭͷίωΫγϣϯͰෳ਺ͷϦΫΤετΛૹΔ
    • L4 ϨΠϠͰϩʔυόϥϯγϯάΛߦ͏ͱίωΫγϣϯ͕੾அ͞ΕΔ·Ͱಉ͡αʔό
    ʹϦΫΤετΛૹͬͯ͠·͏
    • HTTP/2 ʹରԠͨ͠ proxy ͕ඞཁ
    from: [gRPC Load Balancing on Kubernetes without Tears]

    (https://kubernetes.io/blog/2018/11/07/grpc-load-balancing-on-kubernetes-without-tears/)

    View full-size slide

  24. gRPC Load Balancing
    • ϦΫϧʔτ͞Μͷϒϩά͕ΊͬͪΌΑ͔ͬͨ
    from: [EnvoyͱAmazon ECS Service DiscoveryΛར༻ͨ͠gRPCͷෛՙ෼ࢄ]

    (https://tech.recruit-mp.co.jp/infrastructure/post-17098/)

    View full-size slide

  25. ·ͱΊ
    • gPRC ͸͍͍ͧ
    • Ͱ΋Կ΋ߟ͑ͣʹ࠾༻Ͱ͖Δ΋ͷͰ͸ͳ͘ɺ৭ʑ
    ߟྀ͠ͳ͚Ε͹ͳΒͳ͍఺͸ଟʑ͋ΔͷͰ͔ͬ͠
    Γͱௐࠪ, ݕ౼্ͨ͠Ͱ࠾༻͠Α͏
    • gRPC ͷࠓޙʹ͝ظ଴͍ͩ͘͞

    View full-size slide

  26. Enjoy gRPC :)

    View full-size slide