SlideShare a Scribd company logo
1 of 31
Creating modern webservices
in
Golang
// Omid Hojabri
// E-mail: o.hojabri@gmail.com
// Skype: hojabri
// LinkedIn: linkedin.com/in/hojabri
using gRPC + Protocol
Buffers
REST : Popular API
 REST (HTTP-JSON)
 JSON
 Format in URL:
 GET /api/v1/user/231/roles/453
 POST /api/v1/user/231/roles
 PUT …
 DELETE ...
Concerns about APIs
 Data size
 Latency
 Scalability
 Load Balancing
 Communication between languages
 Authentication
 Monitoring
 Logging
What is an API
 Is a contract
 Client sends REQUEST
 Server sends RESPONSE
gRPC
 Is a free and open-source framework developed by
 Allows to simply define REQUEST and RESPONSE for RPC (Remote Procedure Calls)
 Modern, Fast, Efficient (based on HTTP/2)
 Low latency
 Supports streaming
 Many languages support it
 Authentication, Monitoring, Load balancing and Logging are easy to define with gRPC
 Many companies like Google, Netflix, Square, CoreOS, Spotify, Docker, Cisco,… using it fully.
Official supported languages
 C/C++
 Java
 Android Java
 Go
 C#
 Kotlin
 Node.js
 Objective-C
 PHP (Beta)
 Python
 Ruby
 Dart
RPC
 Remote Procedure Call
 Client calls functions directly on the server
 gRPC implements RPC very cleanly and it solves a
lot of problems
gRPC overview
gRPC uses protocol buffers (protobuf) to communicate between clients and servers
How it runs?
 gRPC needs to define messages and services using Protocol
Buffers
 gRPC codes will be generated automatically with “protoc”
command!
 Data is binary
 You need just implementing the methods defined based on your
message type
 Defining Protocol Buffers in .proto files.
.proto files
 We define
messages and
service
definitions in
.proto files.
 (API contract)
Types of API in gRPC
1 Unary
2 Server Streaming
3 Client Streaming
4 Bi-directional Streaming
Unary API
Client Server
Request
Response
Server Streaming API
Client Server
Request
Message 1
Message 2
Message 3
Message n
.
.
.
.
Client Streaming API
Client Server
Message 1
Message 2
Message 3
Message n
Response
.
.
.
.
Bi-directional Streaming API
Client Server
Client Message 1
Client Message 2
Client Message 3
Server Message 3
Server Message 4
Server Message n
Client Message 4
Client Message n
Server Message 2
Server Message 1
gRPC vs REST
gRPC REST
Data is binary, smaller and communication is faster (25
more performance based on benchmarks)
Text based, bigger and slower
HTTP/2 (Low latency) HTTP/1.1 (Higher latency)
Unary, Server streaming, Client streaming, bi-
directional streaming
Request – Response only
Any API commands CRUD (Create – Retrieve – Update – Delete) POST –
GET – PUT - DELETE
Code generation by protocol buffers in any language Manual code or by OpenAPI/Swagger
RPC based HTTP words based
Installation
 Prerequisites:
 Go to be installed (any one of the three latest major
release)
 Protocol Buffer compiler (protoc v3)
 Go plugin for protocol compiler
Protocol Buffer Compiler (v3)
 The protocol buffer compiler (protoc) is used to
compile (code generation) .proto files, which contain
service and message definitions.
 Linux:

 MacOS:

Protocol Buffer Compiler (v3)
 Windows:
 Download and install the latest release of binary version
from:
 https://github.com/protocolbuffers/protobuf/releases/tag/v3.13.0
 (at the moment v3.13.0 is released)
Go plugin for the protocol
buffers
1 Install the protocol compiler plugin for Go (protoc-gen-go)
using the following command:
2 Update your PATH so that the protoc compiler can find the
plugin:
Installing dependencies
 Installing go grpc module: https://github.com/grpc/grpc-
go
 (It may take some time to install completely)
Configuration of a .proto file
 Syntax version and package definition:
Configuration of a .proto file
 Message definition:
Configuration of a .proto file
 Service Definition:
Generating Code
 Will generate a file called “greet.pb.go”
Server sample code
Server sample code
Client sample
Client sample
Full sample source code
 I’ve uploaded my sample source code which covers
all four types of gRPC API
https://github.com/hojabri/grpc-pr
Thank you
Github: https://github.com/hojabri
E-mail: o.hojabri@gmail.com
Skype: hojabri
LinkedIn: https://linkedin.com/in/hojabri

More Related Content

What's hot

Www ccnav5 net_ccna_1_chapter_7_v5_0_exam_answers_2014
Www ccnav5 net_ccna_1_chapter_7_v5_0_exam_answers_2014Www ccnav5 net_ccna_1_chapter_7_v5_0_exam_answers_2014
Www ccnav5 net_ccna_1_chapter_7_v5_0_exam_answers_2014Đồng Quốc Vương
 
HornetQ Presentation On JBoss World 2009
HornetQ Presentation On JBoss World 2009HornetQ Presentation On JBoss World 2009
HornetQ Presentation On JBoss World 2009jarfield
 
Mobicents Telscale and RestComm - FOSDEM 2012
Mobicents Telscale and RestComm - FOSDEM 2012Mobicents Telscale and RestComm - FOSDEM 2012
Mobicents Telscale and RestComm - FOSDEM 2012telestax
 
Running gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on KubernetesRunning gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on KubernetesSungwon Lee
 
Mobicents 2.0, The Java Open Source Communications Platform-FOSDEM 2011 Jean ...
Mobicents 2.0, The Java Open Source Communications Platform-FOSDEM 2011 Jean ...Mobicents 2.0, The Java Open Source Communications Platform-FOSDEM 2011 Jean ...
Mobicents 2.0, The Java Open Source Communications Platform-FOSDEM 2011 Jean ...Jean Deruelle
 
project introduction
project introductionproject introduction
project introductionstinmon
 
Talk Python To Me: Stream Processing in your favourite Language with Beam on ...
Talk Python To Me: Stream Processing in your favourite Language with Beam on ...Talk Python To Me: Stream Processing in your favourite Language with Beam on ...
Talk Python To Me: Stream Processing in your favourite Language with Beam on ...Aljoscha Krettek
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftTalentica Software
 
Flink Forward Berlin 2018: Robert Bradshaw & Maximilian Michels - "Universal ...
Flink Forward Berlin 2018: Robert Bradshaw & Maximilian Michels - "Universal ...Flink Forward Berlin 2018: Robert Bradshaw & Maximilian Michels - "Universal ...
Flink Forward Berlin 2018: Robert Bradshaw & Maximilian Michels - "Universal ...Flink Forward
 
Introduction to RestComm - Mobicents Summit 2011
Introduction to RestComm - Mobicents Summit 2011Introduction to RestComm - Mobicents Summit 2011
Introduction to RestComm - Mobicents Summit 2011telestax
 
Балансировщики KEMP для Microsoft Lync, Skype for Business
Балансировщики KEMP для Microsoft Lync, Skype for BusinessБалансировщики KEMP для Microsoft Lync, Skype for Business
Балансировщики KEMP для Microsoft Lync, Skype for BusinessAlexander Zhuravlev, Ph.D.
 
From ZERO to REST in an hour
From ZERO to REST in an hour From ZERO to REST in an hour
From ZERO to REST in an hour Cisco DevNet
 
Microsoft .NET Platform
Microsoft .NET PlatformMicrosoft .NET Platform
Microsoft .NET PlatformPeter R. Egli
 
TDC2018FLN | Trilha Containers - Kubernetes para usuarios Docker.
TDC2018FLN | Trilha Containers - Kubernetes para usuarios Docker.TDC2018FLN | Trilha Containers - Kubernetes para usuarios Docker.
TDC2018FLN | Trilha Containers - Kubernetes para usuarios Docker.tdc-globalcode
 
Livecode widget course
Livecode widget courseLivecode widget course
Livecode widget coursecrazyaxe
 
IRJET- Mail Server Communication:PHP
IRJET-  	  Mail Server Communication:PHPIRJET-  	  Mail Server Communication:PHP
IRJET- Mail Server Communication:PHPIRJET Journal
 
RIA With Flex & Java Using BlazeDS
RIA With Flex & Java Using BlazeDSRIA With Flex & Java Using BlazeDS
RIA With Flex & Java Using BlazeDSHien Luu
 
Automating SDK generation - London Mobile Forum 2.0
Automating SDK generation - London Mobile Forum 2.0Automating SDK generation - London Mobile Forum 2.0
Automating SDK generation - London Mobile Forum 2.0Thong Nguyen
 

What's hot (20)

Tml for Ruby on Rails
Tml for Ruby on RailsTml for Ruby on Rails
Tml for Ruby on Rails
 
Www ccnav5 net_ccna_1_chapter_7_v5_0_exam_answers_2014
Www ccnav5 net_ccna_1_chapter_7_v5_0_exam_answers_2014Www ccnav5 net_ccna_1_chapter_7_v5_0_exam_answers_2014
Www ccnav5 net_ccna_1_chapter_7_v5_0_exam_answers_2014
 
HornetQ Presentation On JBoss World 2009
HornetQ Presentation On JBoss World 2009HornetQ Presentation On JBoss World 2009
HornetQ Presentation On JBoss World 2009
 
Mobicents Telscale and RestComm - FOSDEM 2012
Mobicents Telscale and RestComm - FOSDEM 2012Mobicents Telscale and RestComm - FOSDEM 2012
Mobicents Telscale and RestComm - FOSDEM 2012
 
Running gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on KubernetesRunning gRPC Services for Serving Legacy API on Kubernetes
Running gRPC Services for Serving Legacy API on Kubernetes
 
Mobicents 2.0, The Java Open Source Communications Platform-FOSDEM 2011 Jean ...
Mobicents 2.0, The Java Open Source Communications Platform-FOSDEM 2011 Jean ...Mobicents 2.0, The Java Open Source Communications Platform-FOSDEM 2011 Jean ...
Mobicents 2.0, The Java Open Source Communications Platform-FOSDEM 2011 Jean ...
 
project introduction
project introductionproject introduction
project introduction
 
Talk Python To Me: Stream Processing in your favourite Language with Beam on ...
Talk Python To Me: Stream Processing in your favourite Language with Beam on ...Talk Python To Me: Stream Processing in your favourite Language with Beam on ...
Talk Python To Me: Stream Processing in your favourite Language with Beam on ...
 
Filas com php
Filas com phpFilas com php
Filas com php
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
 
Flink Forward Berlin 2018: Robert Bradshaw & Maximilian Michels - "Universal ...
Flink Forward Berlin 2018: Robert Bradshaw & Maximilian Michels - "Universal ...Flink Forward Berlin 2018: Robert Bradshaw & Maximilian Michels - "Universal ...
Flink Forward Berlin 2018: Robert Bradshaw & Maximilian Michels - "Universal ...
 
Introduction to RestComm - Mobicents Summit 2011
Introduction to RestComm - Mobicents Summit 2011Introduction to RestComm - Mobicents Summit 2011
Introduction to RestComm - Mobicents Summit 2011
 
Балансировщики KEMP для Microsoft Lync, Skype for Business
Балансировщики KEMP для Microsoft Lync, Skype for BusinessБалансировщики KEMP для Microsoft Lync, Skype for Business
Балансировщики KEMP для Microsoft Lync, Skype for Business
 
From ZERO to REST in an hour
From ZERO to REST in an hour From ZERO to REST in an hour
From ZERO to REST in an hour
 
Microsoft .NET Platform
Microsoft .NET PlatformMicrosoft .NET Platform
Microsoft .NET Platform
 
TDC2018FLN | Trilha Containers - Kubernetes para usuarios Docker.
TDC2018FLN | Trilha Containers - Kubernetes para usuarios Docker.TDC2018FLN | Trilha Containers - Kubernetes para usuarios Docker.
TDC2018FLN | Trilha Containers - Kubernetes para usuarios Docker.
 
Livecode widget course
Livecode widget courseLivecode widget course
Livecode widget course
 
IRJET- Mail Server Communication:PHP
IRJET-  	  Mail Server Communication:PHPIRJET-  	  Mail Server Communication:PHP
IRJET- Mail Server Communication:PHP
 
RIA With Flex & Java Using BlazeDS
RIA With Flex & Java Using BlazeDSRIA With Flex & Java Using BlazeDS
RIA With Flex & Java Using BlazeDS
 
Automating SDK generation - London Mobile Forum 2.0
Automating SDK generation - London Mobile Forum 2.0Automating SDK generation - London Mobile Forum 2.0
Automating SDK generation - London Mobile Forum 2.0
 

Similar to Modern webservices using gRPC and Protocol Buffers in Golang

What I learned about APIs in my first year at Google
What I learned about APIs in my first year at GoogleWhat I learned about APIs in my first year at Google
What I learned about APIs in my first year at GoogleTim Burks
 
Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}
Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}
Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}Md. Sadhan Sarker
 
REST in Peace. Long live gRPC!
REST in Peace. Long live gRPC!REST in Peace. Long live gRPC!
REST in Peace. Long live gRPC!QAware GmbH
 
REST in Peace. Long live gRPC!
REST in Peace. Long live gRPC!REST in Peace. Long live gRPC!
REST in Peace. Long live gRPC!QAware GmbH
 
Driving containerd operations with gRPC
Driving containerd operations with gRPCDriving containerd operations with gRPC
Driving containerd operations with gRPCDocker, Inc.
 
.NET Core Today and Tomorrow
.NET Core Today and Tomorrow.NET Core Today and Tomorrow
.NET Core Today and TomorrowJon Galloway
 
Rpc framework
Rpc frameworkRpc framework
Rpc frameworkjuly mon
 
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...apidays
 
apidays LIVE Jakarta - REST the events: REST APIs for Event-Driven Architectu...
apidays LIVE Jakarta - REST the events: REST APIs for Event-Driven Architectu...apidays LIVE Jakarta - REST the events: REST APIs for Event-Driven Architectu...
apidays LIVE Jakarta - REST the events: REST APIs for Event-Driven Architectu...apidays
 
The new (is it really ) api stack
The new (is it really ) api stackThe new (is it really ) api stack
The new (is it really ) api stackRed Hat
 
Creating microservices architectures using node.js and Kubernetes
Creating microservices architectures using node.js and KubernetesCreating microservices architectures using node.js and Kubernetes
Creating microservices architectures using node.js and KubernetesPaul Goldbaum
 
What you need to know about .NET Core 3.0 and beyond
What you need to know about .NET Core 3.0 and beyondWhat you need to know about .NET Core 3.0 and beyond
What you need to know about .NET Core 3.0 and beyondJon Galloway
 
gRPC and Microservices
gRPC and MicroservicesgRPC and Microservices
gRPC and MicroservicesJonathan Gomez
 
gRPC - Fastest Data Transfer Protocol
gRPC - Fastest Data Transfer ProtocolgRPC - Fastest Data Transfer Protocol
gRPC - Fastest Data Transfer ProtocolSougata Pal
 

Similar to Modern webservices using gRPC and Protocol Buffers in Golang (20)

What I learned about APIs in my first year at Google
What I learned about APIs in my first year at GoogleWhat I learned about APIs in my first year at Google
What I learned about APIs in my first year at Google
 
Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}
Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}
Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}
 
REST in Peace. Long live gRPC!
REST in Peace. Long live gRPC!REST in Peace. Long live gRPC!
REST in Peace. Long live gRPC!
 
Cloud Native API Design and Management
Cloud Native API Design and ManagementCloud Native API Design and Management
Cloud Native API Design and Management
 
gRPC
gRPCgRPC
gRPC
 
REST in Peace. Long live gRPC!
REST in Peace. Long live gRPC!REST in Peace. Long live gRPC!
REST in Peace. Long live gRPC!
 
Driving containerd operations with gRPC
Driving containerd operations with gRPCDriving containerd operations with gRPC
Driving containerd operations with gRPC
 
Presentation1.pptx
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
 
.NET Core Today and Tomorrow
.NET Core Today and Tomorrow.NET Core Today and Tomorrow
.NET Core Today and Tomorrow
 
Rpc framework
Rpc frameworkRpc framework
Rpc framework
 
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
 
apidays LIVE Jakarta - REST the events: REST APIs for Event-Driven Architectu...
apidays LIVE Jakarta - REST the events: REST APIs for Event-Driven Architectu...apidays LIVE Jakarta - REST the events: REST APIs for Event-Driven Architectu...
apidays LIVE Jakarta - REST the events: REST APIs for Event-Driven Architectu...
 
The new (is it really ) api stack
The new (is it really ) api stackThe new (is it really ) api stack
The new (is it really ) api stack
 
Creating microservices architectures using node.js and Kubernetes
Creating microservices architectures using node.js and KubernetesCreating microservices architectures using node.js and Kubernetes
Creating microservices architectures using node.js and Kubernetes
 
What you need to know about .NET Core 3.0 and beyond
What you need to know about .NET Core 3.0 and beyondWhat you need to know about .NET Core 3.0 and beyond
What you need to know about .NET Core 3.0 and beyond
 
gRPC services testing
gRPC services testinggRPC services testing
gRPC services testing
 
XML-RPC and SOAP (April 2003)
XML-RPC and SOAP (April 2003)XML-RPC and SOAP (April 2003)
XML-RPC and SOAP (April 2003)
 
gRPC and Microservices
gRPC and MicroservicesgRPC and Microservices
gRPC and Microservices
 
GRPC.pptx
GRPC.pptxGRPC.pptx
GRPC.pptx
 
gRPC - Fastest Data Transfer Protocol
gRPC - Fastest Data Transfer ProtocolgRPC - Fastest Data Transfer Protocol
gRPC - Fastest Data Transfer Protocol
 

Recently uploaded

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyAnusha Are
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park masabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 

Recently uploaded (20)

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

Modern webservices using gRPC and Protocol Buffers in Golang

  • 1. Creating modern webservices in Golang // Omid Hojabri // E-mail: o.hojabri@gmail.com // Skype: hojabri // LinkedIn: linkedin.com/in/hojabri using gRPC + Protocol Buffers
  • 2. REST : Popular API  REST (HTTP-JSON)  JSON  Format in URL:  GET /api/v1/user/231/roles/453  POST /api/v1/user/231/roles  PUT …  DELETE ...
  • 3. Concerns about APIs  Data size  Latency  Scalability  Load Balancing  Communication between languages  Authentication  Monitoring  Logging
  • 4. What is an API  Is a contract  Client sends REQUEST  Server sends RESPONSE
  • 5. gRPC  Is a free and open-source framework developed by  Allows to simply define REQUEST and RESPONSE for RPC (Remote Procedure Calls)  Modern, Fast, Efficient (based on HTTP/2)  Low latency  Supports streaming  Many languages support it  Authentication, Monitoring, Load balancing and Logging are easy to define with gRPC  Many companies like Google, Netflix, Square, CoreOS, Spotify, Docker, Cisco,… using it fully.
  • 6. Official supported languages  C/C++  Java  Android Java  Go  C#  Kotlin  Node.js  Objective-C  PHP (Beta)  Python  Ruby  Dart
  • 7. RPC  Remote Procedure Call  Client calls functions directly on the server  gRPC implements RPC very cleanly and it solves a lot of problems
  • 8. gRPC overview gRPC uses protocol buffers (protobuf) to communicate between clients and servers
  • 9. How it runs?  gRPC needs to define messages and services using Protocol Buffers  gRPC codes will be generated automatically with “protoc” command!  Data is binary  You need just implementing the methods defined based on your message type  Defining Protocol Buffers in .proto files.
  • 10. .proto files  We define messages and service definitions in .proto files.  (API contract)
  • 11. Types of API in gRPC 1 Unary 2 Server Streaming 3 Client Streaming 4 Bi-directional Streaming
  • 13. Server Streaming API Client Server Request Message 1 Message 2 Message 3 Message n . . . .
  • 14. Client Streaming API Client Server Message 1 Message 2 Message 3 Message n Response . . . .
  • 15. Bi-directional Streaming API Client Server Client Message 1 Client Message 2 Client Message 3 Server Message 3 Server Message 4 Server Message n Client Message 4 Client Message n Server Message 2 Server Message 1
  • 16. gRPC vs REST gRPC REST Data is binary, smaller and communication is faster (25 more performance based on benchmarks) Text based, bigger and slower HTTP/2 (Low latency) HTTP/1.1 (Higher latency) Unary, Server streaming, Client streaming, bi- directional streaming Request – Response only Any API commands CRUD (Create – Retrieve – Update – Delete) POST – GET – PUT - DELETE Code generation by protocol buffers in any language Manual code or by OpenAPI/Swagger RPC based HTTP words based
  • 17. Installation  Prerequisites:  Go to be installed (any one of the three latest major release)  Protocol Buffer compiler (protoc v3)  Go plugin for protocol compiler
  • 18. Protocol Buffer Compiler (v3)  The protocol buffer compiler (protoc) is used to compile (code generation) .proto files, which contain service and message definitions.  Linux:   MacOS: 
  • 19. Protocol Buffer Compiler (v3)  Windows:  Download and install the latest release of binary version from:  https://github.com/protocolbuffers/protobuf/releases/tag/v3.13.0  (at the moment v3.13.0 is released)
  • 20. Go plugin for the protocol buffers 1 Install the protocol compiler plugin for Go (protoc-gen-go) using the following command: 2 Update your PATH so that the protoc compiler can find the plugin:
  • 21. Installing dependencies  Installing go grpc module: https://github.com/grpc/grpc- go  (It may take some time to install completely)
  • 22. Configuration of a .proto file  Syntax version and package definition:
  • 23. Configuration of a .proto file  Message definition:
  • 24. Configuration of a .proto file  Service Definition:
  • 25. Generating Code  Will generate a file called “greet.pb.go”
  • 30. Full sample source code  I’ve uploaded my sample source code which covers all four types of gRPC API https://github.com/hojabri/grpc-pr
  • 31. Thank you Github: https://github.com/hojabri E-mail: o.hojabri@gmail.com Skype: hojabri LinkedIn: https://linkedin.com/in/hojabri