SlideShare a Scribd company logo
Building Microservices with gRPC and
NATS
Shiju Varghese
Consulting Solutions Architect
April 28, 2017
About Me
• Consulting Solutions Architect and Trainer
• Focused on Golang, Microservices and Cloud-Native
distributed systems architectures
• Published Author: “Web Development with Go” and “Go
Recipes”
• Honoured with Microsoft MVP award seven times
• Blog: https://medium.com/@shijuvar
Agenda
• Inter-Process communications in Microservices
architecture
• Building high performance APIs with gRPC and Protocol
Buffers
• Building Microservices with event-driven architectures
using NATS
MICROSERVICES
ARCHITECTURE
Monolithic Architecture
Catalog Management
Customer Accounts
Orders Management
Payment
Monolithic
Database
Monolithic E-Commerce App
eCom Store Web
Shipment
Moving to Microservices
Catalog Management
Customer Accounts
Orders Management
Payment
eCom Store Web
Shipment
Catalog DB
Accounts DB
Orders DB
Payment DB
Store DB
Shipment DB
Microservices
• Software broken up into functional components
• Componentization via Services in which each service is
packaged as one unit of execution
• Independent, autonomous process with no dependency
on other Microservices
• Autonomous services around Bounded Context
• Decentralization of data management
• Independently replaceable and upgradeable
Challenges
• A business transaction may span into multiple services
• Decentralization of data management
• Communications between Microservices without having
any performance bottleneck
Inter-Process Communications between
Microservices
• Communications over high performance APIs
• Event-Driven architecture using messaging systems
Design Considerations for Building APIs
• Scaling APIs into millions (even billions) of APIs calls
• Wire format; Serialisation and deserialisation of
messages
• Building streaming APIs
• RESTful Vs RPC?
• Text encoding Vs binary encoding?
Why not REST
• Uses HTTP/1.x; Separate TCP Connection per request
• Text on the wire; Not performance efficient
• Harder API evolution
• Not Domain-Specific
• Not strongly-typed
• Lack of streaming capabilities
GRPC AND PROTOCOL
BUFFERS
What is gRPC
• High performance, open-source universal RPC
framework
• A Cloud Native Computing Foundation(CNCF) project
• Open source version of Google’s internal framework
Stubby
• Uses Protocol Buffers as the IDL
• HTTP/2 for transport
• Bi-Directional streaming
• RPC is efficient, domain-specific and strongly-typed
• Works across languages and platforms
Protocol Buffers
• Google's language-neutral, platform-neutral, extensible
mechanism for serialising structured data
• IDL - Describe once and generate interfaces for multiple
languages
• Structure of the Request and Response
• Binary format for network transmission
• Supports multiple languages
Communication between gRPC Server and
Client app
Types of RPC Methods
• Simple RPC
• Server-side streaming RPC
• Client-side streaming RPC
• Bi-directional streaming RPC
gRPC Workflow
ProtoBuf
Definitions
protoc
Compiler
Go
Ruby
Java gRPC Server
gRPC Client
Define1 Compile2
Implement3Generate Code
protoc --go_out=plugins=grpc
DEMO
grpc-gateway - gRPC to JSON Proxy Generator
BUILDING MICROSERVICES
WITH EVENT-DRIVEN
ARCHITECTURE USING NATS
Inter-Process Communication Using an Event-
Driven Architecture
Event-Sourcing
Aggregate ID
Aggregate
Type
Event ID Event Type Event Data
301 Order 1001 OrderCreated …
301 Order 1002 OrderApproved …
301 Order 1003 OrderShipped …
301 Order 1004 OrderDelivered …
Event Table
• Open source, lightweight, high-performance cloud
native messaging system
• Highly performant, extremely light-weight; Capable of
sending 11-12 million messages per second
• Publish-Subscribe messaging system
• Available in two interoperable modules:
• NATS Server
• NATS Streaming Server (with persistent messaging)
Introducing NATS - Shiju Varghese's Blog
Chart source: bravenewgeek.com/dissecting-message-queues
Messaging Patterns
• Publish-Subscribe
• Queueing
• Request-Replay
Components of Messaging Architecture
• Message: Messages are the unit of data exchange. A
payload, which is used for exchanging the data between
applications.
• Subject: Subject specifies the destination of messages.
• Producer: Producers send messages to the NATS server.
• Consumer: Consumers receive messages from the NATS
server.
• Messaging Server: NATS Server distributes the messages
from producers to consumers.
Publish-Subscribe
DEMO
Demo App - Workflow
OrderService -
gRPC Server
gRPC client
Subscriber
OrderCreated
Event
Subscriber
Subscriber
Queue
Group
NATS publisher, which publishes events
when new orders are created
RPC call for creating a new order
Example Source: https://github.com/shijuvar/gokit/tree/master/examples/grpc-nats
Thank you
Blog: medium.com/@shijuvar
LinkedIn: linkedin.com/in/shijuvar
Email: gophermonk@gmail.com

More Related Content

PPTX
Introduction to gRPC
PDF
Introduction to gRPC
PPTX
REST vs gRPC: Battle of API's
PPTX
Interop 2018 - Understanding Kubernetes - Brian Gracely
PDF
gRPC Overview
PDF
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...
PPTX
What is gRPC introduction gRPC Explained
Introduction to gRPC
Introduction to gRPC
REST vs gRPC: Battle of API's
Interop 2018 - Understanding Kubernetes - Brian Gracely
gRPC Overview
Introduction to gRPC: A general RPC framework that puts mobile and HTTP/2 fir...
What is gRPC introduction gRPC Explained

What's hot (20)

PDF
Building microservices with grpc
PDF
Inter-Process Communication in Microservices using gRPC
PPTX
GRPC.pptx
PDF
gRPC - RPC rebirth?
PDF
gRPC Design and Implementation
PPTX
Kubernetes for Beginners: An Introductory Guide
PDF
Kubernetes
PPTX
Introduction to Docker - 2017
PDF
An Introduction to Kubernetes
PDF
Helm - Application deployment management for Kubernetes
PDF
Docker Introduction
PPTX
Introduction to microservices
PDF
Kubernetes architecture
PDF
Kubernetes dealing with storage and persistence
PPTX
HTTP2 and gRPC
PDF
CI:CD in Lightspeed with kubernetes and argo cd
PDF
gRPC with java
PDF
Monitoring Kubernetes with Prometheus
PPSX
Event Sourcing & CQRS, Kafka, Rabbit MQ
PDF
Event-Driven Microservices With NATS Streaming
Building microservices with grpc
Inter-Process Communication in Microservices using gRPC
GRPC.pptx
gRPC - RPC rebirth?
gRPC Design and Implementation
Kubernetes for Beginners: An Introductory Guide
Kubernetes
Introduction to Docker - 2017
An Introduction to Kubernetes
Helm - Application deployment management for Kubernetes
Docker Introduction
Introduction to microservices
Kubernetes architecture
Kubernetes dealing with storage and persistence
HTTP2 and gRPC
CI:CD in Lightspeed with kubernetes and argo cd
gRPC with java
Monitoring Kubernetes with Prometheus
Event Sourcing & CQRS, Kafka, Rabbit MQ
Event-Driven Microservices With NATS Streaming
Ad

Similar to Building Microservices with gRPC and NATS (20)

PPTX
CocoaConf: The Language of Mobile Software is APIs
PPTX
Yotpo microservices
PDF
gRPC or Rest, why not both?
PPTX
Introduction to gRPC. Advantages and Disadvantages
PDF
Building Language Agnostic APIs with gRPC - JavaDay Istanbul 2017
PPTX
gRPC - Fastest Data Transfer Protocol
PDF
gRPC Microservices in Go (MEAP V08) Hüseyin Babal
PDF
Fast and Reliable Swift APIs with gRPC
PPTX
gRPC on .NET Core - NDC Sydney 2019
PDF
Microservices Communication Patterns with gRPC
PDF
Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}
PDF
Usable APIs at Scale
PPTX
Akka gRPC Essentials A Hands-On Introduction
PDF
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
PDF
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
PPTX
Building API Using GRPC And Scala
PDF
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
PDF
NATS in action - A Real time Microservices Architecture handled by NATS
PDF
Nats in action a real time microservices architecture handled by nats
PPTX
gRPC on .NET Core - NDC Oslo 2020
CocoaConf: The Language of Mobile Software is APIs
Yotpo microservices
gRPC or Rest, why not both?
Introduction to gRPC. Advantages and Disadvantages
Building Language Agnostic APIs with gRPC - JavaDay Istanbul 2017
gRPC - Fastest Data Transfer Protocol
gRPC Microservices in Go (MEAP V08) Hüseyin Babal
Fast and Reliable Swift APIs with gRPC
gRPC on .NET Core - NDC Sydney 2019
Microservices Communication Patterns with gRPC
Up and Running with gRPC & Cloud Career [GDG-Cloud-Dhaka-IO/2022}
Usable APIs at Scale
Akka gRPC Essentials A Hands-On Introduction
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC b...
Microservices in Go_Dessi_Massimiliano_Codemotion_2017_Rome
Building API Using GRPC And Scala
Bringing Learnings from Googley Microservices with gRPC - Varun Talwar, Google
NATS in action - A Real time Microservices Architecture handled by NATS
Nats in action a real time microservices architecture handled by nats
gRPC on .NET Core - NDC Oslo 2020
Ad

More from Shiju Varghese (20)

PDF
Building Modern Distributed Applications in Go with Service Weaver
PDF
Microservices in Go with Go kit
PDF
NATS: A Cloud Native Messaging System
PDF
Building High Performance APIs In Go Using gRPC And Protocol Buffers
PDF
Building Scalable Backends with Go
PDF
A Primer to Containerization & Microservices
PDF
Writing HTTP Middleware In Go
PDF
Building RESTful Services With Go and MongoDB
PDF
Docker and Kubernetes
PDF
Practicing Mindfulness
PPSX
Azure DocumentDB
PPSX
Azure Mobile Services .NET Backend
PDF
Windows Azure Mobile Services
PDF
JavaScript, Meet Cloud : Node.js on Windows Azure
PPSX
Introduction to Node js
PPSX
Windows Azure Cloud Services
PPSX
Windows Azure Webs Sites
PPS
Building Apps with Node.js
PPSX
Node on Windows Azure
PPTX
Introducing Razor - A new view engine for ASP.NET
Building Modern Distributed Applications in Go with Service Weaver
Microservices in Go with Go kit
NATS: A Cloud Native Messaging System
Building High Performance APIs In Go Using gRPC And Protocol Buffers
Building Scalable Backends with Go
A Primer to Containerization & Microservices
Writing HTTP Middleware In Go
Building RESTful Services With Go and MongoDB
Docker and Kubernetes
Practicing Mindfulness
Azure DocumentDB
Azure Mobile Services .NET Backend
Windows Azure Mobile Services
JavaScript, Meet Cloud : Node.js on Windows Azure
Introduction to Node js
Windows Azure Cloud Services
Windows Azure Webs Sites
Building Apps with Node.js
Node on Windows Azure
Introducing Razor - A new view engine for ASP.NET

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
Electronic commerce courselecture one. Pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
KodekX | Application Modernization Development
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Modernizing your data center with Dell and AMD
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Big Data Technologies - Introduction.pptx
Electronic commerce courselecture one. Pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
The AUB Centre for AI in Media Proposal.docx
MYSQL Presentation for SQL database connectivity
NewMind AI Monthly Chronicles - July 2025
Advanced methodologies resolving dimensionality complications for autism neur...
KodekX | Application Modernization Development
Reach Out and Touch Someone: Haptics and Empathic Computing
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Chapter 3 Spatial Domain Image Processing.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Machine learning based COVID-19 study performance prediction
Review of recent advances in non-invasive hemoglobin estimation
Encapsulation_ Review paper, used for researhc scholars
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Modernizing your data center with Dell and AMD
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Building Microservices with gRPC and NATS

  • 1. Building Microservices with gRPC and NATS Shiju Varghese Consulting Solutions Architect April 28, 2017
  • 2. About Me • Consulting Solutions Architect and Trainer • Focused on Golang, Microservices and Cloud-Native distributed systems architectures • Published Author: “Web Development with Go” and “Go Recipes” • Honoured with Microsoft MVP award seven times • Blog: https://medium.com/@shijuvar
  • 3. Agenda • Inter-Process communications in Microservices architecture • Building high performance APIs with gRPC and Protocol Buffers • Building Microservices with event-driven architectures using NATS
  • 5. Monolithic Architecture Catalog Management Customer Accounts Orders Management Payment Monolithic Database Monolithic E-Commerce App eCom Store Web Shipment
  • 6. Moving to Microservices Catalog Management Customer Accounts Orders Management Payment eCom Store Web Shipment Catalog DB Accounts DB Orders DB Payment DB Store DB Shipment DB
  • 7. Microservices • Software broken up into functional components • Componentization via Services in which each service is packaged as one unit of execution • Independent, autonomous process with no dependency on other Microservices • Autonomous services around Bounded Context • Decentralization of data management • Independently replaceable and upgradeable
  • 8. Challenges • A business transaction may span into multiple services • Decentralization of data management • Communications between Microservices without having any performance bottleneck
  • 9. Inter-Process Communications between Microservices • Communications over high performance APIs • Event-Driven architecture using messaging systems
  • 10. Design Considerations for Building APIs • Scaling APIs into millions (even billions) of APIs calls • Wire format; Serialisation and deserialisation of messages • Building streaming APIs • RESTful Vs RPC? • Text encoding Vs binary encoding?
  • 11. Why not REST • Uses HTTP/1.x; Separate TCP Connection per request • Text on the wire; Not performance efficient • Harder API evolution • Not Domain-Specific • Not strongly-typed • Lack of streaming capabilities
  • 13. What is gRPC • High performance, open-source universal RPC framework • A Cloud Native Computing Foundation(CNCF) project • Open source version of Google’s internal framework Stubby • Uses Protocol Buffers as the IDL • HTTP/2 for transport • Bi-Directional streaming • RPC is efficient, domain-specific and strongly-typed • Works across languages and platforms
  • 14. Protocol Buffers • Google's language-neutral, platform-neutral, extensible mechanism for serialising structured data • IDL - Describe once and generate interfaces for multiple languages • Structure of the Request and Response • Binary format for network transmission • Supports multiple languages
  • 15. Communication between gRPC Server and Client app
  • 16. Types of RPC Methods • Simple RPC • Server-side streaming RPC • Client-side streaming RPC • Bi-directional streaming RPC
  • 17. gRPC Workflow ProtoBuf Definitions protoc Compiler Go Ruby Java gRPC Server gRPC Client Define1 Compile2 Implement3Generate Code protoc --go_out=plugins=grpc
  • 18. DEMO
  • 19. grpc-gateway - gRPC to JSON Proxy Generator
  • 21. Inter-Process Communication Using an Event- Driven Architecture
  • 22. Event-Sourcing Aggregate ID Aggregate Type Event ID Event Type Event Data 301 Order 1001 OrderCreated … 301 Order 1002 OrderApproved … 301 Order 1003 OrderShipped … 301 Order 1004 OrderDelivered … Event Table
  • 23. • Open source, lightweight, high-performance cloud native messaging system • Highly performant, extremely light-weight; Capable of sending 11-12 million messages per second • Publish-Subscribe messaging system • Available in two interoperable modules: • NATS Server • NATS Streaming Server (with persistent messaging) Introducing NATS - Shiju Varghese's Blog
  • 25. Messaging Patterns • Publish-Subscribe • Queueing • Request-Replay
  • 26. Components of Messaging Architecture • Message: Messages are the unit of data exchange. A payload, which is used for exchanging the data between applications. • Subject: Subject specifies the destination of messages. • Producer: Producers send messages to the NATS server. • Consumer: Consumers receive messages from the NATS server. • Messaging Server: NATS Server distributes the messages from producers to consumers.
  • 28. DEMO
  • 29. Demo App - Workflow OrderService - gRPC Server gRPC client Subscriber OrderCreated Event Subscriber Subscriber Queue Group NATS publisher, which publishes events when new orders are created RPC call for creating a new order Example Source: https://github.com/shijuvar/gokit/tree/master/examples/grpc-nats
  • 30. Thank you Blog: medium.com/@shijuvar LinkedIn: linkedin.com/in/shijuvar Email: gophermonk@gmail.com