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 stackLuca Mattia Ferrari
 
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

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 

Recently uploaded (20)

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 

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