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
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.
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. Advantages of gRPC
Multi Language and cross platform Protocol Buffers
Smaller and Faster Great support
DevX + Easy Setup
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. 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. 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. 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. 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. 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. 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. 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. gRPC in a polyglot micro-service architecture
Java
Client
NodeJS
Client
Python
Client
Java
Server
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:
https://github.com/alichherawalla/grpc-movie-client-server