gRPC: Beyond REST
-
Upload
domingo-suarez-torres -
Category
Technology
-
view
160 -
download
0
Transcript of gRPC: Beyond REST
![Page 1: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/1.jpg)
gRPC: Beyond RESThistory repeats itself infinitely
![Page 2: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/2.jpg)
About me
• JVM developer since 1998
• Cofounder @ CirculoSiete
• Staff @ JVM Mexico City
• @domix
![Page 3: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/3.jpg)
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
![Page 4: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/4.jpg)
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
![Page 5: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/5.jpg)
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
![Page 6: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/6.jpg)
Performance
• HTTP/2
• Single TCP connection
• Binary framing layer
• Header compression
• Persistent connections
• http://www.http2demo.io
![Page 7: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/7.jpg)
Contract first approach
![Page 8: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/8.jpg)
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.
![Page 9: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/9.jpg)
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; }
![Page 10: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/10.jpg)
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); }
![Page 11: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/11.jpg)
Multiplatform
![Page 12: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/12.jpg)
gRPC compiler
• Takes proto files then generates specific source files
• It supports several plugins, for different programming languages
• It generates Server files, client files.
![Page 13: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/13.jpg)
JVM
• Netty Powered!
• Gradle and Maven support
• Spring Boot community support
![Page 14: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/14.jpg)
Live Coding!gRPC intro demo
![Page 15: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/15.jpg)
What about REST?
![Page 16: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/16.jpg)
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
![Page 17: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/17.jpg)
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
![Page 18: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/18.jpg)
Live Coding!gRPC complete demo
![Page 20: gRPC: Beyond REST](https://reader031.fdocuments.in/reader031/viewer/2022021508/5a6490a07f8b9a36568b501f/html5/thumbnails/20.jpg)
Photos
• https://unsplash.com/photos/_cb5MjNG3DI
• https://unsplash.com/photos/1qkyck-UL3g
• https://unsplash.com/photos/w7ZyuGYNpRQ
• https://unsplash.com/photos/YucYLQ6Dm8A