SlideShare une entreprise Scribd logo
1  sur  22
Télécharger pour lire hors ligne
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/

Contenu connexe

Tendances

REST vs gRPC: Battle of API's
REST vs gRPC: Battle of API'sREST vs gRPC: Battle of API's
REST vs gRPC: Battle of API'sLuram Archanjo
 
What is gRPC introduction gRPC Explained
What is gRPC introduction gRPC ExplainedWhat is gRPC introduction gRPC Explained
What is gRPC introduction gRPC Explainedjeetendra mandal
 
OpenAPI and gRPC Side by-Side
OpenAPI and gRPC Side by-SideOpenAPI and gRPC Side by-Side
OpenAPI and gRPC Side by-SideTim Burks
 
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...Codemotion
 
Building your First gRPC Service
Building your First gRPC ServiceBuilding your First gRPC Service
Building your First gRPC ServiceJessie Barnett
 
Cilium - API-aware Networking and Security for Containers based on BPF
Cilium - API-aware Networking and Security for Containers based on BPFCilium - API-aware Networking and Security for Containers based on BPF
Cilium - API-aware Networking and Security for Containers based on BPFThomas Graf
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golangBo-Yi Wu
 
Cilium - Network security for microservices
Cilium - Network security for microservicesCilium - Network security for microservices
Cilium - Network security for microservicesThomas Graf
 
Coding with golang
Coding with golangCoding with golang
Coding with golangHannahMoss14
 

Tendances (20)

GRPC.pptx
GRPC.pptxGRPC.pptx
GRPC.pptx
 
Introduction to gRPC
Introduction to gRPCIntroduction to gRPC
Introduction to gRPC
 
Building microservices with grpc
Building microservices with grpcBuilding microservices with grpc
Building microservices with grpc
 
gRPC
gRPC gRPC
gRPC
 
gRPC in Go
gRPC in GogRPC in Go
gRPC in Go
 
gRPC
gRPCgRPC
gRPC
 
REST vs gRPC: Battle of API's
REST vs gRPC: Battle of API'sREST vs gRPC: Battle of API's
REST vs gRPC: Battle of API's
 
gRPC with java
gRPC with javagRPC with java
gRPC with java
 
What is gRPC introduction gRPC Explained
What is gRPC introduction gRPC ExplainedWhat is gRPC introduction gRPC Explained
What is gRPC introduction gRPC Explained
 
OpenAPI and gRPC Side by-Side
OpenAPI and gRPC Side by-SideOpenAPI and gRPC Side by-Side
OpenAPI and gRPC Side by-Side
 
Protocol Buffers
Protocol BuffersProtocol Buffers
Protocol Buffers
 
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...
 
Building your First gRPC Service
Building your First gRPC ServiceBuilding your First gRPC Service
Building your First gRPC Service
 
Cilium - API-aware Networking and Security for Containers based on BPF
Cilium - API-aware Networking and Security for Containers based on BPFCilium - API-aware Networking and Security for Containers based on BPF
Cilium - API-aware Networking and Security for Containers based on BPF
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
Cilium - Network security for microservices
Cilium - Network security for microservicesCilium - Network security for microservices
Cilium - Network security for microservices
 
Node js for beginners
Node js for beginnersNode js for beginners
Node js for beginners
 
Coding with golang
Coding with golangCoding with golang
Coding with golang
 
GoLang Introduction
GoLang IntroductionGoLang Introduction
GoLang Introduction
 
Go at uber
Go at uberGo at uber
Go at uber
 

Similaire à gRPC and Microservices

Microservices Communication Patterns with gRPC
Microservices Communication Patterns with gRPCMicroservices Communication Patterns with gRPC
Microservices Communication Patterns with gRPCWSO2
 
CocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIsCocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIsTim Burks
 
Driving containerd operations with gRPC
Driving containerd operations with gRPCDriving containerd operations with gRPC
Driving containerd operations with gRPCDocker, Inc.
 
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
 
Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)Tim Burks
 
Modern webservices using gRPC and Protocol Buffers in Golang
Modern webservices using gRPC and Protocol Buffers in GolangModern webservices using gRPC and Protocol Buffers in Golang
Modern webservices using gRPC and Protocol Buffers in GolangOmidHojabri1
 
ASP.NET Core 3.0 Deep Dive
ASP.NET Core 3.0 Deep DiveASP.NET Core 3.0 Deep Dive
ASP.NET Core 3.0 Deep DiveJon Galloway
 
Protobuf & Code Generation + Go-Kit
Protobuf & Code Generation + Go-KitProtobuf & Code Generation + Go-Kit
Protobuf & Code Generation + Go-KitManfred Touron
 
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
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesciklum_ods
 
Fast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCFast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCTim Burks
 
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
 
Database Tools by Skype
Database Tools by SkypeDatabase Tools by Skype
Database Tools by Skypeelliando dias
 
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
 
Networked APIs with swift
Networked APIs with swiftNetworked APIs with swift
Networked APIs with swiftTim Burks
 
Deep Dive into SpaceONE
Deep Dive into SpaceONEDeep Dive into SpaceONE
Deep Dive into SpaceONEChoonho Son
 

Similaire à gRPC and Microservices (20)

Microservices Communication Patterns with gRPC
Microservices Communication Patterns with gRPCMicroservices Communication Patterns with gRPC
Microservices Communication Patterns with gRPC
 
CocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIsCocoaConf: The Language of Mobile Software is APIs
CocoaConf: The Language of Mobile Software is APIs
 
Driving containerd operations with gRPC
Driving containerd operations with gRPCDriving containerd operations with gRPC
Driving containerd operations with gRPC
 
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
 
KrakenD API Gateway
KrakenD API GatewayKrakenD API Gateway
KrakenD API Gateway
 
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}
 
Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)Creating Great REST and gRPC API Experiences (in Swift)
Creating Great REST and gRPC API Experiences (in Swift)
 
Modern webservices using gRPC and Protocol Buffers in Golang
Modern webservices using gRPC and Protocol Buffers in GolangModern webservices using gRPC and Protocol Buffers in Golang
Modern webservices using gRPC and Protocol Buffers in Golang
 
ASP.NET Core 3.0 Deep Dive
ASP.NET Core 3.0 Deep DiveASP.NET Core 3.0 Deep Dive
ASP.NET Core 3.0 Deep Dive
 
Protobuf & Code Generation + Go-Kit
Protobuf & Code Generation + Go-KitProtobuf & Code Generation + Go-Kit
Protobuf & Code Generation + Go-Kit
 
Apa itu gRPC_.pptx
Apa itu gRPC_.pptxApa itu gRPC_.pptx
Apa itu gRPC_.pptx
 
XML-RPC and SOAP (April 2003)
XML-RPC and SOAP (April 2003)XML-RPC and SOAP (April 2003)
XML-RPC and SOAP (April 2003)
 
REST in Peace. Long live gRPC!
REST in Peace. Long live gRPC!REST in Peace. Long live gRPC!
REST in Peace. Long live gRPC!
 
Rapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devicesRapid java backend and api development for mobile devices
Rapid java backend and api development for mobile devices
 
Fast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCFast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPC
 
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...
 
Database Tools by Skype
Database Tools by SkypeDatabase Tools by Skype
Database Tools by Skype
 
REST in Peace. Long live gRPC!
REST in Peace. Long live gRPC!REST in Peace. Long live gRPC!
REST in Peace. Long live gRPC!
 
Networked APIs with swift
Networked APIs with swiftNetworked APIs with swift
Networked APIs with swift
 
Deep Dive into SpaceONE
Deep Dive into SpaceONEDeep Dive into SpaceONE
Deep Dive into SpaceONE
 

Dernier

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
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
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
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
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.
 

Dernier (20)

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
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
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
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
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-...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
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 ...
 

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/