Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

gRPC: Beyond REST

273 views

Published on

gRPC is becoming a very good choice to develop high performance networking applications

Published in: Technology
  • Be the first to comment

gRPC: Beyond REST

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

×