SlideShare a Scribd company logo
gRPC or REST
Why not both?
@m_m_murad
Mohammad Murad
Backend and Mobile engineer
Agenda
Agenda
● What is REST?
Agenda
● What is REST?
● Disadvantages of REST.
Agenda
● What is REST?
● Disadvantages of REST.
● What is gRPC?
Agenda
● What is REST?
● Disadvantages of REST.
● What is gRPC?
● Advantages of gRPC.
Agenda
● What is REST?
● Disadvantages of REST.
● What is gRPC?
● Advantages of gRPC.
● gRPC and REST services from a single codebase.
REST
REST
● Representational State Transfer.
REST
● Representational State Transfer.
● Not a protocol but an Design Pattern.
REST
● Representational State Transfer.
● Not a protocol but an Design Pattern.
● Uses HTTP protocol.
REST
● Representational State Transfer.
● Not a protocol but an Design Pattern.
● Uses HTTP protocol.
● Objects that are send or saved are called resources.
REST
● Representational State Transfer.
● Not a protocol but an Design Pattern.
● Uses HTTP protocol.
● Objects that are send or saved are called resources.
● Operations are described by HTTP verbs.
REST
● Representational State Transfer.
● Not a protocol but an Design Pattern.
● Uses HTTP protocol.
● Objects that are send or saved are called resources.
● Operations are described by HTTP verbs.
● Transfers data as XML or JSON or Protocol Buffers.
A REST API can be -
A REST API can be -
XML + HTTP
A REST API can be -
XML + HTTP
JSON + HTTP
A REST API can be -
XML + HTTP
JSON + HTTP
Protocol Buffers + HTTP
XML + HTTP
JSON + HTTP
Protocol Buffers + HTTP
What does a REST call look like?
Is this a REST call?
GET http://0.0.0.0:8081/updateBook
Content-Type: application/json
Authorization: Basic asfd34hk82hg32j==
{
"id": 12,
"author": "Prem"
}
PUT http://0.0.0.0:8081/books
Content-Type: application/json
Authorization: Basic asfd34hk82hg32j==
{
"id": 12,
"author": "Prem"
}
RESTish
RESTful API
PUT http://0.0.0.0:8081/api/v1/books/12
Content-Type: application/json
Authorization: Basic asfd34hk82hg32j==
{
"author": "Prem"
}
Disadvantages of REST?
Disadvantages of REST?
● The data being transferred is heavily bloated.
{
"id": 12,
"name": "Developing in Node",
"author": "Prem Pratap Tomar",
"rating": 3.2,
"release_date": "2019-06-17T19:12:43.905Z",
"units_sold": 123456,
"publisher": "Leaf publications",
"best_sell": true
}
Bloated data
{
"id": 12,
"name": "Developing in Node",
"author": "Prem Pratap Tomar",
"rating": 3.2,
"release_date": "2019-06-17T19:12:43.905Z",
"units_sold": 123456,
"publisher": "Leaf publications",
"best_sell": true
}
Message size - 190 bytes (Ignoring the white spaces)
Bloated data
{
"id": 12,
"name": "Developing in Node",
"author": "Prem Pratap Tomar",
"rating": 3.2,
"release_date": "2019-06-17T19:12:43.905Z",
"units_sold": 123456,
"publisher": "Leaf publications",
"best_sell": true
}
Message size - 190 bytes (Ignoring the white spaces)
Useful info - 107 bytes (56.3%)
Unnecessary info describing useful info - 83 bytes (43.7%)
Bloated data
{"books":[{"id": 12,"name":"Developing in Node", "author":"Prem Pratap
Tomar","rating":3.2,"release_date": "2019-06-17T19:12:43.905Z", "units_sold":1
23456,"publisher":"Leaf
publications", "best_sell":true},{"id":13,"name":"Developing in
Node","author":"Prem Pratap
Tomar","rating":3.2,"release_date": "2019-06-17T19:12:43.930Z", "units_sold":1
23456,"publisher":"Leaf
publications", "best_sell":true},{"id":14,"name":"Developing in
Node","author":"Prem Pratap
Tomar","rating":3.2,"release_date": "2019-06-17T19:12:43.955Z", "units_sold":1
23456,"publisher":"Leaf publications", "best_sell":true}]}
Message size - 190 * 3 = 570 bytes (approx)
Useful info - 107 * 3 = 321 bytes (approx)
Unnecessary info - 83 * 3 = 249 bytes (approx)
Bloated data
Disadvantages of REST?
● The data being transferred is heavily bloated.
● There is no formal contract to communicate.
Disadvantages of REST?
● The data being transferred is heavily bloated.
● There is no formal contract to communicate.
● HTTP verbs don’t always describe your API.
Disadvantages of REST?
● The data being transferred is heavily bloated.
● There is no formal contract to communicate.
● HTTP verbs don’t always describe your API.
● Streaming is difficult.
Disadvantages of REST?
● The data being transferred is heavily bloated.
● There is no formal contract to communicate.
● HTTP verbs don’t always describe your API.
● Streaming is difficult.
● GraphQL problems.
What if not REST?
gRPC
gRPC
● gRPC Remote Procedure Call
gRPC
● gRPC Remote Procedure Call
● Open source version of an internal Google product.
gRPC
● gRPC Remote Procedure Call
● Open source version of an internal Google product.
● High performance RPC framework.
gRPC
● gRPC Remote Procedure Call
● Open source version of an internal Google product.
● High performance RPC framework.
● Uses HTTP/2 protocol.
gRPC
● gRPC Remote Procedure Call
● Open source version of an internal Google product.
● High performance RPC framework.
● Uses HTTP/2 protocol.
● Uses Protocol Buffers for message interchange.
gRPC
● gRPC Remote Procedure Call
● Open source version of an internal Google product.
● High performance RPC framework.
● Uses HTTP/2 protocol.
● Uses Protocol Buffers for message interchange.
● Can use other formats like JSON, XML.
Writing a gRPC service.
Writing a gRPC service. (3 step process)
Messages
and
Services
Define
Writing a gRPC service. (Step 1/3)
Messages
and
Services
compiler
Define Compile
Generated Code
Writing a gRPC service. (Step 2/3)
Messages
and
Services
compiler Generated Code
Servers
and
Clients
ImplementDefine
Writing a gRPC service. (Step 3/3)
Compile
Let’s make a calculator services
Protocol Buffer
Protocol Buffer
● Interface Definition Language (IDL).
Protocol Buffer
● Interface Definition Language (IDL).
● Message interchange format.
Protocol Buffer
● Interface Definition Language (IDL).
● Message interchange format.
● Platform neutral mechanism for serializing structured data.
Protocol Buffer
● Interface Definition Language (IDL).
● Message interchange format.
● Platform neutral mechanism for serializing structured data.
● Similar to XML or JSON but very small and fast.
Protocol Buffer
● Interface Definition Language (IDL).
● Message interchange format.
● Platform neutral mechanism for serializing structured data.
● Similar to XML or JSON but very small and fast.
3-10x smaller than XML
10-100X faster than XML
Let’s make a calculator services
gRPC or Rest, why not both?
gRPC or Rest, why not both?
gRPC or Rest, why not both?
gRPC or Rest, why not both?
gRPC or Rest, why not both?
gRPC or Rest, why not both?
gRPC or Rest, why not both?
Messages
and
Services
.proto
Compiler
protoc
Generated
Code
Servers
and
Clients
Define Compile Implement
Messages
and
Services
.proto
Compiler
protoc
Define Compile Implement
Servers
and
Clients
Generated code
C#
C++
Dart
Go
Java
Node
Objective-C
PHP
Python
Ruby
Go Service
gRPC server
Mobile client
Desktop client
gRPC Stub
gRPC Stub
Ruby Service
gRPC server
Go Service
gRPC server
gRPC
Stub
Java Service
gRPC
Stub
Python
Service
gRPC server
gRPC
Stub
Mobile client
Desktop client
gRPC
Stub
gRPC
Stub
gRPC server
Why gRPC? What do I get?
Why gRPC? What do I get?
● Generated code in 10 languages.
Why gRPC? What do I get?
● Generated code in 10 languages.
● Strict contract between servers and clients.
Why gRPC? What do I get?
● Generated code in 10 languages.
● Strict contract between servers and clients.
● Performant and efficient on the wire
Small binary messages.
Faster serialisation and deserialisation.
Multiplexing and Header Compression.
● Generated code in 10 languages.
● Strict contract between servers and clients.
● Performant and efficient on the wire
Small binary messages.
Faster serialisation and deserialisation.
Multiplexing and Header Compression.
● In addition to traditional unary APIs you also get
Client Streaming APIs
Server Streaming APIs
Bi-Directional streaming APIs
Why gRPC? What do I get?
But...
What about our existing APIs?
But...
What about our existing APIs?
Do we
● Develop both flavors parallelly?
● Deprecate existing APIs and ask clients to update their code.
grpc-gateway
grpc-gateway
● A plugin for protoc compiler.
grpc-gateway
● A plugin for protoc compiler.
● An open source tool by grpc-ecosystem.
grpc-gateway
● A plugin for protoc compiler.
● An open source tool by grpc-ecosystem.
● Generates a reverse proxy which can communicate to your gRPC server
using JSON over HTTP.
gRPC or Rest, why not both?
Using grpc-gateway
Using grpc-gateway (3 step process)
Using grpc-gateway (Step 1/3)
1. Annotating your proto file.
gRPC or Rest, why not both?
gRPC or Rest, why not both?
Using grpc-gateway (Step 2/3)
1. Annotating your proto file.
2. Generate reverse proxy and OpenAPI definitions.
Annotated Messages
and Services
.proto
Compiler
protoc
Server interfaces and
client stubs
Annotated Messages
and Services
.proto
Compiler
protoc + grpc-gateway
Server interfaces and
client stubs
Open API specification
your-service.json
Reverse proxy in Go
your-service.pb.gw.go
Using grpc-gateway (Step 3/3)
1. Annotating your proto file.
2. Generate reverse proxy and OpenAPI definitions.
3. Write an entry point for the reverse proxy.
gRPC or Rest, why not both?
DEMO
gRPC or Rest, why not both?
gRPC or Rest, why not both?
Thank you
More about gRPC and grpc-gateway
● https://grpc.io
● https://github.com/grpc
● https://github.com/grpc-ecosystem/grpc-gateway
● https://grpc-ecosystem.github.io/grpc-gateway

More Related Content

PPTX
Building your First gRPC Service
PDF
Teach your (micro)services talk Protocol Buffers with gRPC.
PPTX
HTTP2 and gRPC
PDF
Make gRPC great again
PDF
gRPC - RPC rebirth?
PDF
gRPC in Go
PDF
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
PDF
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
Building your First gRPC Service
Teach your (micro)services talk Protocol Buffers with gRPC.
HTTP2 and gRPC
Make gRPC great again
gRPC - RPC rebirth?
gRPC in Go
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google

What's hot (20)

PPTX
Microservices summit talk 1/31
PDF
GRPC 101 - DevFest Belgium 2016
PDF
Generating Unified APIs with Protocol Buffers and gRPC
PDF
gRPC and Microservices
PDF
Enabling Googley microservices with HTTP/2 and gRPC.
PDF
gRPC: Beyond REST
PDF
gRPC & Kubernetes
PDF
gRPC Design and Implementation
PDF
Serialization in Go
PDF
H2O - the optimized HTTP server
PPTX
Grpc present
PDF
Developing the fastest HTTP/2 server
PDF
RPC protocols
PDF
How happy they became with H2O/mruby and the future of HTTP
PDF
Promise of Push (HTTP/2 Web Performance)
PPTX
Programming TCP for responsiveness
PDF
HTTP/2で 速くなるとき ならないとき
PDF
Reorganizing Website Architecture for HTTP/2 and Beyond
DOC
Use perl creating web services with xml rpc
Microservices summit talk 1/31
GRPC 101 - DevFest Belgium 2016
Generating Unified APIs with Protocol Buffers and gRPC
gRPC and Microservices
Enabling Googley microservices with HTTP/2 and gRPC.
gRPC: Beyond REST
gRPC & Kubernetes
gRPC Design and Implementation
Serialization in Go
H2O - the optimized HTTP server
Grpc present
Developing the fastest HTTP/2 server
RPC protocols
How happy they became with H2O/mruby and the future of HTTP
Promise of Push (HTTP/2 Web Performance)
Programming TCP for responsiveness
HTTP/2で 速くなるとき ならないとき
Reorganizing Website Architecture for HTTP/2 and Beyond
Use perl creating web services with xml rpc
Ad

Similar to gRPC or Rest, why not both? (20)

PPTX
REST vs gRPC: Battle of API's
PDF
Cloud Native API Design and Management
PPTX
REST in Peace. Long live gRPC! @ Codineers
PDF
REST in Peace. Long live gRPC!
PDF
Microservices Communication Patterns with gRPC
PDF
Testing and Developing gRPC APIs
PDF
Cloud native IPC for Microservices Workshop @ Containerdays 2022
PDF
REST in Peace. Long live gRPC!
PDF
Build microservice with gRPC in golang
PDF
Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020
PDF
Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}
PDF
REST in Peace. Long live gRPC!
PDF
gRPC 프레임워크를 만들며 알아보는 파이썬 - 파이콘2020
PDF
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
PDF
Implementing OpenAPI and GraphQL services with gRPC
PDF
APIdays Helsinki 2019 - gRPC: Lightning Fast, Self-Documenting APIs with Moha...
PDF
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
PPTX
GRPC.pptx
PPTX
Apa itu gRPC_.pptx
REST vs gRPC: Battle of API's
Cloud Native API Design and Management
REST in Peace. Long live gRPC! @ Codineers
REST in Peace. Long live gRPC!
Microservices Communication Patterns with gRPC
Testing and Developing gRPC APIs
Cloud native IPC for Microservices Workshop @ Containerdays 2022
REST in Peace. Long live gRPC!
Build microservice with gRPC in golang
Scala for Everything: From Frontend to Backend Applications - Scala Matsuri 2020
Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}
REST in Peace. Long live gRPC!
gRPC 프레임워크를 만들며 알아보는 파이썬 - 파이콘2020
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
Implementing OpenAPI and GraphQL services with gRPC
APIdays Helsinki 2019 - gRPC: Lightning Fast, Self-Documenting APIs with Moha...
JHipster Conf 2018 : Connect your JHipster apps to the world of APIs with Ope...
GRPC.pptx
Apa itu gRPC_.pptx
Ad

Recently uploaded (20)

PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Cloud computing and distributed systems.
PDF
cuic standard and advanced reporting.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Machine learning based COVID-19 study performance prediction
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Empathic Computing: Creating Shared Understanding
PPT
Teaching material agriculture food technology
PDF
Electronic commerce courselecture one. Pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Cloud computing and distributed systems.
cuic standard and advanced reporting.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
NewMind AI Weekly Chronicles - August'25 Week I
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Spectral efficient network and resource selection model in 5G networks
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
sap open course for s4hana steps from ECC to s4
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine learning based COVID-19 study performance prediction
Encapsulation_ Review paper, used for researhc scholars
Unlocking AI with Model Context Protocol (MCP)
Empathic Computing: Creating Shared Understanding
Teaching material agriculture food technology
Electronic commerce courselecture one. Pdf
Spectroscopy.pptx food analysis technology
Per capita expenditure prediction using model stacking based on satellite ima...

gRPC or Rest, why not both?