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

PDF
Build your next REST API with gRPC
PDF
Implementing OpenAPI and GraphQL services with gRPC
PDF
Enforcing API Design Rules for High Quality Code Generation
PDF
Build Great Networked APIs with Swift, OpenAPI, and gRPC
PPTX
CocoaConf: The Language of Mobile Software is APIs
PDF
Fast and Reliable Swift APIs with gRPC
PDF
Creating Great REST and gRPC API Experiences (in Swift)
PDF
Networked APIs with swift
Build your next REST API with gRPC
Implementing OpenAPI and GraphQL services with gRPC
Enforcing API Design Rules for High Quality Code Generation
Build Great Networked APIs with Swift, OpenAPI, and gRPC
CocoaConf: The Language of Mobile Software is APIs
Fast and Reliable Swift APIs with gRPC
Creating Great REST and gRPC API Experiences (in Swift)
Networked APIs with swift

What's hot (20)

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

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

PDF
gRPC and Microservices
PPTX
What I learned about APIs in my first year at Google
PPTX
Go to gRPC
PPTX
Introduction to gRPC. Advantages and Disadvantages
PDF
Microservices Communication Patterns with gRPC
PDF
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
PPTX
Demystifying gRPC in .Net by John Staveley
PDF
APIdays Helsinki 2019 - gRPC: Lightning Fast, Self-Documenting APIs with Moha...
PDF
gRPC with java
PPTX
Grpc present
PPTX
The new (is it really ) api stack
PDF
Building Language Agnostic APIs with gRPC - JavaDay Istanbul 2017
PDF
Build microservice with gRPC in golang
PDF
gRPC in Go
PPTX
Building API Using GRPC And Scala
PPTX
GRPC.pptx
PPTX
Introduction to gRPC (Application) Presentation
PPTX
Introduction to gRPC Presentation (Java)
PPTX
Managing gRPC Services using Kong KONNECT and the KONG API Gateway
gRPC and Microservices
What I learned about APIs in my first year at Google
Go to gRPC
Introduction to gRPC. Advantages and Disadvantages
Microservices Communication Patterns with gRPC
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
Demystifying gRPC in .Net by John Staveley
APIdays Helsinki 2019 - gRPC: Lightning Fast, Self-Documenting APIs with Moha...
gRPC with java
Grpc present
The new (is it really ) api stack
Building Language Agnostic APIs with gRPC - JavaDay Istanbul 2017
Build microservice with gRPC in golang
gRPC in Go
Building API Using GRPC And Scala
GRPC.pptx
Introduction to gRPC (Application) Presentation
Introduction to gRPC Presentation (Java)
Managing gRPC Services using Kong KONNECT and the KONG API Gateway
Ad

Recently uploaded (20)

PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
medical staffing services at VALiNTRY
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PPTX
ai tools demonstartion for schools and inter college
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Transform Your Business with a Software ERP System
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
AI in Product Development-omnex systems
PDF
top salesforce developer skills in 2025.pdf
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Wondershare Filmora 15 Crack With Activation Key [2025
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
medical staffing services at VALiNTRY
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
ai tools demonstartion for schools and inter college
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Transform Your Business with a Software ERP System
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Navsoft: AI-Powered Business Solutions & Custom Software Development
Odoo POS Development Services by CandidRoot Solutions
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Internet Downloader Manager (IDM) Crack 6.42 Build 41
AI in Product Development-omnex systems
top salesforce developer skills in 2025.pdf
Reimagine Home Health with the Power of Agentic AI​
How to Choose the Right IT Partner for Your Business in Malaysia

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