Upgrade to Pro — share decks privately, control downloads, hide ads and more …

REST in Peace. Long live gRPC! @ Devoxx UK 2022

REST in Peace. Long live gRPC! @ Devoxx UK 2022

This session focuses on modern and efficient Inter Process Communication (IPC) for microservices. We start with a REST API, built with just a few lines of code using JAX-RS and Quarkus to briefly discuss the pros and cons of this approach. Then, we will extend the API with an efficient Protobuf payload representation in order to finally transform the API into a fully fledged high-performance gRPC interface definition. But that's not all! To put some extra icing on the cake, this talk will demonstrate how to consume the gRPC service from a JavaScript web client and also how to completely generate a matching REST API from an enhanced gRPC interface definition to ensure full interoperability in a microservice architecture. #qaware #cloudnativenerd

M.-Leander Reimer

May 12, 2022
Tweet

More Decks by M.-Leander Reimer

Other Decks in Programming

Transcript

  1. #DevoxxUK @LeanderReimer REST in Peace. Long live gRPC! Mario-Leander Reimer

    @LeanderReimer https://lreimer.github.io https://speakerdeck.com/lreimer https://www.qaware.de
  2. #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
  3. #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
  4. #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
  5. #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
  6. #DevoxxUK @LeanderReimer Richardson REST Maturity Model POST /bookingService HTTP/1.1 [various

    other headers] <makeBookingRequest date="2010-01-04" persons="2"/> https://martinfowler.com/articles/richardsonMaturityModel.html POST /bookings HTTP/1.1 [various other headers] <getBookingRequest id="ID-1234567890" user"lreimer"/> 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]
  7. #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
  8. #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
  9. #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
  10. #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/
  11. #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
  12. #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
  13. #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
  14. #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
  15. #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