gRPC with Node.js

0a8f40c6cc23fb6c8aad4de732c5abaf?s=47 Lucas Santos
September 16, 2020

gRPC with Node.js

0a8f40c6cc23fb6c8aad4de732c5abaf?s=128

Lucas Santos

September 16, 2020
Tweet

Transcript

  1. gRPC with Node.js maybe it's time to put ReST to

    rest
  2. blog.lsantos.dev cloud advocate_ who am I_ ludossan@microsoft.com

  3. What is gRPC?

  4. gRPC - Developed by Google in 2015 - Uses HTTP/2

    for transport - RPC stands for "remote procedure call" - Directly calls a method on the server as if it were a local object - Uses protobuf as IDL - Interoperable among languages
  5. None
  6. RPC is NOT new

  7. JRMI - Java Remote Method Invocation Client Remote object Interface

    Stub Remote Object Implementation Remote object Interface Skeleton Client Server Implemented by the developer Implemented by JRMI
  8. Protocol Buffers protobuf for the bffs <3

  9. protobuf - OSS, Developed by Google - Mechanism for serializing

    structured data - Interface Definition Language - Requires compiling
  10. message.proto

  11. Compile time!

  12. Outfile

  13. message_pb.js

  14. Generated Methods

  15. Then we can just use

  16. gRPC != Protobuf

  17. Protobuf is universal_

  18. None
  19. gRPC is based on services_

  20. Defining a service

  21. Defining a service

  22. Types of methods_

  23. Unary

  24. Server Streaming

  25. Client Streaming

  26. Bidirectional

  27. Building the server with NodeJS

  28. Install grpc

  29. One small change

  30. Load the protofile

  31. Load the protofile "Database"

  32. Implement the functions on the serverside

  33. Implement the functions on the serverside

  34. Start the server

  35. Full code

  36. Full code load

  37. Full code load database

  38. Full code load database implementation

  39. Full code load database implementation run

  40. Creating the client

  41. Install grpc

  42. Load the protofile

  43. Add the service

  44. Call it!

  45. Full Code

  46. DEMO

  47. Problems - Docs are not very common - The initial

    development is more complex - Usage with TypeScript requires some work - It is a bit complicated to understand the idea and concepts
  48. Advantages of gRPC - Way smaller due to binary transfer

    - HTTP/2 by default - Simple client calls - Lighter and supports a lot of calls - Supports streaming both in client and server - Protobuf standardizes the message exchange
  49. Comparison

  50. refs_ - https://en.wikipedia.org/wiki/Remote_procedure_call - https://grpc.io/docs/what-is-grpc/introduction/ - https://developers.google.com/protocol-buffers - https://developers.google.com/protocol-buffers/docs/reference/javascript-generated -

    https://medium.com/xp-inc/introdu%C3%A7%C3%A3o-ao-grpc-com-node-js-98f6a4ede11 - https://grpc.io/docs/what-is-grpc/core-concepts/ - https://blog.logrocket.com/creating-a-crud-api-with-node-express-and-grpc/ - https://github.com/khaosdoctor/grpc-nodejs-demo-app
  51. /khaosdoctor @_staticvoid lsantos.dev /khaosdoctor thank you_