SlideShare a Scribd company logo
Alex Borysov
Software Engineer
Enabling Googley microservices with gRPC.
A high performance, open source, HTTP/2-based RPC framework.
Voxxed Days Minsk, May 26, 2018
Google Cloud Platform
Alex Borysov
• Software engineer / tech lead experienced in large scale
software development.
• 12+ years of software engineering experience.
• Active gRPC user.
• devoxx.org.ua program committee member.
@aiborisov
3
devoxx.org.ua
November 23-24, 2018
Kyiv, Ukraine
Save the Date!
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
What is gRPC?
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
What is gRPC?
A high performance, general purpose, feature-rich
RPC framework.
Part of Cloud Native Computing Foundation cncf.io.
HTTP/2 and mobile first.
Open source version of Stubby RPC used in Google.
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
g in gRPC stands for
#VoxxedDaysMinsk
@aiborisov
1.0 'gRPC'
1.1 'good'
1.2 'green'
1.3 'gentle'
. . .
1.9 'glossy'
1.10 'glamorous'
1.11 'gorgeous'
1.12 'glorious'
https://github.com/grpc/grpc/blob/master/doc/g_stands_for.md
Google Cloud Platform
RPC?! But...
#VoxxedDaysMinsk
@aiborisov
AMF?
RMI?
CORBA?
Google Cloud Platform
gRPC is not RMI
#VoxxedDaysMinsk
@aiborisov
Maintainability
Ease of use
Performance
Scalability
L
e
s
s
o
n
s
Years of using Stubby
Google Cloud Platform
What is gRPC?
Abstractions and best practices on how to design
distributed systems.
Default implementation(s) from Google.
Extension points to plug custom implementations and
modifications.
Supports 10+ programming languages
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
What is gRPC?
Abstractions and best practices on how to design
distributed systems.
Default implementation(s) from Google.
Extension points to plug custom implementations and
modifications.
Supports 10+ programming languages, including JS !
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
gRPC vs JSON/HTTP for Google Cloud Pub/Sub
3x increase in throughput
https://cloud.google.com/blog/big-data/2016/03/announcing-grpc-alpha-for-google-cloud-pubsub
11x difference per CPU
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Google ~O(1010
) QPS.
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Google ~O(1010
) QPS.
Your project QPS?
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Continuous Performance Benchmarking
http://www.grpc.io/docs/guides/benchmarking.html
#VoxxedDaysMinsk
@aiborisov
8 core VMs, unary throughput
Google Cloud Platform
Continuous Performance Benchmarking
http://www.grpc.io/docs/guides/benchmarking.html
#VoxxedDaysMinsk
@aiborisov
32 core VMs, unary throughput
Google Cloud Platform
• Single TCP connection.
• No Head-of-line blocking.
• Binary framing layer.
• Header Compression.
HTTP/2 in One Slide
Transport(TCP)
Application (HTTP/2)
Network (IP)
Session (TLS) [optional]
Binary Framing
HEADERS Frame
DATA Frame
HTTP/2
POST: /upload
HTTP/1.1
Host: www.voxxeddays.com
Content-Type: application/json
Content-Length: 27
HTTP/1.x
{“msg”: “Welcome to 2018!”}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
HTTP/1.x vs HTTP/2
http://www.http2demo.io/
https://http2.golang.org/gophertiles
#VoxxedDaysMinsk
@aiborisov
HTTP/1.1 HTTP/2
Google Cloud Platform
Okay, but how?
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Service Definition (weather.proto)
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Service Definition (weather.proto)
syntax = "proto3";
option java_multiple_files = true;
option java_package = "com.voxxeddays.grpcexample" ;
package com.voxxeddays.grpcexample;
service WeatherService {
rpc GetCurrent(WeatherRequest) returns (WeatherResponse);
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Service Definition (weather.proto)
syntax = "proto3";
option java_multiple_files = true;
option java_package = "com.voxxeddays.grpcexample" ;
package com.voxxeddays.grpcexample;
service WeatherService {
rpc GetCurrent(WeatherRequest) returns (WeatherResponse);
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Service Definition (weather.proto)
syntax = "proto3";
service WeatherService {
rpc GetCurrent(WeatherRequest) returns (WeatherResponse);
}
message WeatherRequest {
Coordinates coordinates = 1;
message Coordinates {
fixed64 latitude = 1;
fixed64 longitude = 2;
}
}
message WeatherResponse {
Temperature temperature = 1;
Humidity humidity = 2;
}
message Temperature {
float degrees = 1;
Units units = 2;
enum Units {
FAHRENHEIT = 0;
CELSIUS = 1;
}
}
message Humidity {
float value = 1;
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
#VoxxedDaysMinsk
@aiborisov
Service Definition
weather.proto
gRPC Runtime
Google Cloud Platform
#VoxxedDaysMinsk
@aiborisov
Service Definition
weather.proto
WeatherServiceImplBase.java WeatherRequest.java
WeatherResponse.java
WeatherServiceStub.java
WeatherServiceFutureStub.java
WeatherServiceBlockingStub.java
Service Implementation Request and response Client libraries
gRPC Java runtime
Google Cloud Platform
Implement gRPC Service
public class WeatherService extends WeatherServiceImplBase {
@Override
public void getCurrent(WeatherRequest request,
StreamObserver<WeatherResponse> responseObserver) {
}
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
#VoxxedDaysMinsk
@aiborisov
Thread #X
Thread ...
Thread #7
Thread #6
Thread #5
Thread #4
Thread #3
Thread #2
Thread #1
Thread pool
of size X
Blocking API (aka Thread-per-Request)?
Google Cloud Platform
Blocking API (aka Thread-per-Request)?
#VoxxedDaysMinsk
@aiborisov
Thread #X
Thread ...
Thread #7
Thread #6
Thread #5
Thread #4
Thread #3
Thread #2
Thread #1
Thread pool
of size X
1
Google Cloud Platform
Blocking API (aka Thread-per-Request)?
#VoxxedDaysMinsk
@aiborisov
Thread #X
Thread ...
Thread #7
Thread #6
Thread #5
Thread #4
Thread #3
Thread #2
Thread #1
Thread pool
of size X
1
2
Google Cloud Platform
Blocking API (aka Thread-per-Request)?
#VoxxedDaysMinsk
@aiborisov
Thread #X
Thread ...
Thread #7
Thread #6
Thread #5
Thread #4
Thread #3
Thread #2
Thread #1
Thread pool
of size X
1
2
3
Google Cloud Platform
Blocking API (aka Thread-per-Request)?
#VoxxedDaysMinsk
@aiborisov
Thread #X
Thread ...
Thread #7
Thread #6
Thread #5
Thread #4
Thread #3
Thread #2
Thread #1
Thread pool
of size X
1
2
3
X
. . .
Google Cloud Platform
Blocking API (aka Thread-per-Request)?
#VoxxedDaysMinsk
@aiborisov
Thread #X
Thread ...
Thread #7
Thread #6
Thread #5
Thread #4
Thread #3
Thread #2
Thread #1
Thread pool
of size X
1
2
3
X
. . .
X + 1
Google Cloud Platform
Blocking API (aka Thread-per-Request)?
#VoxxedDaysMinsk
@aiborisov
Thread #X
Thread ...
Thread #7
Thread #6
Thread #5
Thread #4
Thread #3
Thread #2
Thread #1
Thread pool
of size X
1
2
3
X
. . .
X + 1
Google Cloud Platform
Implement gRPC Service
public class WeatherService extends WeatherServiceImplBase {
@Override
public void getCurrent(WeatherRequest request,
StreamObserver<WeatherResponse> responseObserver) {
}
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Implement gRPC Service
public class WeatherService extends WeatherServiceImplBase {
@Override
public void getCurrent(WeatherRequest request,
public interface StreamObserver<WeatherResponse> responseObserver){{
void onNext(WeatherResponse response);
void onCompleted();
void onError(Throwable error);
}
}
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Non-Blocking API
#VoxxedDaysMinsk
@aiborisov
1
2
3
. . .
X + Y
X
. . .
Google Cloud Platform
Non-Blocking API (aka Hollywood Principle)
#VoxxedDaysMinsk
@aiborisov
1
2
3
. . .
X + Y
X
. . .
WillCallYouLater!
Google Cloud Platform
Non-Blocking API
#VoxxedDaysMinsk
@aiborisov
1
2
3
. . .
X + Y
X
. . .
onNext(1)
WillCallYouLater!
Google Cloud Platform
Non-Blocking API
#VoxxedDaysMinsk
@aiborisov
1
2
3
. . .
X + Y
X
. . .
onNext(3)
WillCallYouLater!
Google Cloud Platform
Non-Blocking API
#VoxxedDaysMinsk
@aiborisov
1
2
3
. . .
X + Y
X
. . .
onNext(X)
WillCallYouLater!
Google Cloud Platform
Implement gRPC Service
public class WeatherService extends WeatherServiceImplBase {
@Override
public void getCurrent(WeatherRequest request,
StreamObserver<WeatherResponse> responseObserver) {
}
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Implement gRPC Service
public class WeatherService extends WeatherServiceImplBase {
@Override
public void getCurrent(WeatherRequest request,
StreamObserver<WeatherResponse> responseObserver) {
WeatherResponse response = WeatherResponse.newBuilder()
.setTemperature(Temperature.newBuilder().setUnits(CELSUIS).setDegrees(20.f))
.setHumidity(Humidity.newBuilder().setValue(.65f))
.build();
responseObserver.onNext(response);
responseObserver.onCompleted();
}
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Start gRPC Server
Server grpcServer = NettyServerBuilder.forPort(8090)
.addService(new WeatherService()).build()
.start();
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
gRPC Clients
ManagedChannel grpcChannel = NettyChannelBuilder.forAddress("localhost", 8090).build();
WeatherServiceStub client = WeatherServiceGrpc.newStub(grpcChannel);
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
gRPC Clients
ManagedChannel grpcChannel = NettyChannelBuilder.forAddress("localhost", 8090).build();
WeatherServiceStub client = WeatherServiceGrpc.newStub(grpcChannel);
WeatherServiceBlockingStub blockingClient = WeatherServiceGrpc.newBlockingStub(grpcChannel);
WeatherServiceFutureStub futureClient = WeatherServiceGrpc.newFutureStub(grpcChannel);
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
gRPC Sync Client
WeatherRequest request = WeatherRequest.newBuilder()
.setCoordinates(Coordinates.newBuilder().setLatitude(420000000)
.setLongitude(-720000000)).build();
WeatherResponse response = blockingClient.getCurrent(request);
logger.info("Current weather for {}: {}", request, response);
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
gRPC Async Client
WeatherRequest request = WeatherRequest.newBuilder()
.setCoordinates(Coordinates.newBuilder().setLatitude(504316220)
.setLongitude(305166450)).build();
client.getCurrent(request, new StreamObserver<WeatherResponse>() {
@Override
public void onNext(WeatherResponse response) {
logger.info("Current weather for {}: {}", request, response);
}
@Override
public void onError(Throwable t) { logger.info("Cannot get weather for {}", request); }
@Override
public void onCompleted() { logger.info("Stream completed."); }
});
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Implement gRPC Service
public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase {
@Override
public void getCurrent(WeatherRequest request,
StreamObserver<WeatherResponse> responseObserver) {
WeatherResponse response = WeatherResponse.newBuilder()
.setTemperature(Temperature.newBuilder().setUnits(CELSUIS).setDegrees(20.f))
.setHumidity(Humidity.newBuilder().setValue(.65f))
.build();
responseObserver.onNext(response);
responseObserver.onCompleted();
}
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Adding New [Micro]Services
Weather
Weather
Temp
Wind
Humidity
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Service Definitions
service WeatherService {
rpc GetCurrent(WeatherRequest) returns (WeatherResponse);
}
service TemperatureService {
rpc GetCurrent(Coordinates) returns (Temperature);
}
service HumidityService {
rpc GetCurrent(Coordinates) returns (Humidity);
}
service WindService {
rpc GetCurrent(Coordinates) returns (Wind);
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Service Definition - Response Message
message WeatherResponse {
Temperature temperature = 1;
float humidity = 2;
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Adding New Field
message WeatherResponse {
Temperature temperature = 1;
float humidity = 2;
Wind wind = 3;
}
message Wind {
Speed speed = 1;
float direction = 2;
}
message Speed {
float value = 1;
Units units = 2;
enum Units {
MPH = 0;
MPS = 1;
KNOTS = 2;
KMH = 3;
}
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
private final TemperatureServiceBlockingStub temperatureService;
private final HumidityServiceBlockingStub humidityService;
private final WindServiceBlockingStub windService;
public WeatherService(TemperatureServiceBlockingStub temperatureService,
HumidityServiceBlockingStub humidityService,
WindServiceBlockingStub windService) {
this.temperatureService = temperatureService;
this.humidityService = humidityService;
this.windService = windService;
}
...
Blocking Stub Dependencies
public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase {
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
...
@Override
public void getCurrent(WeatherRequest request,
StreamObserver<WeatherResponse> responseObserver) {
Temperature temperature = temperatureService.getCurrent(request.getCoordinates());
Humidity humidity = humidityService.getCurrent(request.getCoordinates());
Wind wind = windService.getCurrent(request.getCoordinates());
WeatherResponse response = WeatherResponse.newBuilder()
.setTemperature(temperature).setHumidity(humidity).setWind(wind).build();
responseObserver.onNext(response);
responseObserver.onCompleted();
}
}
Blocking Stub Dependencies
public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase {
#VoxxedDaysMinsk
@aiborisov
54
Blocking Stubs
Temp
Humidity
Wind
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
private final TemperatureServiceFutureStub tempService;
private final HumidityServiceFutureStub humidityService;
private final WindServiceFutureStub windService;
public WeatherService(TemperatureServiceFutureStub tempService,
HumidityServiceFutureStub humidityService,
WindServiceFutureStub windService) {
this.tempService = tempService;
this.humidityService = humidityService;
this.windService = windService;
}
...
Async Future Stub Dependencies
public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase {
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
@Override
public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) {
Coordinates coordinates = request.getCoordinates();
ListenableFuture<List<WeatherResponse>> responsesFuture = Futures.allAsList(
Futures.transform(tempService.getCurrent(coordinates),
(Temperature temp) -> WeatherResponse.newBuilder().setTemperature(temp).build()),
Futures.transform(windService.getCurrent(coordinates),
(Wind wind) -> WeatherResponse.newBuilder().setWind(wind).build()),
Futures.transform(humidityService.getCurrent(coordinates),
(Humidity humidity) -> WeatherResponse.newBuilder().setHumidity(humidity).build())
);
...
Async Future Stub Dependencies
public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase {
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
@Override
public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) {
Coordinates coordinates = request.getCoordinates();
ListenableFuture<List<WeatherResponse>> responsesFuture = Futures.allAsList(
Futures.transform(tempService.getCurrent(coordinates),
(Temperature temp) -> WeatherResponse.newBuilder().setTemperature(temp).build()),
Futures.transform(windService.getCurrent(coordinates),
(Wind wind) -> WeatherResponse.newBuilder().setWind(wind).build()),
Futures.transform(humidityService.getCurrent(coordinates),
(Humidity humidity) -> WeatherResponse.newBuilder().setHumidity(humidity).build())
);
...
Async Future Stub Dependencies
public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase {
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
@Override
public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) {
Coordinates coordinates = request.getCoordinates();
ListenableFuture<List<WeatherResponse>> responsesFuture = Futures.allAsList(
Futures.transform(tempService.getCurrent(coordinates),
(Temperature temp) -> WeatherResponse.newBuilder().setTemperature(temp).build()),
Futures.transform(windService.getCurrent(coordinates),
(Wind wind) -> WeatherResponse.newBuilder().setWind(wind).build()),
Futures.transform(humidityService.getCurrent(coordinates),
(Humidity humidity) -> WeatherResponse.newBuilder().setHumidity(humidity).build())
);
...
Async Future Stub Dependencies
public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase {
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
...
Futures.addCallback(responsesFuture, new FutureCallback<List<WeatherResponse>>() {
@Override
public void onSuccess(@Nullable List<WeatherResponse> results) {
WeatherResponse.Builder response = WeatherResponse.newBuilder();
results.forEach(response::mergeFrom);
responseObserver.onNext(response.build());
responseObserver.onCompleted();
}
@Override
public void onFailure(Throwable t) { responseObserver.onError(t); }
});
}
}
Async Future Stub Dependencies
public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase {
@Override
public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) {
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Netty Transport
ManagedChannel grpcChannel = NettyChannelBuilder.forAddress("localhost", 8090).build();
WeatherServiceFutureStub futureClient = WeatherServiceGrpc.newFutureStub(grpcChannel);
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Netty Transport
ManagedChannel grpcChannel = NettyChannelBuilder.forAddress("localhost", 8090).build();
WeatherServiceFutureStub futureClient = WeatherServiceGrpc.newFutureStub(grpcChannel);
Server grpcServer = NettyServerBuilder.forPort(8090)
.addService(new WeatherService()).build().start();
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Netty: Asynchronous and Non-Blocking IO
Netty-based gRPC transport:
• Multiplexes connections on the event loops.
• Decouples I/O waiting from threads.
Request
Event
Loop
Worker thread
Worker thread
Worker thread
Worker thread
Worker thread
Worker thread
Worker thread
Event
Loop
Event
Loop
Event
Loop
Callback
Request
Callback
N
e
t
w
o
r
k
N
e
t
w
o
r
k
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Async Future Stub Dependencies
public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase {
@Override
public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) {
...
Futures.addCallback(responsesFuture, new FutureCallback<List<WeatherResponse>>() {
@Override
public void onSuccess(@Nullable List<WeatherResponse> results) {
WeatherResponse.Builder response = WeatherResponse.newBuilder();
results.forEach(response::mergeFrom);
responseObserver.onNext(response.build());
responseObserver.onCompleted();
}
@Override
public void onFailure(Throwable t) { responseObserver.onError(t); }
});
}
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Async Future Stub Dependencies
public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase {
@Override
public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) {
...
Futures.addCallback(responsesFuture, new FutureCallback<List<WeatherResponse>>() {
@Override
public void onSuccess(@Nullable List<WeatherResponse> results) {
WeatherResponse.Builder response = WeatherResponse.newBuilder();
results.forEach(response::mergeFrom);
responseObserver.onNext(response.build());
responseObserver.onCompleted();
}
@Override
public void onFailure(Throwable t) { responseObserver.onError(t); }
});
}
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Panta rhei, "everything flows".
Heraclitus of Ephesus
~2,400 years Before HTTP/1.x
https://en.wikipedia.org/wiki/Heraclitus
“ ”
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Service Definitions
service WeatherService {
rpc GetCurrent(WeatherRequest) returns (WeatherResponse);
}
service TemperatureService {
rpc GetCurrent(Coordinates) returns (Temperature);
}
service HumidityService {
rpc GetCurrent(Coordinates) returns (Humidity);
}
service WindService {
rpc GetCurrent(Coordinates) returns (Wind);
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Streaming Service Definitions
service WeatherStreamingService {
rpc GetCurrent(WeatherRequest) returns (stream WeatherResponse);
}
service TemperatureStreamingService {
rpc GetCurrent(Coordinates) returns (stream Temperature);
}
service HumidityStreamingService {
rpc GetCurrent(Coordinates) returns (stream Humidity);
}
service WindStreamingService {
rpc GetCurrent(Coordinates) returns (stream Wind);
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Bidirectional Streaming Service Definitions
service WeatherStreamingService {
rpc GetCurrent(stream WeatherRequest) returns (stream WeatherResponse);
}
service TemperatureStreamingService {
rpc GetCurrent(stream Coordinates) returns (stream Temperature);
}
service HumidityStreamingService {
rpc GetCurrent(stream Coordinates) returns (stream Humidity);
}
service WindStreamingService {
rpc GetCurrent(stream Coordinates) returns (stream Wind);
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Bidirectional Streaming Service Definitions
service WeatherStreamingService {
rpc Observe(stream WeatherRequest) returns (stream WeatherResponse);
}
service TemperatureStreamingService {
rpc Observe(stream Coordinates) returns (stream Temperature);
}
service HumidityStreamingService {
rpc Observe(stream Coordinates) returns (stream Humidity);
}
service WindStreamingService {
rpc Observe(stream Coordinates) returns (stream Wind);
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Bidirectional Streaming Service
public class WeatherStreamingService extends WeatherStreamingGrpc.WeatherStreamingImplBase {
...
@Override
public StreamObserver<WeatherRequest> observe(StreamObserver<WeatherResponse> responseObserver) {
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Bidirectional Streaming Service
public class WeatherStreamingService extends WeatherStreamingGrpc.WeatherStreamingImplBase {
...
@Override
public StreamObserver<WeatherRequest> observe(StreamObserver<WeatherResponse> responseObserver) {
StreamObserver<Coordinates> temperatureClientStream =
temperatureService.observe(new StreamObserver<Temperature>() {
@Override
public void onNext(Temperature temperature) {
WeatherResponse resp = WeatherResponse.newBuilder().setTemperature(temperature).build()
responseObserver.onNext(resp);
}
@Override
public void onError(Throwable t) { responseObserver.onError(t); }
@Override
public void onCompleted() { responseObserver.onCompleted(); } });
...
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Bidirectional Streaming Service
public class WeatherStreamingService extends WeatherStreamingGrpc.WeatherStreamingImplBase {
...
@Override
public StreamObserver<WeatherRequest> observe(StreamObserver<WeatherResponse> responseObserver) {
StreamObserver<Coordinates> temperatureClientStream =
temperatureService.observe(new StreamObserver<Temperature>() {
@Override
public void onNext(Temperature temperature) {
WeatherResponse resp = WeatherResponse.newBuilder().setTemperature(temperature).build()
responseObserver.onNext(resp);
}
@Override
public void onError(Throwable t) { responseObserver.onError(t); }
@Override
public void onCompleted() { responseObserver.onCompleted(); } });
...
}
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
return new StreamObserver<WeatherRequest>() {
@Override
public void onNext(WeatherRequest request) {
temperatureClientStream.onNext(request.getCoordinates());
}
@Override
public void onError(Throwable t) { temperatureClientStream.onError(t); }
@Override
public void onCompleted() { temperatureClientStream.onCompleted(); }
};
}
Bidirectional Streaming Service
public class WeatherStreamingService extends WeatherStreamingGrpc.WeatherStreamingImplBase {
...
@Override
public StreamObserver<WeatherRequest> observe(StreamObserver<WeatherResponse> responseObserver) {
StreamObserver<Coordinates> temperatureClientStream = ...
#VoxxedDaysMinsk
@aiborisov
74
Messaging applications.
Games / multiplayer tournaments.
Moving objects.
Sport results.
Stock market quotes.
Smart home devices.
You name it!
Streaming Use-Cases
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Continuous Performance Benchmarking
http://www.grpc.io/docs/guides/benchmarking.html
#VoxxedDaysMinsk
@aiborisov
32 core VMs, streaming throughput
Google Cloud Platform
Continuous Performance Benchmarking
http://www.grpc.io/docs/guides/benchmarking.html
#VoxxedDaysMinsk
@aiborisov
32 core VMs, streaming throughput
Google Cloud Platform
gRPC Speaks Your Language
● Java
● Go
● C/C++
● C#
● Node.js
● PHP
● Ruby
● Python
● Objective-C
● JavaScript
● MacOS
● Linux
● Windows
● Android
● iOS
Service definitions and client libraries Platforms supported
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Interoperability
Java
Service
Python
Service
GoLang
Service
C++
Service
gRPC
Service
gRPC
Stub
gRPC
Stub
gRPC
Stub
gRPC
Stub
gRPC
Service
gRPC
Service
gRPC
Service
gRPC
Stub
#VoxxedDaysMinsk
@aiborisov
#VoxxedDaysMinsk
@aiborisov
Fault Tolerance?
Google Cloud Platform
Use time-outs!
And it will be fine.
“ ”
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Timeouts?
GW
A1 A2 A3
B1 B2 B3
C1 C2 C3
200 ms
?
?
?
? ?
? ?
? ?
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Default Timeout For Every Service?
GW
A1 A2 A3
B1 B2 B3
C1 C2 C3
200 ms
200 ms
200 ms
200 ms
200 ms 200 ms
200 ms 200 ms
200 ms 200 ms
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Default Timeout For Every Service?
Gateway
20 ms 10 ms 10 ms
FastFastFast
30 ms 40 ms 20 ms
130 ms
200 ms
timeout
200 ms
timeout
200 ms
timeout
200 ms
timeout
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Default Timeout For Every Service?
Gateway
30 ms 80 ms 100 ms
SlowFair
210 ms
200 ms
timeout
200 ms
timeout
200 ms
timeout
200 ms
timeout
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Default Timeout For Every Service?
30 ms 80 ms 100 ms
SlowFair
210 ms
200 ms
timeout
200 ms
timeout
200 ms
timeout
200 ms
timeout
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Default Timeout For Every Service?
80 ms 100 ms
SlowFair
200 ms
timeout
200 ms
timeout
200 ms
timeout
200 ms
timeout
Still working!
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Default Timeout For Every Service?
BusyBusy
200 ms
timeout
200 ms
timeout
200 ms
timeout
Idle Busy
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Default Timeout For Every Service?
BusyBusy
200 ms
timeout
200 ms
timeout
200 ms
timeout
Idle Busy
R
e
t
r
y
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Default Timeout For Every Service?
BusyBusy
200 ms
timeout
200 ms
timeout
200 ms
timeout
Idle Busy
R
e
t
r
y
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Default Timeout For Every Service?
200 ms
timeout
200 ms
timeout
200 ms
timeout
R
e
t
r
y
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Tune Timeout For Every Service?
GW
A1 A2 A3
B1 B2 B3
C1 C2 C3
200 ms
190 ms
190 ms
190 ms
110 ms 50 ms
110 ms 50 ms
110 ms 50 ms
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Tune Timeout For Every Service?
Gateway
200 ms
timeout
190 ms
timeout
110 ms
timeout
30 ms 80 ms 25 ms
FastFair
55 ms
Fast
30 ms
50 ms
timeout
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Tune Timeout For Every Service?
Gateway
200 ms
timeout
190 ms
timeout
110 ms
timeout
30 ms 80 ms 25 ms
Fair
55 ms
Fast
30 ms
50 ms
timeout
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
200 ms
timeout
190 ms
timeout
110 ms
timeout
80 ms 25 ms
Fair
55 ms
Fast
30 ms
50 ms
timeout
#JokerConf @aiborisov
30 ms
Waiting
for an RPC
response
Tune Timeout For Every Service?
Google Cloud Platform
Timeouts?
GW
A1 A2 A3
B1 B2 B3
C1 C2 C3
200 ms
?
?
?
? ?
? ?
? ?
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Timeouts for Real World?
GW
A1 A2 A3
B1 B2 B3
C1 C2 C3
200 ms
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Timeouts for Real World?
GW
A1 A2 A3
B1 B2 B3
C1 C2 C3
200 ms
2,500 ms
140 ms
#VoxxedDaysMinsk
@aiborisov
98
Timeouts in gRPC
#VoxxedDaysMinsk
@aiborisov
99
gRPC Java does not support timeouts.
Timeouts in gRPC
#VoxxedDaysMinsk
@aiborisov
100
gRPC Java does not support timeouts.
gRPC supports deadlines instead!
gRPC Deadlines
WeatherResponse response =
client.withDeadlineAfter(200, MILLISECONDS)
.getCurrent(request);
#VoxxedDaysMinsk
@aiborisov
101
First-class feature in gRPC.
Deadline is an absolute point in time.
Deadline indicates to the server how
long the client is willing to wait for an
answer.
RPC will fail with DEADLINE_EXCEEDED
status code when deadline reached.
gRPC Deadlines
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
gRPC Deadline Propagation
Gateway
Now =
1476600000000
Deadline =
1476600000200
Remaining = 200
withDeadlineAfter(200, MILLISECONDS)
DEADLINE_EXCEEDED DEADLINE_EXCEEDED
60 ms
DEADLINE_EXCEEDED
90 ms
DEADLINE_EXCEEDED
60 ms
Now =
1476600000060
Deadline =
1476600000200
Remaining = 140
Now =
1476600000150
Deadline =
1476600000200
Remaining = 50
Now =
1476600000210
Deadline =
1476600000200
Remaining = -10
#VoxxedDaysMinsk
@aiborisov
103
Deadlines are automatically propagated!
Can be accessed by the receiver!
gRPC Deadlines
Context context = Context.current();
context.getDeadline().isExpired();
context.getDeadline()
.timeRemaining(MILLISECONDS);
context.getDeadline().runOnExpiration(() ->
logger.info("Deadline exceeded!"), exec);
#VoxxedDaysMinsk
@aiborisov
104
Deadlines are expected.
What about unpredictable cancellations?
• User cancelled request.
• Caller is not interested in the result any
more.
• etc
Cancellation?
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Cancellation?
GW
Busy Busy Busy
Busy Busy Busy
Busy Busy Busy
RPC
Active RPC Active RPC
Active RPC
Active RPC Active RPCActive RPC
Active RPC Active RPC
Active RPC
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Cancellation?
GW
Busy Busy Busy
Busy Busy Busy
Busy Busy Busy
Active RPC Active RPC
Active RPC
Active RPC Active RPCActive RPC
Active RPC Active RPC
Active RPC
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Cancellation Propagation
GW
Idle Idle Idle
Idle Idle Idle
Idle Idle Idle
#VoxxedDaysMinsk
@aiborisov
108
Automatically propagated.
RPC fails with CANCELLED status code.
Cancellation status can be accessed by
the receiver.
Server (receiver) always knows if RPC is
valid!
gRPC Cancellation
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
gRPC Cancellation
public class WeatherService extends WeatherGrpc.WeatherServiceImplBase {
...
@Override
public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) {
ServerCallStreamObserver<WeatherResponse> streamObserver =
(ServerCallStreamObserver<WeatherResponse>) responseObserver;
streamObserver.isCancelled();
...
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
gRPC Cancellation
public class WeatherService extends WeatherGrpc.WeatherServiceImplBase {
...
@Override
public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) {
ServerCallStreamObserver<WeatherResponse> streamObserver =
(ServerCallStreamObserver<WeatherResponse>) responseObserver;
streamObserver.setOnCancelHandler(() -> {
cleanupResources();
logger.info("Call cancelled by client!");
});
...
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
More Control?
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
BiDi Streaming - Slow Client
Fast Server
Request
Responses
Slow Client
CANCELLED
UNAVAILABLE
RESOURCE_EXHAUSTED
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
BiDi Streaming - Slow Server
Slow Server
Request
Response
Fast Client
CANCELLED
UNAVAILABLE
RESOURCE_EXHAUSTED
Requests
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Client-Side Flow-Control
Server
Request, count = 4
Client
2 Responses
4 Responses
Count = 2
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Server-Side Flow-Control
Server
Request
Client
Response
count = 2
2 Requests
count = 3
3 Requests
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Flow-Control (Client-Side)
CallStreamObserver<WeatherRequest> requestStream =
(CallStreamObserver) client.observe(new ClientResponseObserver<WeatherRequest, WeatherResponse>() {
@Override
public void beforeStart(ClientCallStreamObserver outboundStream) {
outboundStream.disableAutoInboundFlowControl();
}
@Override
public void onNext(WeatherResponse response) { processResponse(response); }
@Override
public void onError(Throwable e) { logger.error("Error on weather request.", e); }
@Override
public void onCompleted() { logger.info("Stream completed."); }
});
requestStream.onNext(request);
requestStream.request(3); // Request up to 3 responses from server
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Flow-Control (Client-Side)
CallStreamObserver<WeatherRequest> requestStream =
(CallStreamObserver) client.observe(new ClientResponseObserver<WeatherRequest, WeatherResponse>() {
@Override
public void beforeStart(ClientCallStreamObserver outboundStream) {
outboundStream.disableAutoInboundFlowControl();
}
@Override
public void onNext(WeatherResponse response) { processResponse(response); }
@Override
public void onError(Throwable e) { logger.error("Error on weather request.", e); }
@Override
public void onCompleted() { logger.info("Stream completed."); }
});
requestStream.onNext(request);
requestStream.request(3); // Request up to 3 responses from server
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Flow-Control (Client-Side)
CallStreamObserver<WeatherRequest> requestStream =
(CallStreamObserver) client.observe(new ClientResponseObserver<WeatherRequest, WeatherResponse>() {
@Override
public void beforeStart(ClientCallStreamObserver outboundStream) {
outboundStream.disableAutoInboundFlowControl();
}
@Override
public void onNext(WeatherResponse response) { processResponse(response); }
@Override
public void onError(Throwable e) { logger.error("Error on weather request.", e); }
@Override
public void onCompleted() { logger.info("Stream completed."); }
});
requestStream.onNext(request);
requestStream.request(3); // Request up to 3 responses from server
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Flow-Control (Client-Side)
CallStreamObserver<WeatherRequest> requestStream =
(CallStreamObserver) client.observe(new ClientResponseObserver<WeatherRequest, WeatherResponse>() {
@Override
public void beforeStart(ClientCallStreamObserver outboundStream) {
outboundStream.disableAutoInboundFlowControl();
}
@Override
public void onNext(WeatherResponse response) { processResponse(response); }
@Override
public void onError(Throwable e) { logger.error("Error on weather request.", e); }
@Override
public void onCompleted() { logger.info("Stream completed."); }
});
requestStream.onNext(request);
requestStream.request(3); // Request up to 3 responses from server
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Flow-Control (Client-Side)
CallStreamObserver<WeatherRequest> requestStream =
(CallStreamObserver) client.observe(new ClientResponseObserver<WeatherRequest, WeatherResponse>() {
@Override
public void beforeStart(ClientCallStreamObserver outboundStream) {
outboundStream.disableAutoInboundFlowControl();
}
@Override
public void onNext(WeatherResponse response) { processResponse(response); }
@Override
public void onError(Throwable e) { logger.error("Error on weather request.", e); }
@Override
public void onCompleted() { logger.info("Stream completed."); }
});
requestStream.onNext(request);
requestStream.request(3); // Request up to 3 responses from server
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Flow-Control (Client-Side)
public class WeatherStreamingService extends WeatherStreamingGrpc.WeatherStreaminServicegImplBase {
...
@Override
public StreamObserver<WeatherRequest> observe(StreamObserver<WeatherResponse> responseObserver) {
ServerCallStreamObserver<WeatherResponse> streamObserver =
(ServerCallStreamObserver<WeatherResponse>) responseObserver;
streamObserver.setOnReadyHandler(() -> {
if (streamObserver.isReady()) {
streamObserver.onNext(calculateWeather());
}
});
...
#VoxxedDaysMinsk
@aiborisov
122
Helps to balance computing power
and network capacity between client
and server.
gRPC supports both client- and
server-side flow control.
Disabled by default.
Flow-Control
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
What else?
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Microservices?! But...
#JokerConf @aiborisov
Performance Hit?
Service Discovery?
Load Balancing?
Fault Tolerance?
Monitoring?
Tracing?
Testing?
Google Cloud Platform
Service Discovery & Load Balancing
HTTP/2
RPC Server-side App
Service Definition
(extends generated definition)
ServerCall handler
TransportTransport
ServerCall
RPC Client-Side App
Channel
Stub
Future
Stub
Blocking
Stub
ClientCall
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
HTTP/2
Service Discovery & Load Balancing
RPC Client-Side App
Instance
#1
Instance
#N
Instance
#2
RPC Server-side Apps
Transport
Channel
Stub
Future
Stub
Blocking
Stub
ClientCall
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Service Discovery & Load Balancing
HTTP/2
RPC Client-Side App
Channel
Stub
Future
Stub
Blocking
Stub
ClientCall
RPC Server-side Apps
Tran #1 Tran #2 Tran #N
Service Definition
(extends generated definition)
ServerCall handler
Transport
ServerCall
NameResolver LoadBalancer
Pluggable
Load
Balancing
and
Service
Discovery
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Service Discovery & Load Balancing
String host = System.getenv("weather_host");
int post = Integer.valueOf(System.getenv("weather_port"));
ManagedChannel grpcChannel = NettyChannelBuilder.forAddress(host, port)
.build();
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Service Discovery & Load Balancing
ManagedChannel grpcChannel = NettyChannelBuilder.forTarget("WeatherSrv")
.build();
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Service Discovery & Load Balancing
ManagedChannel grpcChannel = NettyChannelBuilder.forTarget("WeatherSrv")
.nameResolverFactory(new DnsNameResolverProvider())
.loadBalancerFactory(RoundRobinLoadBalancerFactory.getInstance())
.build();
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Service Discovery & Load Balancing
ManagedChannel grpcChannel = NettyChannelBuilder.forTarget("WeatherSrv")
.nameResolverFactory(new DnsNameResolverProvider())
.loadBalancerFactory(RoundRobinLoadBalancerFactory.getInstance())
.build();
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Service Discovery & Load Balancing
ManagedChannel grpcChannel = NettyChannelBuilder.forTarget("WeatherSrv")
.nameResolverFactory(new MyCustomNameResolverProviderFactory())
.loadBalancerFactory(new MyMoonPhaseLoadBalancerFactory())
.build();
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Testing Support
In-process server transport and client-side channel
StreamRecorder - StreamObserver that records all the observed values and errors.
MetadataUtils for testing metadata headers and trailer.
grpc-testing - utility functions for unit and integration testing:
https://github.com/grpc/grpc-java/tree/master/testing
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Testing Support - InProcess
In-process transport: fully-featured, high performance, and useful in testing.
WeatherServiceAsync weatherService =
new WeatherServiceAsync(tempService, humidityService, windService);
Server grpcServer = InProcessServerBuilder.forName("weather")
.addService(weatherService).build();
Channel grpcChannel = InProcessChannelBuilder.forName("weather").build();
WeatherServiceBlockingStub stub =
WeatherServiceGrpc.newBlockingStub(grpcChannel).withDeadlineAfter(100, MILLISECONDS);
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
More Features
Distributed tracing support:
• OpenTracing, Zipkin / Brave support
Interceptors to add cross-cutting behavior:
• Client- and server-side
Monitoring:
• OpenCensus, gRPC Prometheus; grpcz-monitoring.
Built-in authentication mechanisms:
• SSL/TLS; token-based authentication with Google; authentication API.
Payload compression: https://github.com/grpc/grpc/blob/master/doc/compression.md
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Growing Community and Ecosystem
Your
company could
be here
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Try It Out!
http://grpc.io
gRPC on Github: https://github.com/grpc
Demo: https://github.com/alxbnet/voxxeddays-grpc-demo
Google group: grpc-io@googlegroups.com
gRPC Java quickstart: http://www.grpc.io/docs/quickstart/java.html
gRPC Java tutorial: http://www.grpc.io/docs/tutorials/basic/java.html
gRPC contribution: https://github.com/grpc/grpc-contrib
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Takeaways
gRPC (http://grpc.io):
• HTTP/2 transport based, open source, general purpose
standards-based, feature-rich RPC framework.
• Bidirectional streaming over one single TCP connection.
• Netty transport provides asynchronous and non-blocking I/O.
• Deadline and cancellations propagation.
• Client and server-side flow-control.
• Pluggable service discovery and load-balancing
• Generated client libraries
• Supports 10+ programming languages.
• Build-in testing support.
• Production-ready and growing ecosystem.
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Questions?
#VoxxedDaysMinsk
@aiborisov
Thank You
#VoxxedDaysMinsk
@aiborisov
Google Cloud Platform
Images Used
Special thanks for the provided photos:
• Andrey Borisenko
• Stanislav Vedmid
Photo from https://www.google.com/about/datacenters page:
• https://www.google.com/about/datacenters/gallery/#/tech/12
Photos licenced by Creative Commons 2.0 https://creativecommons.org/licenses/by/2.0/ :
• https://www.flickr.com/photos/garryknight/5754661212/ by Garry Knight
• https://www.flickr.com/photos/sodaigomi/21128888345/ by sodai gomi
• https://www.flickr.com/photos/zengame/15972170944/ by Zengame
• https://www.flickr.com/photos/londonmatt/18496249193/ by Matt Brown
• https://www.flickr.com/photos/gazeronly/8058105980/ by torbakhopper
#VoxxedDaysMinsk
@aiborisov

More Related Content

PDF
"gRPC vs REST: let the battle begin!" OSCON 2018 edition
PDF
gRPC vs REST: let the battle begin!
PDF
gRPC vs REST: let the battle begin!
PDF
"Enabling Googley microservices with gRPC" Riga DevDays 2018 edition
PDF
Devoxx Ukraine 2018 "Break me if you can: practical guide to building fault-t...
PDF
"gRPC vs REST: let the battle begin!" GeeCON Krakow 2018 edition
PDF
"gRPC-Web: It’s All About Communication": Devoxx Ukraine 2019
PDF
"gRPC vs REST: let the battle begin!" DevoxxUK 2018 edition
"gRPC vs REST: let the battle begin!" OSCON 2018 edition
gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!
"Enabling Googley microservices with gRPC" Riga DevDays 2018 edition
Devoxx Ukraine 2018 "Break me if you can: practical guide to building fault-t...
"gRPC vs REST: let the battle begin!" GeeCON Krakow 2018 edition
"gRPC-Web: It’s All About Communication": Devoxx Ukraine 2019
"gRPC vs REST: let the battle begin!" DevoxxUK 2018 edition

What's hot (20)

PDF
Break me if you can: practical guide to building fault-tolerant systems (with...
PDF
"gRPC-Web: It’s All About Communication": Devoxx Belgium 2019
PDF
OSCON 2019 "Break me if you can: practical guide to building fault-tolerant s...
PDF
"gRPC-Web: It’s All About Communication": Devoxx Ukraine 2019
PDF
DevNexus 2020 "Break me if you can: practical guide to building fault-toleran...
PDF
REST API vs gRPC, which one should you use in breaking a monolith [Dev conf 2...
PDF
Cloud Expo Europe 2022 "Break me if you can: practical guide to building faul...
PDF
Curl with rust
PDF
HTTP/3 is next generation HTTP
PDF
common mistakes when using libcurl
PDF
REST API vs gRPC, which one should you use in breaking a monolith [Kdg.net 2018]
PDF
JavaLand gRPC vs REST API
PDF
2018 IterateConf Deconstructing and Evolving REST Security
PDF
curl better
PDF
HTTP/3 in curl
PDF
HTTP/3 for everyone
PDF
Http3 fullstackfest-2019
PDF
HTTP/3 in curl 2020
PDF
Just curl it!
PDF
Technical Product Owner or How to build technical backing for services
Break me if you can: practical guide to building fault-tolerant systems (with...
"gRPC-Web: It’s All About Communication": Devoxx Belgium 2019
OSCON 2019 "Break me if you can: practical guide to building fault-tolerant s...
"gRPC-Web: It’s All About Communication": Devoxx Ukraine 2019
DevNexus 2020 "Break me if you can: practical guide to building fault-toleran...
REST API vs gRPC, which one should you use in breaking a monolith [Dev conf 2...
Cloud Expo Europe 2022 "Break me if you can: practical guide to building faul...
Curl with rust
HTTP/3 is next generation HTTP
common mistakes when using libcurl
REST API vs gRPC, which one should you use in breaking a monolith [Kdg.net 2018]
JavaLand gRPC vs REST API
2018 IterateConf Deconstructing and Evolving REST Security
curl better
HTTP/3 in curl
HTTP/3 for everyone
Http3 fullstackfest-2019
HTTP/3 in curl 2020
Just curl it!
Technical Product Owner or How to build technical backing for services
Ad

Similar to "Enabling Googley microservices with gRPC" VoxxedDays Minsk edition (20)

PDF
Enabling Googley microservices with HTTP/2 and gRPC.
PDF
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...
PDF
Introduction to gRPC - Mete Atamel - Codemotion Rome 2017
PDF
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
PPTX
Microservices summit talk 1/31
PDF
"Enabling Googley microservices with gRPC" at JDK.IO 2017
PPTX
CocoaConf: The Language of Mobile Software is APIs
PPTX
The new (is it really ) api stack
PDF
Usable APIs at Scale
PDF
"Enabling Googley microservices with gRPC" at JEEConf 2017
PDF
"Enabling Googley microservices with gRPC." at Devoxx France 2017
PDF
gRPC - RPC rebirth?
PDF
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
PDF
Creating Great REST and gRPC API Experiences (in Swift)
PDF
From '00s to '20s: from RESTful to gRPC
PPTX
What I learned about APIs in my first year at Google
PDF
gRPC Design and Implementation
PPTX
Introduction to gRPC. Advantages and Disadvantages
PPTX
Introduction to gRPC (Application) Presentation
Enabling Googley microservices with HTTP/2 and gRPC.
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...
Introduction to gRPC - Mete Atamel - Codemotion Rome 2017
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Microservices summit talk 1/31
"Enabling Googley microservices with gRPC" at JDK.IO 2017
CocoaConf: The Language of Mobile Software is APIs
The new (is it really ) api stack
Usable APIs at Scale
"Enabling Googley microservices with gRPC" at JEEConf 2017
"Enabling Googley microservices with gRPC." at Devoxx France 2017
gRPC - RPC rebirth?
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
Creating Great REST and gRPC API Experiences (in Swift)
From '00s to '20s: from RESTful to gRPC
What I learned about APIs in my first year at Google
gRPC Design and Implementation
Introduction to gRPC. Advantages and Disadvantages
Introduction to gRPC (Application) Presentation
Ad

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Approach and Philosophy of On baking technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Spectroscopy.pptx food analysis technology
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Big Data Technologies - Introduction.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Building Integrated photovoltaic BIPV_UPV.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
20250228 LYD VKU AI Blended-Learning.pptx
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
Spectral efficient network and resource selection model in 5G networks
NewMind AI Weekly Chronicles - August'25 Week I
Approach and Philosophy of On baking technology
MIND Revenue Release Quarter 2 2025 Press Release
Agricultural_Statistics_at_a_Glance_2022_0.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Spectroscopy.pptx food analysis technology
Programs and apps: productivity, graphics, security and other tools
Understanding_Digital_Forensics_Presentation.pptx
Empathic Computing: Creating Shared Understanding
Big Data Technologies - Introduction.pptx

"Enabling Googley microservices with gRPC" VoxxedDays Minsk edition

  • 1. Alex Borysov Software Engineer Enabling Googley microservices with gRPC. A high performance, open source, HTTP/2-based RPC framework. Voxxed Days Minsk, May 26, 2018
  • 2. Google Cloud Platform Alex Borysov • Software engineer / tech lead experienced in large scale software development. • 12+ years of software engineering experience. • Active gRPC user. • devoxx.org.ua program committee member. @aiborisov
  • 3. 3 devoxx.org.ua November 23-24, 2018 Kyiv, Ukraine Save the Date! #VoxxedDaysMinsk @aiborisov
  • 4. Google Cloud Platform What is gRPC? #VoxxedDaysMinsk @aiborisov
  • 5. Google Cloud Platform What is gRPC? A high performance, general purpose, feature-rich RPC framework. Part of Cloud Native Computing Foundation cncf.io. HTTP/2 and mobile first. Open source version of Stubby RPC used in Google. #VoxxedDaysMinsk @aiborisov
  • 6. Google Cloud Platform g in gRPC stands for #VoxxedDaysMinsk @aiborisov 1.0 'gRPC' 1.1 'good' 1.2 'green' 1.3 'gentle' . . . 1.9 'glossy' 1.10 'glamorous' 1.11 'gorgeous' 1.12 'glorious' https://github.com/grpc/grpc/blob/master/doc/g_stands_for.md
  • 7. Google Cloud Platform RPC?! But... #VoxxedDaysMinsk @aiborisov AMF? RMI? CORBA?
  • 8. Google Cloud Platform gRPC is not RMI #VoxxedDaysMinsk @aiborisov Maintainability Ease of use Performance Scalability L e s s o n s Years of using Stubby
  • 9. Google Cloud Platform What is gRPC? Abstractions and best practices on how to design distributed systems. Default implementation(s) from Google. Extension points to plug custom implementations and modifications. Supports 10+ programming languages #VoxxedDaysMinsk @aiborisov
  • 10. Google Cloud Platform What is gRPC? Abstractions and best practices on how to design distributed systems. Default implementation(s) from Google. Extension points to plug custom implementations and modifications. Supports 10+ programming languages, including JS ! #VoxxedDaysMinsk @aiborisov
  • 11. Google Cloud Platform gRPC vs JSON/HTTP for Google Cloud Pub/Sub 3x increase in throughput https://cloud.google.com/blog/big-data/2016/03/announcing-grpc-alpha-for-google-cloud-pubsub 11x difference per CPU #VoxxedDaysMinsk @aiborisov
  • 12. Google Cloud Platform Google ~O(1010 ) QPS. #VoxxedDaysMinsk @aiborisov
  • 13. Google Cloud Platform Google ~O(1010 ) QPS. Your project QPS? #VoxxedDaysMinsk @aiborisov
  • 14. Google Cloud Platform Continuous Performance Benchmarking http://www.grpc.io/docs/guides/benchmarking.html #VoxxedDaysMinsk @aiborisov 8 core VMs, unary throughput
  • 15. Google Cloud Platform Continuous Performance Benchmarking http://www.grpc.io/docs/guides/benchmarking.html #VoxxedDaysMinsk @aiborisov 32 core VMs, unary throughput
  • 16. Google Cloud Platform • Single TCP connection. • No Head-of-line blocking. • Binary framing layer. • Header Compression. HTTP/2 in One Slide Transport(TCP) Application (HTTP/2) Network (IP) Session (TLS) [optional] Binary Framing HEADERS Frame DATA Frame HTTP/2 POST: /upload HTTP/1.1 Host: www.voxxeddays.com Content-Type: application/json Content-Length: 27 HTTP/1.x {“msg”: “Welcome to 2018!”} #VoxxedDaysMinsk @aiborisov
  • 17. Google Cloud Platform HTTP/1.x vs HTTP/2 http://www.http2demo.io/ https://http2.golang.org/gophertiles #VoxxedDaysMinsk @aiborisov HTTP/1.1 HTTP/2
  • 18. Google Cloud Platform Okay, but how? #VoxxedDaysMinsk @aiborisov
  • 19. Google Cloud Platform Service Definition (weather.proto) #VoxxedDaysMinsk @aiborisov
  • 20. Google Cloud Platform Service Definition (weather.proto) syntax = "proto3"; option java_multiple_files = true; option java_package = "com.voxxeddays.grpcexample" ; package com.voxxeddays.grpcexample; service WeatherService { rpc GetCurrent(WeatherRequest) returns (WeatherResponse); } #VoxxedDaysMinsk @aiborisov
  • 21. Google Cloud Platform Service Definition (weather.proto) syntax = "proto3"; option java_multiple_files = true; option java_package = "com.voxxeddays.grpcexample" ; package com.voxxeddays.grpcexample; service WeatherService { rpc GetCurrent(WeatherRequest) returns (WeatherResponse); } #VoxxedDaysMinsk @aiborisov
  • 22. Google Cloud Platform Service Definition (weather.proto) syntax = "proto3"; service WeatherService { rpc GetCurrent(WeatherRequest) returns (WeatherResponse); } message WeatherRequest { Coordinates coordinates = 1; message Coordinates { fixed64 latitude = 1; fixed64 longitude = 2; } } message WeatherResponse { Temperature temperature = 1; Humidity humidity = 2; } message Temperature { float degrees = 1; Units units = 2; enum Units { FAHRENHEIT = 0; CELSIUS = 1; } } message Humidity { float value = 1; } #VoxxedDaysMinsk @aiborisov
  • 23. Google Cloud Platform #VoxxedDaysMinsk @aiborisov Service Definition weather.proto gRPC Runtime
  • 24. Google Cloud Platform #VoxxedDaysMinsk @aiborisov Service Definition weather.proto WeatherServiceImplBase.java WeatherRequest.java WeatherResponse.java WeatherServiceStub.java WeatherServiceFutureStub.java WeatherServiceBlockingStub.java Service Implementation Request and response Client libraries gRPC Java runtime
  • 25. Google Cloud Platform Implement gRPC Service public class WeatherService extends WeatherServiceImplBase { @Override public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) { } } #VoxxedDaysMinsk @aiborisov
  • 26. Google Cloud Platform #VoxxedDaysMinsk @aiborisov Thread #X Thread ... Thread #7 Thread #6 Thread #5 Thread #4 Thread #3 Thread #2 Thread #1 Thread pool of size X Blocking API (aka Thread-per-Request)?
  • 27. Google Cloud Platform Blocking API (aka Thread-per-Request)? #VoxxedDaysMinsk @aiborisov Thread #X Thread ... Thread #7 Thread #6 Thread #5 Thread #4 Thread #3 Thread #2 Thread #1 Thread pool of size X 1
  • 28. Google Cloud Platform Blocking API (aka Thread-per-Request)? #VoxxedDaysMinsk @aiborisov Thread #X Thread ... Thread #7 Thread #6 Thread #5 Thread #4 Thread #3 Thread #2 Thread #1 Thread pool of size X 1 2
  • 29. Google Cloud Platform Blocking API (aka Thread-per-Request)? #VoxxedDaysMinsk @aiborisov Thread #X Thread ... Thread #7 Thread #6 Thread #5 Thread #4 Thread #3 Thread #2 Thread #1 Thread pool of size X 1 2 3
  • 30. Google Cloud Platform Blocking API (aka Thread-per-Request)? #VoxxedDaysMinsk @aiborisov Thread #X Thread ... Thread #7 Thread #6 Thread #5 Thread #4 Thread #3 Thread #2 Thread #1 Thread pool of size X 1 2 3 X . . .
  • 31. Google Cloud Platform Blocking API (aka Thread-per-Request)? #VoxxedDaysMinsk @aiborisov Thread #X Thread ... Thread #7 Thread #6 Thread #5 Thread #4 Thread #3 Thread #2 Thread #1 Thread pool of size X 1 2 3 X . . . X + 1
  • 32. Google Cloud Platform Blocking API (aka Thread-per-Request)? #VoxxedDaysMinsk @aiborisov Thread #X Thread ... Thread #7 Thread #6 Thread #5 Thread #4 Thread #3 Thread #2 Thread #1 Thread pool of size X 1 2 3 X . . . X + 1
  • 33. Google Cloud Platform Implement gRPC Service public class WeatherService extends WeatherServiceImplBase { @Override public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) { } } #VoxxedDaysMinsk @aiborisov
  • 34. Google Cloud Platform Implement gRPC Service public class WeatherService extends WeatherServiceImplBase { @Override public void getCurrent(WeatherRequest request, public interface StreamObserver<WeatherResponse> responseObserver){{ void onNext(WeatherResponse response); void onCompleted(); void onError(Throwable error); } } } #VoxxedDaysMinsk @aiborisov
  • 35. Google Cloud Platform Non-Blocking API #VoxxedDaysMinsk @aiborisov 1 2 3 . . . X + Y X . . .
  • 36. Google Cloud Platform Non-Blocking API (aka Hollywood Principle) #VoxxedDaysMinsk @aiborisov 1 2 3 . . . X + Y X . . . WillCallYouLater!
  • 37. Google Cloud Platform Non-Blocking API #VoxxedDaysMinsk @aiborisov 1 2 3 . . . X + Y X . . . onNext(1) WillCallYouLater!
  • 38. Google Cloud Platform Non-Blocking API #VoxxedDaysMinsk @aiborisov 1 2 3 . . . X + Y X . . . onNext(3) WillCallYouLater!
  • 39. Google Cloud Platform Non-Blocking API #VoxxedDaysMinsk @aiborisov 1 2 3 . . . X + Y X . . . onNext(X) WillCallYouLater!
  • 40. Google Cloud Platform Implement gRPC Service public class WeatherService extends WeatherServiceImplBase { @Override public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) { } } #VoxxedDaysMinsk @aiborisov
  • 41. Google Cloud Platform Implement gRPC Service public class WeatherService extends WeatherServiceImplBase { @Override public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) { WeatherResponse response = WeatherResponse.newBuilder() .setTemperature(Temperature.newBuilder().setUnits(CELSUIS).setDegrees(20.f)) .setHumidity(Humidity.newBuilder().setValue(.65f)) .build(); responseObserver.onNext(response); responseObserver.onCompleted(); } } #VoxxedDaysMinsk @aiborisov
  • 42. Google Cloud Platform Start gRPC Server Server grpcServer = NettyServerBuilder.forPort(8090) .addService(new WeatherService()).build() .start(); #VoxxedDaysMinsk @aiborisov
  • 43. Google Cloud Platform gRPC Clients ManagedChannel grpcChannel = NettyChannelBuilder.forAddress("localhost", 8090).build(); WeatherServiceStub client = WeatherServiceGrpc.newStub(grpcChannel); #VoxxedDaysMinsk @aiborisov
  • 44. Google Cloud Platform gRPC Clients ManagedChannel grpcChannel = NettyChannelBuilder.forAddress("localhost", 8090).build(); WeatherServiceStub client = WeatherServiceGrpc.newStub(grpcChannel); WeatherServiceBlockingStub blockingClient = WeatherServiceGrpc.newBlockingStub(grpcChannel); WeatherServiceFutureStub futureClient = WeatherServiceGrpc.newFutureStub(grpcChannel); #VoxxedDaysMinsk @aiborisov
  • 45. Google Cloud Platform gRPC Sync Client WeatherRequest request = WeatherRequest.newBuilder() .setCoordinates(Coordinates.newBuilder().setLatitude(420000000) .setLongitude(-720000000)).build(); WeatherResponse response = blockingClient.getCurrent(request); logger.info("Current weather for {}: {}", request, response); #VoxxedDaysMinsk @aiborisov
  • 46. Google Cloud Platform gRPC Async Client WeatherRequest request = WeatherRequest.newBuilder() .setCoordinates(Coordinates.newBuilder().setLatitude(504316220) .setLongitude(305166450)).build(); client.getCurrent(request, new StreamObserver<WeatherResponse>() { @Override public void onNext(WeatherResponse response) { logger.info("Current weather for {}: {}", request, response); } @Override public void onError(Throwable t) { logger.info("Cannot get weather for {}", request); } @Override public void onCompleted() { logger.info("Stream completed."); } }); #VoxxedDaysMinsk @aiborisov
  • 47. Google Cloud Platform Implement gRPC Service public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase { @Override public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) { WeatherResponse response = WeatherResponse.newBuilder() .setTemperature(Temperature.newBuilder().setUnits(CELSUIS).setDegrees(20.f)) .setHumidity(Humidity.newBuilder().setValue(.65f)) .build(); responseObserver.onNext(response); responseObserver.onCompleted(); } } #VoxxedDaysMinsk @aiborisov
  • 48. Google Cloud Platform Adding New [Micro]Services Weather Weather Temp Wind Humidity #VoxxedDaysMinsk @aiborisov
  • 49. Google Cloud Platform Service Definitions service WeatherService { rpc GetCurrent(WeatherRequest) returns (WeatherResponse); } service TemperatureService { rpc GetCurrent(Coordinates) returns (Temperature); } service HumidityService { rpc GetCurrent(Coordinates) returns (Humidity); } service WindService { rpc GetCurrent(Coordinates) returns (Wind); } #VoxxedDaysMinsk @aiborisov
  • 50. Google Cloud Platform Service Definition - Response Message message WeatherResponse { Temperature temperature = 1; float humidity = 2; } #VoxxedDaysMinsk @aiborisov
  • 51. Google Cloud Platform Adding New Field message WeatherResponse { Temperature temperature = 1; float humidity = 2; Wind wind = 3; } message Wind { Speed speed = 1; float direction = 2; } message Speed { float value = 1; Units units = 2; enum Units { MPH = 0; MPS = 1; KNOTS = 2; KMH = 3; } } #VoxxedDaysMinsk @aiborisov
  • 52. Google Cloud Platform private final TemperatureServiceBlockingStub temperatureService; private final HumidityServiceBlockingStub humidityService; private final WindServiceBlockingStub windService; public WeatherService(TemperatureServiceBlockingStub temperatureService, HumidityServiceBlockingStub humidityService, WindServiceBlockingStub windService) { this.temperatureService = temperatureService; this.humidityService = humidityService; this.windService = windService; } ... Blocking Stub Dependencies public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase { #VoxxedDaysMinsk @aiborisov
  • 53. Google Cloud Platform ... @Override public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) { Temperature temperature = temperatureService.getCurrent(request.getCoordinates()); Humidity humidity = humidityService.getCurrent(request.getCoordinates()); Wind wind = windService.getCurrent(request.getCoordinates()); WeatherResponse response = WeatherResponse.newBuilder() .setTemperature(temperature).setHumidity(humidity).setWind(wind).build(); responseObserver.onNext(response); responseObserver.onCompleted(); } } Blocking Stub Dependencies public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase { #VoxxedDaysMinsk @aiborisov
  • 55. Google Cloud Platform private final TemperatureServiceFutureStub tempService; private final HumidityServiceFutureStub humidityService; private final WindServiceFutureStub windService; public WeatherService(TemperatureServiceFutureStub tempService, HumidityServiceFutureStub humidityService, WindServiceFutureStub windService) { this.tempService = tempService; this.humidityService = humidityService; this.windService = windService; } ... Async Future Stub Dependencies public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase { #VoxxedDaysMinsk @aiborisov
  • 56. Google Cloud Platform @Override public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) { Coordinates coordinates = request.getCoordinates(); ListenableFuture<List<WeatherResponse>> responsesFuture = Futures.allAsList( Futures.transform(tempService.getCurrent(coordinates), (Temperature temp) -> WeatherResponse.newBuilder().setTemperature(temp).build()), Futures.transform(windService.getCurrent(coordinates), (Wind wind) -> WeatherResponse.newBuilder().setWind(wind).build()), Futures.transform(humidityService.getCurrent(coordinates), (Humidity humidity) -> WeatherResponse.newBuilder().setHumidity(humidity).build()) ); ... Async Future Stub Dependencies public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase { #VoxxedDaysMinsk @aiborisov
  • 57. Google Cloud Platform @Override public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) { Coordinates coordinates = request.getCoordinates(); ListenableFuture<List<WeatherResponse>> responsesFuture = Futures.allAsList( Futures.transform(tempService.getCurrent(coordinates), (Temperature temp) -> WeatherResponse.newBuilder().setTemperature(temp).build()), Futures.transform(windService.getCurrent(coordinates), (Wind wind) -> WeatherResponse.newBuilder().setWind(wind).build()), Futures.transform(humidityService.getCurrent(coordinates), (Humidity humidity) -> WeatherResponse.newBuilder().setHumidity(humidity).build()) ); ... Async Future Stub Dependencies public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase { #VoxxedDaysMinsk @aiborisov
  • 58. Google Cloud Platform @Override public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) { Coordinates coordinates = request.getCoordinates(); ListenableFuture<List<WeatherResponse>> responsesFuture = Futures.allAsList( Futures.transform(tempService.getCurrent(coordinates), (Temperature temp) -> WeatherResponse.newBuilder().setTemperature(temp).build()), Futures.transform(windService.getCurrent(coordinates), (Wind wind) -> WeatherResponse.newBuilder().setWind(wind).build()), Futures.transform(humidityService.getCurrent(coordinates), (Humidity humidity) -> WeatherResponse.newBuilder().setHumidity(humidity).build()) ); ... Async Future Stub Dependencies public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase { #VoxxedDaysMinsk @aiborisov
  • 59. Google Cloud Platform ... Futures.addCallback(responsesFuture, new FutureCallback<List<WeatherResponse>>() { @Override public void onSuccess(@Nullable List<WeatherResponse> results) { WeatherResponse.Builder response = WeatherResponse.newBuilder(); results.forEach(response::mergeFrom); responseObserver.onNext(response.build()); responseObserver.onCompleted(); } @Override public void onFailure(Throwable t) { responseObserver.onError(t); } }); } } Async Future Stub Dependencies public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase { @Override public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) { #VoxxedDaysMinsk @aiborisov
  • 60. Google Cloud Platform Netty Transport ManagedChannel grpcChannel = NettyChannelBuilder.forAddress("localhost", 8090).build(); WeatherServiceFutureStub futureClient = WeatherServiceGrpc.newFutureStub(grpcChannel); #VoxxedDaysMinsk @aiborisov
  • 61. Google Cloud Platform Netty Transport ManagedChannel grpcChannel = NettyChannelBuilder.forAddress("localhost", 8090).build(); WeatherServiceFutureStub futureClient = WeatherServiceGrpc.newFutureStub(grpcChannel); Server grpcServer = NettyServerBuilder.forPort(8090) .addService(new WeatherService()).build().start(); #VoxxedDaysMinsk @aiborisov
  • 62. Google Cloud Platform Netty: Asynchronous and Non-Blocking IO Netty-based gRPC transport: • Multiplexes connections on the event loops. • Decouples I/O waiting from threads. Request Event Loop Worker thread Worker thread Worker thread Worker thread Worker thread Worker thread Worker thread Event Loop Event Loop Event Loop Callback Request Callback N e t w o r k N e t w o r k #VoxxedDaysMinsk @aiborisov
  • 63. Google Cloud Platform Async Future Stub Dependencies public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase { @Override public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) { ... Futures.addCallback(responsesFuture, new FutureCallback<List<WeatherResponse>>() { @Override public void onSuccess(@Nullable List<WeatherResponse> results) { WeatherResponse.Builder response = WeatherResponse.newBuilder(); results.forEach(response::mergeFrom); responseObserver.onNext(response.build()); responseObserver.onCompleted(); } @Override public void onFailure(Throwable t) { responseObserver.onError(t); } }); } } #VoxxedDaysMinsk @aiborisov
  • 64. Google Cloud Platform Async Future Stub Dependencies public class WeatherService extends WeatherServiceGrpc.WeatherServiceImplBase { @Override public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) { ... Futures.addCallback(responsesFuture, new FutureCallback<List<WeatherResponse>>() { @Override public void onSuccess(@Nullable List<WeatherResponse> results) { WeatherResponse.Builder response = WeatherResponse.newBuilder(); results.forEach(response::mergeFrom); responseObserver.onNext(response.build()); responseObserver.onCompleted(); } @Override public void onFailure(Throwable t) { responseObserver.onError(t); } }); } } #VoxxedDaysMinsk @aiborisov
  • 65. Google Cloud Platform Panta rhei, "everything flows". Heraclitus of Ephesus ~2,400 years Before HTTP/1.x https://en.wikipedia.org/wiki/Heraclitus “ ” #VoxxedDaysMinsk @aiborisov
  • 66. Google Cloud Platform Service Definitions service WeatherService { rpc GetCurrent(WeatherRequest) returns (WeatherResponse); } service TemperatureService { rpc GetCurrent(Coordinates) returns (Temperature); } service HumidityService { rpc GetCurrent(Coordinates) returns (Humidity); } service WindService { rpc GetCurrent(Coordinates) returns (Wind); } #VoxxedDaysMinsk @aiborisov
  • 67. Google Cloud Platform Streaming Service Definitions service WeatherStreamingService { rpc GetCurrent(WeatherRequest) returns (stream WeatherResponse); } service TemperatureStreamingService { rpc GetCurrent(Coordinates) returns (stream Temperature); } service HumidityStreamingService { rpc GetCurrent(Coordinates) returns (stream Humidity); } service WindStreamingService { rpc GetCurrent(Coordinates) returns (stream Wind); } #VoxxedDaysMinsk @aiborisov
  • 68. Google Cloud Platform Bidirectional Streaming Service Definitions service WeatherStreamingService { rpc GetCurrent(stream WeatherRequest) returns (stream WeatherResponse); } service TemperatureStreamingService { rpc GetCurrent(stream Coordinates) returns (stream Temperature); } service HumidityStreamingService { rpc GetCurrent(stream Coordinates) returns (stream Humidity); } service WindStreamingService { rpc GetCurrent(stream Coordinates) returns (stream Wind); } #VoxxedDaysMinsk @aiborisov
  • 69. Google Cloud Platform Bidirectional Streaming Service Definitions service WeatherStreamingService { rpc Observe(stream WeatherRequest) returns (stream WeatherResponse); } service TemperatureStreamingService { rpc Observe(stream Coordinates) returns (stream Temperature); } service HumidityStreamingService { rpc Observe(stream Coordinates) returns (stream Humidity); } service WindStreamingService { rpc Observe(stream Coordinates) returns (stream Wind); } #VoxxedDaysMinsk @aiborisov
  • 70. Google Cloud Platform Bidirectional Streaming Service public class WeatherStreamingService extends WeatherStreamingGrpc.WeatherStreamingImplBase { ... @Override public StreamObserver<WeatherRequest> observe(StreamObserver<WeatherResponse> responseObserver) { #VoxxedDaysMinsk @aiborisov
  • 71. Google Cloud Platform Bidirectional Streaming Service public class WeatherStreamingService extends WeatherStreamingGrpc.WeatherStreamingImplBase { ... @Override public StreamObserver<WeatherRequest> observe(StreamObserver<WeatherResponse> responseObserver) { StreamObserver<Coordinates> temperatureClientStream = temperatureService.observe(new StreamObserver<Temperature>() { @Override public void onNext(Temperature temperature) { WeatherResponse resp = WeatherResponse.newBuilder().setTemperature(temperature).build() responseObserver.onNext(resp); } @Override public void onError(Throwable t) { responseObserver.onError(t); } @Override public void onCompleted() { responseObserver.onCompleted(); } }); ... } #VoxxedDaysMinsk @aiborisov
  • 72. Google Cloud Platform Bidirectional Streaming Service public class WeatherStreamingService extends WeatherStreamingGrpc.WeatherStreamingImplBase { ... @Override public StreamObserver<WeatherRequest> observe(StreamObserver<WeatherResponse> responseObserver) { StreamObserver<Coordinates> temperatureClientStream = temperatureService.observe(new StreamObserver<Temperature>() { @Override public void onNext(Temperature temperature) { WeatherResponse resp = WeatherResponse.newBuilder().setTemperature(temperature).build() responseObserver.onNext(resp); } @Override public void onError(Throwable t) { responseObserver.onError(t); } @Override public void onCompleted() { responseObserver.onCompleted(); } }); ... } #VoxxedDaysMinsk @aiborisov
  • 73. Google Cloud Platform return new StreamObserver<WeatherRequest>() { @Override public void onNext(WeatherRequest request) { temperatureClientStream.onNext(request.getCoordinates()); } @Override public void onError(Throwable t) { temperatureClientStream.onError(t); } @Override public void onCompleted() { temperatureClientStream.onCompleted(); } }; } Bidirectional Streaming Service public class WeatherStreamingService extends WeatherStreamingGrpc.WeatherStreamingImplBase { ... @Override public StreamObserver<WeatherRequest> observe(StreamObserver<WeatherResponse> responseObserver) { StreamObserver<Coordinates> temperatureClientStream = ... #VoxxedDaysMinsk @aiborisov
  • 74. 74 Messaging applications. Games / multiplayer tournaments. Moving objects. Sport results. Stock market quotes. Smart home devices. You name it! Streaming Use-Cases #VoxxedDaysMinsk @aiborisov
  • 75. Google Cloud Platform Continuous Performance Benchmarking http://www.grpc.io/docs/guides/benchmarking.html #VoxxedDaysMinsk @aiborisov 32 core VMs, streaming throughput
  • 76. Google Cloud Platform Continuous Performance Benchmarking http://www.grpc.io/docs/guides/benchmarking.html #VoxxedDaysMinsk @aiborisov 32 core VMs, streaming throughput
  • 77. Google Cloud Platform gRPC Speaks Your Language ● Java ● Go ● C/C++ ● C# ● Node.js ● PHP ● Ruby ● Python ● Objective-C ● JavaScript ● MacOS ● Linux ● Windows ● Android ● iOS Service definitions and client libraries Platforms supported #VoxxedDaysMinsk @aiborisov
  • 80. Google Cloud Platform Use time-outs! And it will be fine. “ ” #VoxxedDaysMinsk @aiborisov
  • 81. Google Cloud Platform Timeouts? GW A1 A2 A3 B1 B2 B3 C1 C2 C3 200 ms ? ? ? ? ? ? ? ? ? #VoxxedDaysMinsk @aiborisov
  • 82. Google Cloud Platform Default Timeout For Every Service? GW A1 A2 A3 B1 B2 B3 C1 C2 C3 200 ms 200 ms 200 ms 200 ms 200 ms 200 ms 200 ms 200 ms 200 ms 200 ms #VoxxedDaysMinsk @aiborisov
  • 83. Google Cloud Platform Default Timeout For Every Service? Gateway 20 ms 10 ms 10 ms FastFastFast 30 ms 40 ms 20 ms 130 ms 200 ms timeout 200 ms timeout 200 ms timeout 200 ms timeout #VoxxedDaysMinsk @aiborisov
  • 84. Google Cloud Platform Default Timeout For Every Service? Gateway 30 ms 80 ms 100 ms SlowFair 210 ms 200 ms timeout 200 ms timeout 200 ms timeout 200 ms timeout #VoxxedDaysMinsk @aiborisov
  • 85. Google Cloud Platform Default Timeout For Every Service? 30 ms 80 ms 100 ms SlowFair 210 ms 200 ms timeout 200 ms timeout 200 ms timeout 200 ms timeout #VoxxedDaysMinsk @aiborisov
  • 86. Google Cloud Platform Default Timeout For Every Service? 80 ms 100 ms SlowFair 200 ms timeout 200 ms timeout 200 ms timeout 200 ms timeout Still working! #VoxxedDaysMinsk @aiborisov
  • 87. Google Cloud Platform Default Timeout For Every Service? BusyBusy 200 ms timeout 200 ms timeout 200 ms timeout Idle Busy #VoxxedDaysMinsk @aiborisov
  • 88. Google Cloud Platform Default Timeout For Every Service? BusyBusy 200 ms timeout 200 ms timeout 200 ms timeout Idle Busy R e t r y #VoxxedDaysMinsk @aiborisov
  • 89. Google Cloud Platform Default Timeout For Every Service? BusyBusy 200 ms timeout 200 ms timeout 200 ms timeout Idle Busy R e t r y #VoxxedDaysMinsk @aiborisov
  • 90. Google Cloud Platform Default Timeout For Every Service? 200 ms timeout 200 ms timeout 200 ms timeout R e t r y #VoxxedDaysMinsk @aiborisov
  • 91. Google Cloud Platform Tune Timeout For Every Service? GW A1 A2 A3 B1 B2 B3 C1 C2 C3 200 ms 190 ms 190 ms 190 ms 110 ms 50 ms 110 ms 50 ms 110 ms 50 ms #VoxxedDaysMinsk @aiborisov
  • 92. Google Cloud Platform Tune Timeout For Every Service? Gateway 200 ms timeout 190 ms timeout 110 ms timeout 30 ms 80 ms 25 ms FastFair 55 ms Fast 30 ms 50 ms timeout #VoxxedDaysMinsk @aiborisov
  • 93. Google Cloud Platform Tune Timeout For Every Service? Gateway 200 ms timeout 190 ms timeout 110 ms timeout 30 ms 80 ms 25 ms Fair 55 ms Fast 30 ms 50 ms timeout #VoxxedDaysMinsk @aiborisov
  • 94. Google Cloud Platform 200 ms timeout 190 ms timeout 110 ms timeout 80 ms 25 ms Fair 55 ms Fast 30 ms 50 ms timeout #JokerConf @aiborisov 30 ms Waiting for an RPC response Tune Timeout For Every Service?
  • 95. Google Cloud Platform Timeouts? GW A1 A2 A3 B1 B2 B3 C1 C2 C3 200 ms ? ? ? ? ? ? ? ? ? #VoxxedDaysMinsk @aiborisov
  • 96. Google Cloud Platform Timeouts for Real World? GW A1 A2 A3 B1 B2 B3 C1 C2 C3 200 ms #VoxxedDaysMinsk @aiborisov
  • 97. Google Cloud Platform Timeouts for Real World? GW A1 A2 A3 B1 B2 B3 C1 C2 C3 200 ms 2,500 ms 140 ms #VoxxedDaysMinsk @aiborisov
  • 99. 99 gRPC Java does not support timeouts. Timeouts in gRPC #VoxxedDaysMinsk @aiborisov
  • 100. 100 gRPC Java does not support timeouts. gRPC supports deadlines instead! gRPC Deadlines WeatherResponse response = client.withDeadlineAfter(200, MILLISECONDS) .getCurrent(request); #VoxxedDaysMinsk @aiborisov
  • 101. 101 First-class feature in gRPC. Deadline is an absolute point in time. Deadline indicates to the server how long the client is willing to wait for an answer. RPC will fail with DEADLINE_EXCEEDED status code when deadline reached. gRPC Deadlines #VoxxedDaysMinsk @aiborisov
  • 102. Google Cloud Platform gRPC Deadline Propagation Gateway Now = 1476600000000 Deadline = 1476600000200 Remaining = 200 withDeadlineAfter(200, MILLISECONDS) DEADLINE_EXCEEDED DEADLINE_EXCEEDED 60 ms DEADLINE_EXCEEDED 90 ms DEADLINE_EXCEEDED 60 ms Now = 1476600000060 Deadline = 1476600000200 Remaining = 140 Now = 1476600000150 Deadline = 1476600000200 Remaining = 50 Now = 1476600000210 Deadline = 1476600000200 Remaining = -10 #VoxxedDaysMinsk @aiborisov
  • 103. 103 Deadlines are automatically propagated! Can be accessed by the receiver! gRPC Deadlines Context context = Context.current(); context.getDeadline().isExpired(); context.getDeadline() .timeRemaining(MILLISECONDS); context.getDeadline().runOnExpiration(() -> logger.info("Deadline exceeded!"), exec); #VoxxedDaysMinsk @aiborisov
  • 104. 104 Deadlines are expected. What about unpredictable cancellations? • User cancelled request. • Caller is not interested in the result any more. • etc Cancellation? #VoxxedDaysMinsk @aiborisov
  • 105. Google Cloud Platform Cancellation? GW Busy Busy Busy Busy Busy Busy Busy Busy Busy RPC Active RPC Active RPC Active RPC Active RPC Active RPCActive RPC Active RPC Active RPC Active RPC #VoxxedDaysMinsk @aiborisov
  • 106. Google Cloud Platform Cancellation? GW Busy Busy Busy Busy Busy Busy Busy Busy Busy Active RPC Active RPC Active RPC Active RPC Active RPCActive RPC Active RPC Active RPC Active RPC #VoxxedDaysMinsk @aiborisov
  • 107. Google Cloud Platform Cancellation Propagation GW Idle Idle Idle Idle Idle Idle Idle Idle Idle #VoxxedDaysMinsk @aiborisov
  • 108. 108 Automatically propagated. RPC fails with CANCELLED status code. Cancellation status can be accessed by the receiver. Server (receiver) always knows if RPC is valid! gRPC Cancellation #VoxxedDaysMinsk @aiborisov
  • 109. Google Cloud Platform gRPC Cancellation public class WeatherService extends WeatherGrpc.WeatherServiceImplBase { ... @Override public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) { ServerCallStreamObserver<WeatherResponse> streamObserver = (ServerCallStreamObserver<WeatherResponse>) responseObserver; streamObserver.isCancelled(); ... #VoxxedDaysMinsk @aiborisov
  • 110. Google Cloud Platform gRPC Cancellation public class WeatherService extends WeatherGrpc.WeatherServiceImplBase { ... @Override public void getCurrent(WeatherRequest request, StreamObserver<WeatherResponse> responseObserver) { ServerCallStreamObserver<WeatherResponse> streamObserver = (ServerCallStreamObserver<WeatherResponse>) responseObserver; streamObserver.setOnCancelHandler(() -> { cleanupResources(); logger.info("Call cancelled by client!"); }); ... #VoxxedDaysMinsk @aiborisov
  • 111. Google Cloud Platform More Control? #VoxxedDaysMinsk @aiborisov
  • 112. Google Cloud Platform BiDi Streaming - Slow Client Fast Server Request Responses Slow Client CANCELLED UNAVAILABLE RESOURCE_EXHAUSTED #VoxxedDaysMinsk @aiborisov
  • 113. Google Cloud Platform BiDi Streaming - Slow Server Slow Server Request Response Fast Client CANCELLED UNAVAILABLE RESOURCE_EXHAUSTED Requests #VoxxedDaysMinsk @aiborisov
  • 114. Google Cloud Platform Client-Side Flow-Control Server Request, count = 4 Client 2 Responses 4 Responses Count = 2 #VoxxedDaysMinsk @aiborisov
  • 115. Google Cloud Platform Server-Side Flow-Control Server Request Client Response count = 2 2 Requests count = 3 3 Requests #VoxxedDaysMinsk @aiborisov
  • 116. Google Cloud Platform Flow-Control (Client-Side) CallStreamObserver<WeatherRequest> requestStream = (CallStreamObserver) client.observe(new ClientResponseObserver<WeatherRequest, WeatherResponse>() { @Override public void beforeStart(ClientCallStreamObserver outboundStream) { outboundStream.disableAutoInboundFlowControl(); } @Override public void onNext(WeatherResponse response) { processResponse(response); } @Override public void onError(Throwable e) { logger.error("Error on weather request.", e); } @Override public void onCompleted() { logger.info("Stream completed."); } }); requestStream.onNext(request); requestStream.request(3); // Request up to 3 responses from server #VoxxedDaysMinsk @aiborisov
  • 117. Google Cloud Platform Flow-Control (Client-Side) CallStreamObserver<WeatherRequest> requestStream = (CallStreamObserver) client.observe(new ClientResponseObserver<WeatherRequest, WeatherResponse>() { @Override public void beforeStart(ClientCallStreamObserver outboundStream) { outboundStream.disableAutoInboundFlowControl(); } @Override public void onNext(WeatherResponse response) { processResponse(response); } @Override public void onError(Throwable e) { logger.error("Error on weather request.", e); } @Override public void onCompleted() { logger.info("Stream completed."); } }); requestStream.onNext(request); requestStream.request(3); // Request up to 3 responses from server #VoxxedDaysMinsk @aiborisov
  • 118. Google Cloud Platform Flow-Control (Client-Side) CallStreamObserver<WeatherRequest> requestStream = (CallStreamObserver) client.observe(new ClientResponseObserver<WeatherRequest, WeatherResponse>() { @Override public void beforeStart(ClientCallStreamObserver outboundStream) { outboundStream.disableAutoInboundFlowControl(); } @Override public void onNext(WeatherResponse response) { processResponse(response); } @Override public void onError(Throwable e) { logger.error("Error on weather request.", e); } @Override public void onCompleted() { logger.info("Stream completed."); } }); requestStream.onNext(request); requestStream.request(3); // Request up to 3 responses from server #VoxxedDaysMinsk @aiborisov
  • 119. Google Cloud Platform Flow-Control (Client-Side) CallStreamObserver<WeatherRequest> requestStream = (CallStreamObserver) client.observe(new ClientResponseObserver<WeatherRequest, WeatherResponse>() { @Override public void beforeStart(ClientCallStreamObserver outboundStream) { outboundStream.disableAutoInboundFlowControl(); } @Override public void onNext(WeatherResponse response) { processResponse(response); } @Override public void onError(Throwable e) { logger.error("Error on weather request.", e); } @Override public void onCompleted() { logger.info("Stream completed."); } }); requestStream.onNext(request); requestStream.request(3); // Request up to 3 responses from server #VoxxedDaysMinsk @aiborisov
  • 120. Google Cloud Platform Flow-Control (Client-Side) CallStreamObserver<WeatherRequest> requestStream = (CallStreamObserver) client.observe(new ClientResponseObserver<WeatherRequest, WeatherResponse>() { @Override public void beforeStart(ClientCallStreamObserver outboundStream) { outboundStream.disableAutoInboundFlowControl(); } @Override public void onNext(WeatherResponse response) { processResponse(response); } @Override public void onError(Throwable e) { logger.error("Error on weather request.", e); } @Override public void onCompleted() { logger.info("Stream completed."); } }); requestStream.onNext(request); requestStream.request(3); // Request up to 3 responses from server #VoxxedDaysMinsk @aiborisov
  • 121. Google Cloud Platform Flow-Control (Client-Side) public class WeatherStreamingService extends WeatherStreamingGrpc.WeatherStreaminServicegImplBase { ... @Override public StreamObserver<WeatherRequest> observe(StreamObserver<WeatherResponse> responseObserver) { ServerCallStreamObserver<WeatherResponse> streamObserver = (ServerCallStreamObserver<WeatherResponse>) responseObserver; streamObserver.setOnReadyHandler(() -> { if (streamObserver.isReady()) { streamObserver.onNext(calculateWeather()); } }); ... #VoxxedDaysMinsk @aiborisov
  • 122. 122 Helps to balance computing power and network capacity between client and server. gRPC supports both client- and server-side flow control. Disabled by default. Flow-Control #VoxxedDaysMinsk @aiborisov
  • 123. Google Cloud Platform What else? #VoxxedDaysMinsk @aiborisov
  • 124. Google Cloud Platform Microservices?! But... #JokerConf @aiborisov Performance Hit? Service Discovery? Load Balancing? Fault Tolerance? Monitoring? Tracing? Testing?
  • 125. Google Cloud Platform Service Discovery & Load Balancing HTTP/2 RPC Server-side App Service Definition (extends generated definition) ServerCall handler TransportTransport ServerCall RPC Client-Side App Channel Stub Future Stub Blocking Stub ClientCall #VoxxedDaysMinsk @aiborisov
  • 126. Google Cloud Platform HTTP/2 Service Discovery & Load Balancing RPC Client-Side App Instance #1 Instance #N Instance #2 RPC Server-side Apps Transport Channel Stub Future Stub Blocking Stub ClientCall #VoxxedDaysMinsk @aiborisov
  • 127. Google Cloud Platform Service Discovery & Load Balancing HTTP/2 RPC Client-Side App Channel Stub Future Stub Blocking Stub ClientCall RPC Server-side Apps Tran #1 Tran #2 Tran #N Service Definition (extends generated definition) ServerCall handler Transport ServerCall NameResolver LoadBalancer Pluggable Load Balancing and Service Discovery #VoxxedDaysMinsk @aiborisov
  • 128. Google Cloud Platform Service Discovery & Load Balancing String host = System.getenv("weather_host"); int post = Integer.valueOf(System.getenv("weather_port")); ManagedChannel grpcChannel = NettyChannelBuilder.forAddress(host, port) .build(); #VoxxedDaysMinsk @aiborisov
  • 129. Google Cloud Platform Service Discovery & Load Balancing ManagedChannel grpcChannel = NettyChannelBuilder.forTarget("WeatherSrv") .build(); #VoxxedDaysMinsk @aiborisov
  • 130. Google Cloud Platform Service Discovery & Load Balancing ManagedChannel grpcChannel = NettyChannelBuilder.forTarget("WeatherSrv") .nameResolverFactory(new DnsNameResolverProvider()) .loadBalancerFactory(RoundRobinLoadBalancerFactory.getInstance()) .build(); #VoxxedDaysMinsk @aiborisov
  • 131. Google Cloud Platform Service Discovery & Load Balancing ManagedChannel grpcChannel = NettyChannelBuilder.forTarget("WeatherSrv") .nameResolverFactory(new DnsNameResolverProvider()) .loadBalancerFactory(RoundRobinLoadBalancerFactory.getInstance()) .build(); #VoxxedDaysMinsk @aiborisov
  • 132. Google Cloud Platform Service Discovery & Load Balancing ManagedChannel grpcChannel = NettyChannelBuilder.forTarget("WeatherSrv") .nameResolverFactory(new MyCustomNameResolverProviderFactory()) .loadBalancerFactory(new MyMoonPhaseLoadBalancerFactory()) .build(); #VoxxedDaysMinsk @aiborisov
  • 133. Google Cloud Platform Testing Support In-process server transport and client-side channel StreamRecorder - StreamObserver that records all the observed values and errors. MetadataUtils for testing metadata headers and trailer. grpc-testing - utility functions for unit and integration testing: https://github.com/grpc/grpc-java/tree/master/testing #VoxxedDaysMinsk @aiborisov
  • 134. Google Cloud Platform Testing Support - InProcess In-process transport: fully-featured, high performance, and useful in testing. WeatherServiceAsync weatherService = new WeatherServiceAsync(tempService, humidityService, windService); Server grpcServer = InProcessServerBuilder.forName("weather") .addService(weatherService).build(); Channel grpcChannel = InProcessChannelBuilder.forName("weather").build(); WeatherServiceBlockingStub stub = WeatherServiceGrpc.newBlockingStub(grpcChannel).withDeadlineAfter(100, MILLISECONDS); #VoxxedDaysMinsk @aiborisov
  • 135. Google Cloud Platform More Features Distributed tracing support: • OpenTracing, Zipkin / Brave support Interceptors to add cross-cutting behavior: • Client- and server-side Monitoring: • OpenCensus, gRPC Prometheus; grpcz-monitoring. Built-in authentication mechanisms: • SSL/TLS; token-based authentication with Google; authentication API. Payload compression: https://github.com/grpc/grpc/blob/master/doc/compression.md #VoxxedDaysMinsk @aiborisov
  • 136. Google Cloud Platform Growing Community and Ecosystem Your company could be here #VoxxedDaysMinsk @aiborisov
  • 137. Google Cloud Platform Try It Out! http://grpc.io gRPC on Github: https://github.com/grpc Demo: https://github.com/alxbnet/voxxeddays-grpc-demo Google group: grpc-io@googlegroups.com gRPC Java quickstart: http://www.grpc.io/docs/quickstart/java.html gRPC Java tutorial: http://www.grpc.io/docs/tutorials/basic/java.html gRPC contribution: https://github.com/grpc/grpc-contrib #VoxxedDaysMinsk @aiborisov
  • 138. Google Cloud Platform Takeaways gRPC (http://grpc.io): • HTTP/2 transport based, open source, general purpose standards-based, feature-rich RPC framework. • Bidirectional streaming over one single TCP connection. • Netty transport provides asynchronous and non-blocking I/O. • Deadline and cancellations propagation. • Client and server-side flow-control. • Pluggable service discovery and load-balancing • Generated client libraries • Supports 10+ programming languages. • Build-in testing support. • Production-ready and growing ecosystem. #VoxxedDaysMinsk @aiborisov
  • 141. Google Cloud Platform Images Used Special thanks for the provided photos: • Andrey Borisenko • Stanislav Vedmid Photo from https://www.google.com/about/datacenters page: • https://www.google.com/about/datacenters/gallery/#/tech/12 Photos licenced by Creative Commons 2.0 https://creativecommons.org/licenses/by/2.0/ : • https://www.flickr.com/photos/garryknight/5754661212/ by Garry Knight • https://www.flickr.com/photos/sodaigomi/21128888345/ by sodai gomi • https://www.flickr.com/photos/zengame/15972170944/ by Zengame • https://www.flickr.com/photos/londonmatt/18496249193/ by Matt Brown • https://www.flickr.com/photos/gazeronly/8058105980/ by torbakhopper #VoxxedDaysMinsk @aiborisov