Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

APIdays Helsinki 2019 - gRPC: Lightning Fast, Self-Documenting APIs with Mohammed Ali Chherawalla, Ninja Van

90 visualizaciones

Publicado el

gRPC: Lightning Fast, Self-Documenting APIs, Mohammed Ali Chherawalla, Senior Software Engineer at Ninja Van

Publicado en: Tecnología
  • Sé el primero en comentar

  • Sé el primero en recomendar esto

APIdays Helsinki 2019 - gRPC: Lightning Fast, Self-Documenting APIs with Mohammed Ali Chherawalla, Ninja Van

  1. 1. Lightning Fast, Self-Documenting APIs An overview of HTTP/2, gRPC and its advantages Presented by: Mohammed Ali
  2. 2. ○ What is HTTP/2? ○ Advantages of HTTP/2 ○ What is gRPC? ○ Advantages of gRPC ○ Types of gRPC ○ Building a gRPC service ○ Demo of gRPC in a polyglot microservice architecture ○ Overview Contents
  3. 3. HTTP/2 Source:
  4. 4. What is HTTP/2? ● New version of HTTP. ● Derived from SPDY. ● Primarily focused on performance. ● Same core semantics as HTTP/1.1. ● Results in better UX and faster client applications.
  5. 5. Advantages of HTTP/2 Fully multiplexed Binary Header Compression Server Push Bidirectional Streaming
  6. 6. gRPC Remote Procedure Calls gRPC
  7. 7. gRPC Remote Procedure Calls Uses HTTP/2 Based on protocol buffers Fast & Efficient What is a Remote Procedure Call? ○ invocation of a procedure / method from the client to perform an action on the server What is gRPC? ○ an open source RPC framework developed by google, that uses protobufs
  8. 8. Advantages of gRPC Multi Language and cross platform Protocol Buffers Smaller and Faster Great support DevX + Easy Setup
  9. 9. Types of RPC Unary RPC 1. Login request. 2. Getting details of a single resource, education details for employeeNumber = 10 1 Android Client Go Server Client makes a single request Server responds with a single message
  10. 10. Types of RPC Client Streaming RPC 1. Streaming analytics data. 2. Syncing GPS data. 2 iOS Client Python Server Stream of messages from client Single Message from server after all messages from the client are done
  11. 11. Types of RPC Server Streaming RPC 1. Fetching a list of items that need to displayed on the client 2. Propagation of new data 3 iOS Client Node.js Server Single message from client Streams of messages from server
  12. 12. Types of RPC Bidirectional Streaming RPC 1. Syncing events between services. 2. Chat application 4 Go Client Java Server Streams of messages from client Streams of messages from server
  13. 13. Building a gRPC service 101 Defining a .proto file message Movie { int64 id = 1; string movie_name = 2; string genre = 3; string client_id = 4; } a. Define the type of message that you want to send. b. Tags should not be overridden when writing new features 1
  14. 14. Building a gRPC service 101 Design APIs2 a. Designing and writing your protocol buffer is one of the most important tasks in gRPC b. For designing your API right, your protocol buffer needs to be written very well. service MovieLibrary { // Bidirectional streaming rpc to allow user to get and add movies to collection rpc getAndUpdateMovieLibrary (stream Movie) returns (stream Movie) {} // Client side streaming rpc to allow user to fetch movies from the server rpc listMovies (ListMoviesRequest) returns (stream Movie) {} }
  15. 15. Building a gRPC service 101 Generate server and client stubs using protocol buffer compiler3 ./gradlew build python -m grpc_tools.protoc -I=src/main/proto/ --python_out=clients/python-client/ --grpc_python_out=clients/python-client/ src/main/proto/movie.proto
  16. 16. Building a gRPC service 101 Extend and implement the interfaces created in this .proto in the server class public class MovieService extends MovieLibraryGrpc.MovieLibraryImplBase { @Override public StreamObserver<Movie> getAndUpdateMovieLibrary(StreamObserver<Movie> responseObserver) { // handle returning new stream and updating movie library here } @Override public void listMovies(ListMoviesRequest request, StreamObserver<Movie> responseObserver) { // handle returning new stream here } } 4
  17. 17. gRPC in a polyglot micro-service architecture Java Client NodeJS Client Python Client Java Server
  18. 18. ○ HTTP/2 and its advantages. ○ gRPC, its types and advantages. ○ Building a gRPC service ○ gRPC in a polyglot architecture Key Takeaways The code for the demo can be found at: