+ All Categories
Home > Technology > gRPC: Beyond REST

gRPC: Beyond REST

Date post: 21-Jan-2018
Category:
Upload: domingo-suarez-torres
View: 158 times
Download: 0 times
Share this document with a friend
20
gRPC: Beyond REST history repeats itself infinitely
Transcript
Page 1: gRPC: Beyond REST

gRPC: Beyond RESThistory repeats itself infinitely

Page 2: gRPC: Beyond REST

About me

• JVM developer since 1998

• Cofounder @ CirculoSiete

• Staff @ JVM Mexico City

• @domix

Page 3: gRPC: Beyond REST

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

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

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

Performance

• HTTP/2

• Single TCP connection

• Binary framing layer

• Header compression

• Persistent connections

• http://www.http2demo.io

Page 7: gRPC: Beyond REST

Contract first approach

Page 8: gRPC: Beyond REST

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

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

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

Multiplatform

Page 12: gRPC: Beyond REST

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

JVM

• Netty Powered!

• Gradle and Maven support

• Spring Boot community support

Page 14: gRPC: Beyond REST

Live Coding!gRPC intro demo

Page 15: gRPC: Beyond REST

What about REST?

Page 16: gRPC: Beyond 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

Page 17: gRPC: Beyond REST

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

Live Coding!gRPC complete demo

Page 19: gRPC: Beyond REST

Contact

• @domix

[email protected]

• http://slideshare.net/domingo.suarez

Page 20: gRPC: Beyond REST

Photos

• https://unsplash.com/photos/_cb5MjNG3DI

• https://unsplash.com/photos/1qkyck-UL3g

• https://unsplash.com/photos/w7ZyuGYNpRQ

• https://unsplash.com/photos/YucYLQ6Dm8A


Recommended