SlideShare a Scribd company logo
6
Most read
21
Most read
22
Most read
gRPC and Microservices
Jonathan Gomez
Golang Melbourne - June 2016 Go Hack Night
— Google open sourced in Feb 2015
— Transport: HTTP/2
— Wire format: Protocol Buffers v3 (Binary)
— Service definition: Protocol Buffers IDL
— Libraries in ~10 languages (native C, Go, Java)
— Microservices framework
What is gRPC for? (from official FAQ)
— Low latency, highly scalable, distributed systems
— Developing mobile clients which are communicating
to a cloud server
— Designing a new protocol that needs to be accurate,
efficient and language independent
— Layered design to enable extension e.g.
authentication, load balancing, logging and
monitoring etc
The Alternative?
— HTTP-JSON-REST APIs/Microservices
— Transport: HTTP/1.1
— Wire format: JSON (Text)
— Service definition:
— REST, Swagger, API Blueprint
— JSON Schema, strummer1
1
Developed for JSON validation and used within node.js services at Tabcorp.
HTTP/2 & Protobuf 101
HTTP/2 - Binary
HTTP/2 - Multiplexed
— multiple reqs/resps can be in-flight over one conn
— avoid multiple TCP conns to make parallel requests
HTTP/2 - Streams
— 'independent, bidirectional sequence of frames
exchanged between the client and server within an
HTTP/2 connection'
— beyond request/response
— effectively supercedes 'websockets'
Protocol Buffers
— mechanism for serializing structured data
— Interface Definition Language (IDL)
— binary, compact, fast
— versioned
syntax = "proto3";
message SearchRequest {
string query = 1;
int32 page_number = 2;
int32 result_per_page = 3;
}
Protocol Buffers
— strongly typed. .proto type -> Go type:
— float -> float32
— bool -> bool
— string -> string
— defaults, enums, nested types, Any, OneOf, maps
— proto3 easily transformed to JSON (for debugging!)
— https://developers.google.com/protocol-buffers/
Workflow
Example
— pinging tool redalert
— Go binary
— periodically runs checks on
various servers/DBs/
containers etc
— serves a status web page...
— lacks an API
— lacks a CLI
— lets build one with
Example - Define Service and Messages
syntax = "proto3";
package service;
service RedalertService {
rpc ListChecks(ListChecksRequest) returns (ListChecksResponse) {}
}
message ListChecksRequest {}
message ListChecksResponse {
repeated Check members = 1;
}
message Check {
string ID = 1;
string name = 2;
enum Status {
UNKNOWN = 0;
NORMAL = 1;
FAILING = 2;
RECOVERED = 3;
}
Status status = 3;
}
Example - Generate Server Interfaces and Client Stubs
Example - Generate Server Interfaces and Client Stubs
— Download compiler protoc via Github releases
— Install Go implementation of gRPC:
— go get -u google.golang.org/grpc
— protoc --go_out=plugins=grpc:.
service.proto
type RedalertServiceServer interface {
ListChecks(context.Context, *ListChecksRequest) (*ListChecksResponse, error)
}
Example - Implement Server
type server struct {}
func (s *server) ListChecks(ctx context.Context, in *pb.ListChecksRequest) (*pb.ListChecksResponse, error) {
...insert business logic here
}
lis, err := net.Listen("tcp", ":50051")
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
pb.RegisterRedalertServiceServer(s, &server{})
s.Serve(lis)
Example - Implement Client
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
log.Fatalf("did not connect: %v", err)
}
defer conn.Close()
c := pb.NewRedalertServiceClient(conn)
r, err := c.ListChecks(context.Background(), &pb.ListChecksRequest{})
if err != nil {
log.Fatalf("could not get response: %v", err)
}
Microservices Framework
— 4 kinds of service methods
// Request-response
rpc ListChecks(ListChecksRequest) returns (ListChecksResponse) {}
// Server-to-client streaming
rpc StreamEvents(StreamEventsRequest) returns (stream Event) {}
// Client-to-server streaming
rpc SendHeartbeat(stream Heartbeat) returns (HeartbeatResponse) {}
// Bi-directional streaming
rpc NodeChat(stream HealthCheck) returns (stream HealthCheck) {}
— Pre-defined error status codes
Backwards Compatibility
— Run a reverse proxy JSON API in front of gRPC server
— Generate via github.com/gengo/grpc-gateway
Advanced gRPC
— Context (e.g. propagating timeouts & cancellations)
— Interceptors
— Authentication
— Service discovery / client-side load balancing
— Extend common functionality via protobuf IDL
Key Benefits
— Focus on the service/API design
— Freedom to pick language which suits the problem
— Server-to-server friendly
— Server-to-mobile friendly
— Growing community. Square, CoreOS, Docker.
References
— http://www.grpc.io/
— https://developers.google.com/protocol-buffers/
— https://github.com/grpc/grpc-go
— gRPC with REST and Open APIs
— https://www.nginx.com/blog/http2-module-nginx/

More Related Content

PDF
gRPC Overview
PPTX
HTTP2 and gRPC
PPTX
REST vs gRPC: Battle of API's
PPTX
GRPC.pptx
PDF
Designing APIs with OpenAPI Spec
PPTX
Owl: The New Odoo UI Framework
PPTX
Dev Containers Spring 2023.pptx
PDF
Web Services (SOAP, WSDL, UDDI)
gRPC Overview
HTTP2 and gRPC
REST vs gRPC: Battle of API's
GRPC.pptx
Designing APIs with OpenAPI Spec
Owl: The New Odoo UI Framework
Dev Containers Spring 2023.pptx
Web Services (SOAP, WSDL, UDDI)

What's hot (20)

PDF
Introduction to gRPC
PDF
Building microservices with grpc
PDF
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
PPTX
Introduction to gRPC
PDF
gRPC Design and Implementation
PDF
gRPC - RPC rebirth?
PDF
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...
PDF
OpenAPI and gRPC Side by-Side
PDF
gRPC vs REST: let the battle begin!
PDF
gRPC with java
PDF
Power-up services with gRPC
PPTX
What is gRPC introduction gRPC Explained
PDF
Inter-Process Communication in Microservices using gRPC
PDF
Building Microservices with gRPC and NATS
PDF
gRPC in Go
ODP
Protocol Buffers
PPTX
Building your First gRPC Service
Introduction to gRPC
Building microservices with grpc
Robert Kubis - gRPC - boilerplate to high-performance scalable APIs - code.t...
Introduction to gRPC
gRPC Design and Implementation
gRPC - RPC rebirth?
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...
OpenAPI and gRPC Side by-Side
gRPC vs REST: let the battle begin!
gRPC with java
Power-up services with gRPC
What is gRPC introduction gRPC Explained
Inter-Process Communication in Microservices using gRPC
Building Microservices with gRPC and NATS
gRPC in Go
Protocol Buffers
Building your First gRPC Service
Ad

Similar to gRPC and Microservices (20)

PDF
Microservices Communication Patterns with gRPC
PPTX
CocoaConf: The Language of Mobile Software is APIs
PDF
Driving containerd operations with gRPC
PPTX
What I learned about APIs in my first year at Google
PDF
KrakenD API Gateway
PDF
Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}
PDF
Creating Great REST and gRPC API Experiences (in Swift)
PPTX
Modern webservices using gRPC and Protocol Buffers in Golang
PPTX
ASP.NET Core 3.0 Deep Dive
PDF
Protobuf & Code Generation + Go-Kit
PPTX
Managing gRPC Services using Kong KONNECT and the KONG API Gateway
PPTX
Apa itu gRPC_.pptx
PDF
XML-RPC and SOAP (April 2003)
PDF
REST in Peace. Long live gRPC!
PPT
Rapid java backend and api development for mobile devices
PDF
Fast and Reliable Swift APIs with gRPC
PDF
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
PDF
Database Tools by Skype
PDF
REST in Peace. Long live gRPC!
PDF
Networked APIs with swift
Microservices Communication Patterns with gRPC
CocoaConf: The Language of Mobile Software is APIs
Driving containerd operations with gRPC
What I learned about APIs in my first year at Google
KrakenD API Gateway
Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}
Creating Great REST and gRPC API Experiences (in Swift)
Modern webservices using gRPC and Protocol Buffers in Golang
ASP.NET Core 3.0 Deep Dive
Protobuf & Code Generation + Go-Kit
Managing gRPC Services using Kong KONNECT and the KONG API Gateway
Apa itu gRPC_.pptx
XML-RPC and SOAP (April 2003)
REST in Peace. Long live gRPC!
Rapid java backend and api development for mobile devices
Fast and Reliable Swift APIs with gRPC
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
Database Tools by Skype
REST in Peace. Long live gRPC!
Networked APIs with swift
Ad

Recently uploaded (20)

PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
System and Network Administration Chapter 2
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
System and Network Administraation Chapter 3
PPT
Introduction Database Management System for Course Database
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Nekopoi APK 2025 free lastest update
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
top salesforce developer skills in 2025.pdf
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
ai tools demonstartion for schools and inter college
Odoo POS Development Services by CandidRoot Solutions
System and Network Administration Chapter 2
2025 Textile ERP Trends: SAP, Odoo & Oracle
System and Network Administraation Chapter 3
Introduction Database Management System for Course Database
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Nekopoi APK 2025 free lastest update
Understanding Forklifts - TECH EHS Solution
Upgrade and Innovation Strategies for SAP ERP Customers
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Online Work Permit System for Fast Permit Processing
Odoo Companies in India – Driving Business Transformation.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Adobe Illustrator 28.6 Crack My Vision of Vector Design
top salesforce developer skills in 2025.pdf
Which alternative to Crystal Reports is best for small or large businesses.pdf
How Creative Agencies Leverage Project Management Software.pdf
ai tools demonstartion for schools and inter college

gRPC and Microservices

  • 1. gRPC and Microservices Jonathan Gomez Golang Melbourne - June 2016 Go Hack Night
  • 2. — Google open sourced in Feb 2015 — Transport: HTTP/2 — Wire format: Protocol Buffers v3 (Binary) — Service definition: Protocol Buffers IDL — Libraries in ~10 languages (native C, Go, Java) — Microservices framework
  • 3. What is gRPC for? (from official FAQ) — Low latency, highly scalable, distributed systems — Developing mobile clients which are communicating to a cloud server — Designing a new protocol that needs to be accurate, efficient and language independent — Layered design to enable extension e.g. authentication, load balancing, logging and monitoring etc
  • 4. The Alternative? — HTTP-JSON-REST APIs/Microservices — Transport: HTTP/1.1 — Wire format: JSON (Text) — Service definition: — REST, Swagger, API Blueprint — JSON Schema, strummer1 1 Developed for JSON validation and used within node.js services at Tabcorp.
  • 7. HTTP/2 - Multiplexed — multiple reqs/resps can be in-flight over one conn — avoid multiple TCP conns to make parallel requests
  • 8. HTTP/2 - Streams — 'independent, bidirectional sequence of frames exchanged between the client and server within an HTTP/2 connection' — beyond request/response — effectively supercedes 'websockets'
  • 9. Protocol Buffers — mechanism for serializing structured data — Interface Definition Language (IDL) — binary, compact, fast — versioned syntax = "proto3"; message SearchRequest { string query = 1; int32 page_number = 2; int32 result_per_page = 3; }
  • 10. Protocol Buffers — strongly typed. .proto type -> Go type: — float -> float32 — bool -> bool — string -> string — defaults, enums, nested types, Any, OneOf, maps — proto3 easily transformed to JSON (for debugging!) — https://developers.google.com/protocol-buffers/
  • 12. Example — pinging tool redalert — Go binary — periodically runs checks on various servers/DBs/ containers etc — serves a status web page... — lacks an API — lacks a CLI — lets build one with
  • 13. Example - Define Service and Messages syntax = "proto3"; package service; service RedalertService { rpc ListChecks(ListChecksRequest) returns (ListChecksResponse) {} } message ListChecksRequest {} message ListChecksResponse { repeated Check members = 1; } message Check { string ID = 1; string name = 2; enum Status { UNKNOWN = 0; NORMAL = 1; FAILING = 2; RECOVERED = 3; } Status status = 3; }
  • 14. Example - Generate Server Interfaces and Client Stubs
  • 15. Example - Generate Server Interfaces and Client Stubs — Download compiler protoc via Github releases — Install Go implementation of gRPC: — go get -u google.golang.org/grpc — protoc --go_out=plugins=grpc:. service.proto type RedalertServiceServer interface { ListChecks(context.Context, *ListChecksRequest) (*ListChecksResponse, error) }
  • 16. Example - Implement Server type server struct {} func (s *server) ListChecks(ctx context.Context, in *pb.ListChecksRequest) (*pb.ListChecksResponse, error) { ...insert business logic here } lis, err := net.Listen("tcp", ":50051") if err != nil { log.Fatalf("failed to listen: %v", err) } s := grpc.NewServer() pb.RegisterRedalertServiceServer(s, &server{}) s.Serve(lis)
  • 17. Example - Implement Client conn, err := grpc.Dial(address, grpc.WithInsecure()) if err != nil { log.Fatalf("did not connect: %v", err) } defer conn.Close() c := pb.NewRedalertServiceClient(conn) r, err := c.ListChecks(context.Background(), &pb.ListChecksRequest{}) if err != nil { log.Fatalf("could not get response: %v", err) }
  • 18. Microservices Framework — 4 kinds of service methods // Request-response rpc ListChecks(ListChecksRequest) returns (ListChecksResponse) {} // Server-to-client streaming rpc StreamEvents(StreamEventsRequest) returns (stream Event) {} // Client-to-server streaming rpc SendHeartbeat(stream Heartbeat) returns (HeartbeatResponse) {} // Bi-directional streaming rpc NodeChat(stream HealthCheck) returns (stream HealthCheck) {} — Pre-defined error status codes
  • 19. Backwards Compatibility — Run a reverse proxy JSON API in front of gRPC server — Generate via github.com/gengo/grpc-gateway
  • 20. Advanced gRPC — Context (e.g. propagating timeouts & cancellations) — Interceptors — Authentication — Service discovery / client-side load balancing — Extend common functionality via protobuf IDL
  • 21. Key Benefits — Focus on the service/API design — Freedom to pick language which suits the problem — Server-to-server friendly — Server-to-mobile friendly — Growing community. Square, CoreOS, Docker.
  • 22. References — http://www.grpc.io/ — https://developers.google.com/protocol-buffers/ — https://github.com/grpc/grpc-go — gRPC with REST and Open APIs — https://www.nginx.com/blog/http2-module-nginx/