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

gRPC vs REST - API Strat 2016

gRPC vs REST - API Strat 2016

Comparing gRPC and REST for building an Microservices API.

Tweet at @sandeepdinesh for more info!

365bbc53688d2cceb72e296acf7f65ee?s=128

Sandeep Dinesh

November 03, 2016
Tweet

More Decks by Sandeep Dinesh

Other Decks in Technology

Transcript

  1. Sandeep Dinesh Developer Advocate @sandeepdinesh vs {REST}

  2. @sandeepdinesh Who has heard of gRPC?

  3. @sandeepdinesh Who is using gRPC?

  4. @sandeepdinesh Who is using gRPC?

  5. 5 gRPC REST

  6. 6 gRPC REST

  7. @sandeepdinesh gRPC is basically Protobuf over HTTP/2 POST

  8. @sandeepdinesh REST is basically JSON over HTTP 1.1

  9. @sandeepdinesh JSON → Protobuf HTTP 1.1→ HTTP/2

  10. @sandeepdinesh JSON vs Protobuf plaintext vs binary human readable vs

    machine readable repetitive vs compressed fast (de)serialization vs faster (de)serialization* Everything supports it vs limited support
  11. @sandeepdinesh HTTP 1.1 vs. HTTP/2 plaintext vs binary no pipelining

    vs native pipelining new connection per request vs persistent TCP connection repetitive vs compressed polling vs streaming Non-secure by default vs TLS by default Everything supports it vs limited support
  12. @sandeepdinesh Let’s Benchmark!

  13. @sandeepdinesh

  14. @sandeepdinesh

  15. @sandeepdinesh

  16. @sandeepdinesh us-west1-a us-east1-c Data B46 Data B64

  17. @sandeepdinesh Make 10,000 “Simultaneous Requests” See how fast the server

    can process them all
  18. @sandeepdinesh https://commons.wikimedia.org/wiki/File:Rabbit_Looks_Surprised_by_Monique_Haen.jpg Rabbit Hole

  19. @sandeepdinesh Three endpoints REST Non-Streaming gRPC Bidirectional Streaming gRPC Fast?

    Faster? Fastest?
  20. @sandeepdinesh us-west1-a us-east1-c Node.js Client Node.js Server

  21. @sandeepdinesh Node.js is async, but single threaded Go has true

    multithreading
  22. @sandeepdinesh Node.js uses a C driver for gRPC Go uses

    a native Go driver
  23. @sandeepdinesh us-west1-a us-east1-c Go Client Go Server Node.js Client Node.js

    Server
  24. @sandeepdinesh BENCHMARKS https://public.tableau.com/shared/N4YBPFJ7W?:display_count=yes

  25. @sandeepdinesh us-west1-a us-east1-c 1

  26. @sandeepdinesh us-west1-a us-east1-c 2

  27. @sandeepdinesh us-west1-a us-east1-c 2

  28. @sandeepdinesh us-west1-a us-east1-c 3

  29. @sandeepdinesh Make 10,000 Ping-Pongs over the “same” connection

  30. @sandeepdinesh Cheating!

  31. @sandeepdinesh 12 Server Methods 12 Client Methods 2 Languages 3

    Datacenters
  32. @sandeepdinesh gRPC is consistently faster

  33. @sandeepdinesh Introducing gRPC into your microservices

  34. @sandeepdinesh Clients REST Server v1 REST Server v2 gRPC Server

    v3 REST REST gRPC??? WTF MATE?
  35. @sandeepdinesh 1) Force clients to upgrade or use the old

    service 2) Create gRPC and REST endpoints for the new service
  36. @sandeepdinesh 1) Force clients to upgrade or use the old

    service 2) Create gRPC and REST endpoints for the new service https://commons.wikimedia.org/wiki/File:Carrot-fb.jpg https://pixabay.com/en/photos/wooden%20stick/ >
  37. @sandeepdinesh message Person { enum PhoneType { MOBILE = 0;

    HOME = 1; WORK = 2; } message PhoneNumber { string number = 1; PhoneType type = 2; } string name = 1; int32 id = 2; string email = 3; repeated PhoneNumber phone = 4; } { "name": "‘Sandeep’", "id": 123, "email": "‘a@b.com’", "phone": [ { "number": 1234566543, "type": "‘HOME’" }, { "number": 1234566545, "type": "‘MOBILE’" } ] }
  38. @sandeepdinesh gRPC Gateway!

  39. @sandeepdinesh

  40. @sandeepdinesh syntax = "proto3"; package pingpong; service PingPong { rpc

    SyncPerson (Person) returns (Base64) {} }
  41. @sandeepdinesh syntax = "proto3"; package pingpong; import "google/api/annotations.proto"; service PingPong

    { rpc SyncPerson (Person) returns (Base64) { option (google.api.http) = { post: "/addperson" body: "*" }; } }
  42. @sandeepdinesh

  43. @sandeepdinesh Bonus: Swagger!

  44. @sandeepdinesh REST isn’t “dead”

  45. @sandeepdinesh gRPC give you additional capabilities like streaming, consistency, and

    tooling
  46. @sandeepdinesh gRPC Gateway is an easy way to provide backwards

    compatibility
  47. @sandeepdinesh

  48. @sandeepdinesh Use HTTP/2 There is no excuse!

  49. @sandeepdinesh Thanks! gRPC: grpc.io gRPC Gateway: github.com/grpc-ecosystem/grpc-gateway Benchmark Charts: public.tableau.com/profile/sandeep.dinesh