Presented By: Shivraj Singh
Software Consultant
Knoldus Inc.
Building API using
GRPC and Scala
1. History.
2. gRPC: Introduction.
3. gRPC: Workflow.
4. Why gRPC.
5. Scenarios.
6. Core Features
7. Using an HTTP/1.1 transport and its limitations.
8. Difference b/w gRPC and REST.
9. gPRC helps Microservices.
10.gRPC: Powered by.
11.Why not jut use XML.
Our Agenda
History
● Google has been using a RPC infrastructure called Stubby to
connect the large number of microservices running within and
across their data centers for over a decade.
● RPC backbone behind every Google service that we use today.
gRPC: Introduction
● gRPC is a modern open source high performance RPC
framework that can run in any environment.
● It can efficiently connect services in and across data centers
with pluggable support for load balancing, tracing, health
checking and authentication.
● It is also applicable in last mile of distributed computing to
connect devices, mobile applications and browsers to backend
services.
Why gRPC?
● With gRPC we can define our service once in a .proto file and
implement clients and servers in any of gRPC’s supported
languages.
● gRPC is roughly 7 times faster than REST when receiving data
● It is 10 times faster than REST when sending data for this
specific payload.
Scenarios
● Efficiently connecting polyglot services in microservices style
architecture
● Connecting mobile devices, browser clients to backend services.
● Low latency(process a very high volume of data messages with
minimal delay).
● Highly scalable(it can handle a large increase in users, workload
or transactions without undue strain)
Core Features
● Idiomatic client libraries in 10 languages
● Highly efficient on wire and simple service definition framework
● Bi-directional streaming with http/2 based transport
● Pluggable auth(Use:Secure Socket Layer), tracing(opentracing),
load balancing and health checking(package grpc.health.v1;)
Microservices
Using HTTP/1.1 Limitations
● Request-Response protocol
○ Each connection supports pipelining... but not parallelism
(in-order only)
○ Content may be compressed... but headers are text format.
● Naturally supports single-direction streaming ... but not
bidirectional
HTTP/2 Advantages
● For HTTP/1.1 and HTTP/2 protocol with a slight difference.
Imagine that waiters are TCP connections and you want to order
your meal and a bottle of water. For HTTP/1.1 that would mean
that you ask one waiter for your meal and another one for
water, hence you would allocate two TCP connections.
● Request → Stream
○ Streams are multiplexed using framing
● Header compression
● Directly supports bidirectional streaming
HTTP/1 vs HTTP/2
Diff b/w gRPC and REST
Problems in Microservices
gRPC Help Microservices
● Distributed logging, tracing
● Ready to honor backward and forward compatibility, even
if you're the same person consuming this service on the
other side
● Provide Quality of service(QoS) - request deadline even if
it's propagated to many different services
● Provide request propagations/cancellations - stop
cascading failures
Use of Protocol Buffers
Protocol buffer data is structured as messages, where each
message is a small logical record of information containing a series
of name-value pairs called fields.
For example:
syntax = “proto3”;
message Person {
string name = 1;
int32 id = 2;
string email = 3;
}
Example of XML and Protobuf
In XML:
<person>
<name>John Doe</name>
<email>jdoe@example.com</email>
</person>
In Protobuf:
person {
name: "John Doe"
email: "jdoe@example.com"
}
Why not just use XML
Protocol buffers have many advantages over XML for serializing
structured data. Protocol buffers:
● are simpler
● are 3 to 10 times smaller
● are 20 to 100 times faster
● are less ambiguous
● generate data access classes that are easier to use
programmatically
gRPC : Powered by
● https://grpc.io/docs/guides/
● https://grpc.io/docs/tutorials/basic/java/#client
● https://grpc.io/docs/talks/
● https://grpc.io/about/
● https://grpc.io/blog/
References
Thank You!
@Knolspeak
/KnoldusSoftware

Building API Using GRPC And Scala

  • 1.
    Presented By: ShivrajSingh Software Consultant Knoldus Inc. Building API using GRPC and Scala
  • 2.
    1. History. 2. gRPC:Introduction. 3. gRPC: Workflow. 4. Why gRPC. 5. Scenarios. 6. Core Features 7. Using an HTTP/1.1 transport and its limitations. 8. Difference b/w gRPC and REST. 9. gPRC helps Microservices. 10.gRPC: Powered by. 11.Why not jut use XML. Our Agenda
  • 3.
    History ● Google hasbeen using a RPC infrastructure called Stubby to connect the large number of microservices running within and across their data centers for over a decade. ● RPC backbone behind every Google service that we use today.
  • 4.
    gRPC: Introduction ● gRPCis a modern open source high performance RPC framework that can run in any environment. ● It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication. ● It is also applicable in last mile of distributed computing to connect devices, mobile applications and browsers to backend services.
  • 6.
    Why gRPC? ● WithgRPC we can define our service once in a .proto file and implement clients and servers in any of gRPC’s supported languages. ● gRPC is roughly 7 times faster than REST when receiving data ● It is 10 times faster than REST when sending data for this specific payload.
  • 7.
    Scenarios ● Efficiently connectingpolyglot services in microservices style architecture ● Connecting mobile devices, browser clients to backend services. ● Low latency(process a very high volume of data messages with minimal delay). ● Highly scalable(it can handle a large increase in users, workload or transactions without undue strain)
  • 8.
    Core Features ● Idiomaticclient libraries in 10 languages ● Highly efficient on wire and simple service definition framework ● Bi-directional streaming with http/2 based transport ● Pluggable auth(Use:Secure Socket Layer), tracing(opentracing), load balancing and health checking(package grpc.health.v1;)
  • 9.
  • 10.
    Using HTTP/1.1 Limitations ●Request-Response protocol ○ Each connection supports pipelining... but not parallelism (in-order only) ○ Content may be compressed... but headers are text format. ● Naturally supports single-direction streaming ... but not bidirectional
  • 11.
    HTTP/2 Advantages ● ForHTTP/1.1 and HTTP/2 protocol with a slight difference. Imagine that waiters are TCP connections and you want to order your meal and a bottle of water. For HTTP/1.1 that would mean that you ask one waiter for your meal and another one for water, hence you would allocate two TCP connections. ● Request → Stream ○ Streams are multiplexed using framing ● Header compression ● Directly supports bidirectional streaming
  • 12.
  • 13.
    Diff b/w gRPCand REST
  • 14.
  • 15.
    gRPC Help Microservices ●Distributed logging, tracing ● Ready to honor backward and forward compatibility, even if you're the same person consuming this service on the other side ● Provide Quality of service(QoS) - request deadline even if it's propagated to many different services ● Provide request propagations/cancellations - stop cascading failures
  • 16.
    Use of ProtocolBuffers Protocol buffer data is structured as messages, where each message is a small logical record of information containing a series of name-value pairs called fields. For example: syntax = “proto3”; message Person { string name = 1; int32 id = 2; string email = 3; }
  • 17.
    Example of XMLand Protobuf In XML: <person> <name>John Doe</name> <email>jdoe@example.com</email> </person> In Protobuf: person { name: "John Doe" email: "jdoe@example.com" }
  • 18.
    Why not justuse XML Protocol buffers have many advantages over XML for serializing structured data. Protocol buffers: ● are simpler ● are 3 to 10 times smaller ● are 20 to 100 times faster ● are less ambiguous ● generate data access classes that are easier to use programmatically
  • 19.
  • 20.
    ● https://grpc.io/docs/guides/ ● https://grpc.io/docs/tutorials/basic/java/#client ●https://grpc.io/docs/talks/ ● https://grpc.io/about/ ● https://grpc.io/blog/ References
  • 21.