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

What's hot (20)

PPTX
Microservices summit talk 1/31
Varun Talwar
 
PDF
GRPC 101 - DevFest Belgium 2016
Alex Van Boxel
 
PDF
Generating Unified APIs with Protocol Buffers and gRPC
C4Media
 
PDF
gRPC and Microservices
Jonathan Gomez
 
PDF
Enabling Googley microservices with HTTP/2 and gRPC.
Alex Borysov
 
PDF
gRPC: Beyond REST
Domingo Suarez Torres
 
PDF
gRPC & Kubernetes
Kausal
 
PDF
gRPC Design and Implementation
Varun Talwar
 
PDF
Serialization in Go
Albert Strasheim
 
PDF
H2O - the optimized HTTP server
Kazuho Oku
 
PPTX
Grpc present
Phạm Hải Anh
 
PDF
Developing the fastest HTTP/2 server
Kazuho Oku
 
PDF
RPC protocols
오석 한
 
PDF
How happy they became with H2O/mruby and the future of HTTP
Ichito Nagata
 
PDF
Promise of Push (HTTP/2 Web Performance)
Colin Bendell
 
PPTX
Programming TCP for responsiveness
Kazuho Oku
 
PDF
HTTP/2で 速くなるとき ならないとき
Kazuho Oku
 
PDF
Reorganizing Website Architecture for HTTP/2 and Beyond
Kazuho Oku
 
DOC
Use perl creating web services with xml rpc
Johnny Pork
 
Microservices summit talk 1/31
Varun Talwar
 
GRPC 101 - DevFest Belgium 2016
Alex Van Boxel
 
Generating Unified APIs with Protocol Buffers and gRPC
C4Media
 
gRPC and Microservices
Jonathan Gomez
 
Enabling Googley microservices with HTTP/2 and gRPC.
Alex Borysov
 
gRPC: Beyond REST
Domingo Suarez Torres
 
gRPC & Kubernetes
Kausal
 
gRPC Design and Implementation
Varun Talwar
 
Serialization in Go
Albert Strasheim
 
H2O - the optimized HTTP server
Kazuho Oku
 
Grpc present
Phạm Hải Anh
 
Developing the fastest HTTP/2 server
Kazuho Oku
 
RPC protocols
오석 한
 
How happy they became with H2O/mruby and the future of HTTP
Ichito Nagata
 
Promise of Push (HTTP/2 Web Performance)
Colin Bendell
 
Programming TCP for responsiveness
Kazuho Oku
 
HTTP/2で 速くなるとき ならないとき
Kazuho Oku
 
Reorganizing Website Architecture for HTTP/2 and Beyond
Kazuho Oku
 
Use perl creating web services with xml rpc
Johnny Pork
 

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

PPTX
Introduction to gRPC. Advantages and Disadvantages
abdulrehmanlatif65
 
PDF
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays
 
PDF
Implementing OpenAPI and GraphQL services with gRPC
Tim Burks
 
PPTX
CocoaConf: The Language of Mobile Software is APIs
Tim Burks
 
PPTX
What is gRPC introduction gRPC Explained
jeetendra mandal
 
PPTX
The new (is it really ) api stack
Red Hat
 
PDF
APIdays Helsinki 2019 - gRPC: Lightning Fast, Self-Documenting APIs with Moha...
apidays
 
PDF
Building REST APIs using gRPC and Go
Alvaro Viebrantz
 
PDF
Inter-Process Communication in Microservices using gRPC
Shiju Varghese
 
PDF
gRPC Microservices in Go (MEAP V08) Hüseyin Babal
bouicmalapa
 
PPTX
Building API Using GRPC And Scala
Knoldus Inc.
 
PDF
Building Language Agnostic APIs with gRPC - JavaDay Istanbul 2017
Mustafa AKIN
 
PDF
Testing and Developing gRPC APIs
Postman
 
PDF
Build your next REST API with gRPC
Tim Burks
 
PPTX
GRPC.pptx
Afzal Juneja
 
PDF
From '00s to '20s: from RESTful to gRPC
Gianfranco Reppucci
 
PDF
Eran Stiller: API design in the modern era - architecture next 2020
CodeValue
 
PDF
API Design in the Modern Era - Architecture Next 2020
Eran Stiller
 
PPTX
ASP.NET Core 3.0 Deep Dive
Jon Galloway
 
Introduction to gRPC. Advantages and Disadvantages
abdulrehmanlatif65
 
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays
 
Implementing OpenAPI and GraphQL services with gRPC
Tim Burks
 
CocoaConf: The Language of Mobile Software is APIs
Tim Burks
 
What is gRPC introduction gRPC Explained
jeetendra mandal
 
The new (is it really ) api stack
Red Hat
 
APIdays Helsinki 2019 - gRPC: Lightning Fast, Self-Documenting APIs with Moha...
apidays
 
Building REST APIs using gRPC and Go
Alvaro Viebrantz
 
Inter-Process Communication in Microservices using gRPC
Shiju Varghese
 
gRPC Microservices in Go (MEAP V08) Hüseyin Babal
bouicmalapa
 
Building API Using GRPC And Scala
Knoldus Inc.
 
Building Language Agnostic APIs with gRPC - JavaDay Istanbul 2017
Mustafa AKIN
 
Testing and Developing gRPC APIs
Postman
 
Build your next REST API with gRPC
Tim Burks
 
GRPC.pptx
Afzal Juneja
 
From '00s to '20s: from RESTful to gRPC
Gianfranco Reppucci
 
Eran Stiller: API design in the modern era - architecture next 2020
CodeValue
 
API Design in the Modern Era - Architecture Next 2020
Eran Stiller
 
ASP.NET Core 3.0 Deep Dive
Jon Galloway
 
Ad

Recently uploaded (20)

PDF
July Patch Tuesday
Ivanti
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PPTX
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
July Patch Tuesday
Ivanti
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
✨Unleashing Collaboration: Salesforce Channels & Community Power in Patna!✨
SanjeetMishra29
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Ad

gRPC or Rest, why not both?