Slide 1

Slide 1 text

#DevoxxUK @LeanderReimer REST in Peace. Long live gRPC! Mario-Leander Reimer @LeanderReimer https://lreimer.github.io https://speakerdeck.com/lreimer https://www.qaware.de

Slide 2

Slide 2 text

#DevoxxUK @LeanderReimer Mario-Leander Reimer Principal Software Architect @LeanderReimer #cloudnativenerd #qaware

Slide 3

Slide 3 text

#DevoxxUK @LeanderReimer Agenda REST Beer Service REST Beer Service application/json application/x-protobuf gRPC Beer Service gRPC Beer Service gRPC Beer Web UI gRPC Beer Client gRPC REST Gateway application/json gRPC LB Nginx gRPC gRPC gRPC gRPC gRPC Web UI gRPC Web Envoy TypeScript

Slide 4

Slide 4 text

#DevoxxUK @LeanderReimer Code and Demos lreimer/from-rest-to-grpc

Slide 5

Slide 5 text

#DevoxxUK @LeanderReimer "One cannot not communicate." - Paul Watzlawick

Slide 6

Slide 6 text

#DevoxxUK @LeanderReimer A Quick History Lesson on Inter Process Communication HTTP/1.0 Mai 1996 RFC 1945 RPC 14.01.1976 RFC 707 Java RMI Feb 1997 JDK 1.1 REST 2000 by Roy T. Fielding RPC Oct 1983 Birrel and Nielson CORBA 1.0 Oct 1991 CORBA 2.0 August 1996 DCOM 18.09.1996 Win95 HTTP/1.1 Juni 1999 RFC 2616 CORBA 2.3 Juni 1999 XML-RPC 1998 gRPC 1.0 Aug 2016 CORBA 3.0 July 2002 SOAP 1.2 2003 RESTful Applications 2014 (?) HTTP/2.0 Mai 2015 RFC 7540

Slide 7

Slide 7 text

#DevoxxUK @LeanderReimer Agenda REST Beer Service REST Beer Service application/json application/x-protobuf gRPC Beer Service gRPC Beer Service gRPC Beer Web UI gRPC Beer Client gRPC REST Gateway application/json gRPC LB Nginx gRPC gRPC gRPC gRPC gRPC Web UI gRPC Web Envoy TypeScript

Slide 8

Slide 8 text

#DevoxxUK @LeanderReimer REST APIs GET /api/beers POST /api/beers 
 GET /api/beers/{asin} PUT /api/beers/{asin} DELETE /api/beers/{asin} HTTP/1.1 200 OK Content-Length: 139 Content-Type: application/json; charset=utf-8 Date: Wed, 10 Nov 2021 10:21:54 GMT { "alcohol": 5.6, "asin": "B01AU6LWNC", "brand": "Augustiner Brauerei München", "country": "Germany", "name": "Edelstoff Exportbier", "type": "Lager" } GET /api/beers/B01AU6LWNC HTTP/1.1 Accept: application/json Accept-Encoding: gzip, deflate Connection: keep-alive Host: localhost:8080 User-Agent: HTTPie/2.5.0 „Pretty URLs with JSON payloads“ 
 — @hhariri Verbs Nouns Response Request

Slide 9

Slide 9 text

#DevoxxUK @LeanderReimer Richardson REST Maturity Model POST /bookingService HTTP/1.1 [various other headers] https://martinfowler.com/articles/richardsonMaturityModel.html POST /bookings HTTP/1.1 [various other headers] GET /bookings/1234567890?user=lreimer HTTP/1.1 Accept: application/json [various other headers] GET /bookings/1234567890?user=lreimer HTTP/1.1 Accept: application/json Link: /users/lreimer [various other headers]

Slide 10

Slide 10 text

#DevoxxUK @LeanderReimer There is no Readability in ISO 25010! Software Product Quality (ISO 25010) ● Modularity ● Reusability ● Analysability ● Modifiability ● Testability ● Adaptability ● Installability ● Replaceability ● Confidentiality ● Integrity ● Non-repudiation ● Authenticity ● Accountability ● Maturity ● Availability ● Fault Tolerance ● Recoverability Maintainability Portability Security Reliability ● Co-existence ● Interoperability Compatibility ● Time Behaviour ● Resource Utilization ● Capacity Efficiency ● Completeness ● Correctness ● Appropriateness Functional Suitability ● Operability ● Learnability ● UI Aesthetics ● Accessibility Usability

Slide 11

Slide 11 text

#DevoxxUK @LeanderReimer The 8 Fallacies of Distributed Computing 1. The network is reliable 2. Latency is zero 3. Bandwidth is infinite 4. The network is secure 
 5. Topology doesn’t change 6. There is one administrator 7. Transport cost is zero 8. The network is homogeneous

Slide 12

Slide 12 text

#DevoxxUK @LeanderReimer Protocol Buffers in a Nutshell • Like XML or JSON - just smaller, faster and easier! • Language-neutral, platform-neutral extensible mechanism for serializing structured data • Google Protobuf uses an efficient binary format to serialize data structures • Data structures and message payloads are defined using an Interface Definition Language (IDL) • Protocol Buffers supports code generation for Java, Python, Objective-C, C++, Kotlin, Dart, Go, Ruby und C#. • Protobuf supports schema evolution and extension. Backwards and forwards compatibility are supported

Slide 13

Slide 13 text

#DevoxxUK @LeanderReimer Protobuf IDL with Java Demo

Slide 14

Slide 14 text

#DevoxxUK @LeanderReimer JSON vs. Protobuf Performance • Protobuf on a non-compressed environment, the requests took 78% less time than the JSON requests. The binary format performed almost 5 times faster than the text format. • Protobuf on a compressed environment performed 6 times faster, taking only 25ms to handle requests that took 150ms on a JSON format. Disclaimer: please perform your own benchmarks for your specific use case! https://auth0.com/blog/beating-json-performance-with-protobuf/ https://blog.qaware.de/posts/binary-data-format-comparison/

Slide 15

Slide 15 text

#DevoxxUK @LeanderReimer Agenda REST Beer Service REST Beer Service application/json application/x-protobuf gRPC Beer Service gRPC Beer Service gRPC Beer Web UI gRPC Beer Client gRPC REST Gateway application/json gRPC LB Nginx gRPC gRPC gRPC gRPC gRPC Web UI gRPC Web Envoy TypeScript

Slide 16

Slide 16 text

#DevoxxUK @LeanderReimer gRPC in a Nutshell • A modern, high performance, open source and universal RPC framework. • Uses HTTP/2 as modern Web-friendly transport protocol (Multiplexing, TLS, compression) • Supports several types of communication: classic request-response as well as streaming from Client-side, Server-side, Uni- and Bi-Directional • Uses Protobuf IDL to define services and payload messages • Client and server stubs are generated from the IDL easily for several languages • Support various load balancing options: proxy, client-side and look-aside balancing • Flexible support for tracing, health checks and authentication

Slide 17

Slide 17 text

#DevoxxUK @LeanderReimer gRPC Service with Java Demo Service Definition

Slide 18

Slide 18 text

#DevoxxUK @LeanderReimer Agenda REST Beer Service REST Beer Service application/json application/x-protobuf gRPC Beer Service gRPC Beer Service gRPC Beer Web UI gRPC Beer Client gRPC REST Gateway application/json gRPC LB Nginx gRPC gRPC gRPC gRPC gRPC Web UI gRPC Web Envoy TypeScript

Slide 19

Slide 19 text

#DevoxxUK @LeanderReimer gRPC Ecosystem in a Nutshell • Different projects from the gRPC ecosystem enable good interoperability • gRPC Gateway - https://grpc-ecosystem.github.io/grpc-gateway/ • gRPC Web - https://grpc.io/docs/platforms/web/quickstart/ • https://blog.envoyproxy.io/envoy-and-grpc-web-a-fresh-new-alternative-to- rest-6504ce7eb880 • Support various load balancing options: proxy, client-side and look-aside balancing • Nginx - https://nginx.org/en/docs/http/ngx_http_grpc_module.html • Envoy - https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/ other_protocols/grpc

Slide 20

Slide 20 text

#DevoxxUK @LeanderReimer gRPC Gateway Demo Map gRPC call to GET request path Map {asin} path param to request Use beer field as response body Map POST body to request

Slide 21

Slide 21 text

#DevoxxUK @LeanderReimer gRPC Web Demo Enable gRPC Web Envoy Filter

Slide 22

Slide 22 text

#DevoxxUK @LeanderReimer & & Mario-Leander Reimer @LeanderReimer https://lreimer.github.io https://speakerdeck.com/lreimer https://www.qaware.de