gRPC: Beyond REST
history repeats itself infinitely
About me
• JVM developer since 1998
• Cofounder @ CirculoSiete
• Staff @ JVM Mexico City
• @domix
History
• Lupine. Powered Courier by XEROX (1981)
• Bruce Jay Nelson coined the term ‘RPC’
• SUN’s RPC (ONC RPC) ~NFS
• CORBA (1991)
• RMI
• Burlap/Hessian
gRPC?
• Stands for ‘gRPC Remote Procedure Call’
• Open source project from Google hosted by the Cloud Native Computing
Foundation
• High Performance, general purpose standard base, RPC framework.
• Open sourced of ‘Stubby RPC’ at Google
Why gRPC?
• We already have REST|GraphQL, why?
• Maybe performance?
• https://goo.gl/yM7XPM
• https://goo.gl/oYY8dr
• https://goo.gl/TtzXad
• Contract first approach
• Multi platform
Performance
• HTTP/2
• Single TCP connection
• Binary framing layer
• Header compression
• Persistent connections
• http://www.http2demo.io
Contract first approach
Protocol Buffers
• Protocol buffers are a flexible, efficient, automated
mechanism for serializing structured data, smaller, faster,
and simpler than XML or JSON.
• You can update your data structure without breaking
deployed programs.
• Language/platform agnostic.
• You have to write a definition in a text file ‘.proto’.
• A compiler is needed to generate the desired source code.
syntax = "proto3";
package com.circulosiete.cursos.k8s;
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto";
import "google/api/annotations.proto";
option java_multiple_files = true;
option go_package = "warehouse";
message PageProductResponse {
google.protobuf.BoolValue first = 1; //unique numbered tag: 1
google.protobuf.BoolValue last = 2; //unique numbered tag: 2
google.protobuf.Int32Value number = 3; //unique numbered tag: 3
google.protobuf.Int32Value numberOfElements = 4; //unique numbered tag: 4
google.protobuf.Int32Value size = 5; //unique numbered tag: 5
google.protobuf.Int64Value totalElements = 6; //unique numbered tag: 6
google.protobuf.Int32Value totalPages = 7; //unique numbered tag: 7
repeated ProductModel content = 8;
}
message ProductModel {
int64 id = 1;
string name = 2;
string description = 3;
string price = 4;
google.protobuf.Timestamp createdAt = 5;
google.protobuf.Timestamp modifiedDate = 6;
int64 version = 7;
}
Contract!
service ProductService {
rpc Create (ProductRequest) returns (ProductResponse);
rpc Read (EntityId) returns (ProductResponse);
rpc Update (ProductModel) returns (ProductResponse);
rpc Delete (EntityId) returns (ProductResponse);
rpc Paged (Page) returns (PageProductResponse);
rpc List (Page) returns (stream ProductResponse);
}
service ValidacionService {
rpc ValidacionCreate (CreateRequest) returns (ValidacionResponse);
rpc ValidacionDelete (EntityId) returns (ValidacionResponse);
}
Multiplatform
gRPC compiler
• Takes proto files then generates specific source files
• It supports several plugins, for different programming languages
• It generates Server files, client files.
JVM
• Netty Powered!
• Gradle and Maven support
• Spring Boot community support
Live Coding!
gRPC intro demo
What about REST?
REST and gRPC
• REST is still necessary
• JavaScript applications
• Web Browser
• We can reuse our gRPC endpoints in REST
• https://github.com/grpc-ecosystem/grpc-gateway
gRPC gateway
• For now only supports Go Lang
• We have to use some Google Annotations
• The good
• Fast as hell!
• The Ugly
• Sometimes the Go Lang dev env is difficult to setup
Live Coding!
gRPC complete demo
Contact
• @domix
• domingo.suarez@gmail.com
• http://slideshare.net/domingo.suarez
Photos
• https://unsplash.com/photos/_cb5MjNG3DI
• https://unsplash.com/photos/1qkyck-UL3g
• https://unsplash.com/photos/w7ZyuGYNpRQ
• https://unsplash.com/photos/YucYLQ6Dm8A

gRPC: Beyond REST

  • 1.
    gRPC: Beyond REST historyrepeats itself infinitely
  • 2.
    About me • JVMdeveloper since 1998 • Cofounder @ CirculoSiete • Staff @ JVM Mexico City • @domix
  • 3.
    History • Lupine. PoweredCourier by XEROX (1981) • Bruce Jay Nelson coined the term ‘RPC’ • SUN’s RPC (ONC RPC) ~NFS • CORBA (1991) • RMI • Burlap/Hessian
  • 4.
    gRPC? • Stands for‘gRPC Remote Procedure Call’ • Open source project from Google hosted by the Cloud Native Computing Foundation • High Performance, general purpose standard base, RPC framework. • Open sourced of ‘Stubby RPC’ at Google
  • 5.
    Why gRPC? • Wealready have REST|GraphQL, why? • Maybe performance? • https://goo.gl/yM7XPM • https://goo.gl/oYY8dr • https://goo.gl/TtzXad • Contract first approach • Multi platform
  • 6.
    Performance • HTTP/2 • SingleTCP connection • Binary framing layer • Header compression • Persistent connections • http://www.http2demo.io
  • 7.
  • 8.
    Protocol Buffers • Protocolbuffers are a flexible, efficient, automated mechanism for serializing structured data, smaller, faster, and simpler than XML or JSON. • You can update your data structure without breaking deployed programs. • Language/platform agnostic. • You have to write a definition in a text file ‘.proto’. • A compiler is needed to generate the desired source code.
  • 9.
    syntax = "proto3"; packagecom.circulosiete.cursos.k8s; import "google/protobuf/timestamp.proto"; import "google/protobuf/wrappers.proto"; import "google/api/annotations.proto"; option java_multiple_files = true; option go_package = "warehouse"; message PageProductResponse { google.protobuf.BoolValue first = 1; //unique numbered tag: 1 google.protobuf.BoolValue last = 2; //unique numbered tag: 2 google.protobuf.Int32Value number = 3; //unique numbered tag: 3 google.protobuf.Int32Value numberOfElements = 4; //unique numbered tag: 4 google.protobuf.Int32Value size = 5; //unique numbered tag: 5 google.protobuf.Int64Value totalElements = 6; //unique numbered tag: 6 google.protobuf.Int32Value totalPages = 7; //unique numbered tag: 7 repeated ProductModel content = 8; } message ProductModel { int64 id = 1; string name = 2; string description = 3; string price = 4; google.protobuf.Timestamp createdAt = 5; google.protobuf.Timestamp modifiedDate = 6; int64 version = 7; }
  • 10.
    Contract! service ProductService { rpcCreate (ProductRequest) returns (ProductResponse); rpc Read (EntityId) returns (ProductResponse); rpc Update (ProductModel) returns (ProductResponse); rpc Delete (EntityId) returns (ProductResponse); rpc Paged (Page) returns (PageProductResponse); rpc List (Page) returns (stream ProductResponse); } service ValidacionService { rpc ValidacionCreate (CreateRequest) returns (ValidacionResponse); rpc ValidacionDelete (EntityId) returns (ValidacionResponse); }
  • 11.
  • 12.
    gRPC compiler • Takesproto files then generates specific source files • It supports several plugins, for different programming languages • It generates Server files, client files.
  • 13.
    JVM • Netty Powered! •Gradle and Maven support • Spring Boot community support
  • 14.
  • 15.
  • 16.
    REST and gRPC •REST is still necessary • JavaScript applications • Web Browser • We can reuse our gRPC endpoints in REST • https://github.com/grpc-ecosystem/grpc-gateway
  • 17.
    gRPC gateway • Fornow only supports Go Lang • We have to use some Google Annotations • The good • Fast as hell! • The Ugly • Sometimes the Go Lang dev env is difficult to setup
  • 18.
  • 19.
    Contact • @domix • domingo.suarez@gmail.com •http://slideshare.net/domingo.suarez
  • 20.
    Photos • https://unsplash.com/photos/_cb5MjNG3DI • https://unsplash.com/photos/1qkyck-UL3g •https://unsplash.com/photos/w7ZyuGYNpRQ • https://unsplash.com/photos/YucYLQ6Dm8A