SlideShare a Scribd company logo
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 (20)

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

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

PDF
gRPC and Microservices
Jonathan Gomez
 
PPTX
What I learned about APIs in my first year at Google
Tim Burks
 
PPTX
Go to gRPC
Naren Arya
 
PPTX
Introduction to gRPC. Advantages and Disadvantages
abdulrehmanlatif65
 
PDF
Microservices Communication Patterns with gRPC
WSO2
 
PDF
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays
 
PPTX
Demystifying gRPC in .Net by John Staveley
John Staveley
 
PDF
APIdays Helsinki 2019 - gRPC: Lightning Fast, Self-Documenting APIs with Moha...
apidays
 
PDF
gRPC with java
Knoldus Inc.
 
PPTX
Grpc present
Phạm Hải Anh
 
PPTX
The new (is it really ) api stack
Red Hat
 
PDF
Building Language Agnostic APIs with gRPC - JavaDay Istanbul 2017
Mustafa AKIN
 
PDF
Build microservice with gRPC in golang
Ting-Li Chou
 
PDF
gRPC in Go
Almog Baku
 
PPTX
Building API Using GRPC And Scala
Knoldus Inc.
 
PPTX
GRPC.pptx
Afzal Juneja
 
PPTX
Introduction to gRPC (Application) Presentation
Knoldus Inc.
 
PPTX
Introduction to gRPC Presentation (Java)
Knoldus Inc.
 
PPTX
Managing gRPC Services using Kong KONNECT and the KONG API Gateway
João Esperancinha
 
gRPC and Microservices
Jonathan Gomez
 
What I learned about APIs in my first year at Google
Tim Burks
 
Go to gRPC
Naren Arya
 
Introduction to gRPC. Advantages and Disadvantages
abdulrehmanlatif65
 
Microservices Communication Patterns with gRPC
WSO2
 
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
apidays
 
Demystifying gRPC in .Net by John Staveley
John Staveley
 
APIdays Helsinki 2019 - gRPC: Lightning Fast, Self-Documenting APIs with Moha...
apidays
 
gRPC with java
Knoldus Inc.
 
Grpc present
Phạm Hải Anh
 
The new (is it really ) api stack
Red Hat
 
Building Language Agnostic APIs with gRPC - JavaDay Istanbul 2017
Mustafa AKIN
 
Build microservice with gRPC in golang
Ting-Li Chou
 
gRPC in Go
Almog Baku
 
Building API Using GRPC And Scala
Knoldus Inc.
 
GRPC.pptx
Afzal Juneja
 
Introduction to gRPC (Application) Presentation
Knoldus Inc.
 
Introduction to gRPC Presentation (Java)
Knoldus Inc.
 
Managing gRPC Services using Kong KONNECT and the KONG API Gateway
João Esperancinha
 
Ad

Recently uploaded (20)

PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PDF
Executive Business Intelligence Dashboards
vandeslie24
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PDF
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
PDF
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Executive Business Intelligence Dashboards
vandeslie24
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Revenue streams of the Wazirx clone script.pdf
aaronjeffray
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Feb 2021 Cohesity first pitch presentation.pptx
enginsayin1
 
Beyond Binaries: Understanding Diversity and Allyship in a Global Workplace -...
Imma Valls Bernaus
 
Tally software_Introduction_Presentation
AditiBansal54083
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Ad

Modern webservices using gRPC and Protocol Buffers in Golang

  • 1. Creating modern webservices in Golang // Omid Hojabri // E-mail: [email protected] // 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: [email protected] Skype: hojabri LinkedIn: https://linkedin.com/in/hojabri