SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
NATS:
Control Flow for Distributed Systems
Focus
© 2015 Bridgevine. All Rights reserved. December 9, 2015 2
The Transaction Engine
© 2015 Bridgevine. All Rights reserved. December 9, 2015 3
© 2015 Bridgevine. All Rights reserved. December 9, 2015 4
Engine speak
We refer to the outer circles as components, you’ll see
that term later...
Recently started referring to the center as the “queue”. It’s a
combination of NATS and Elasticsearch. More on this later too...
Elasticsearch is also the store used by History Recorder and the
Cache components.
Since everything communicates by messages, we wanted to use the
same message struct format but retain flexibility for the different
types of information the system will pass...
Find your center
© 2015 Bridgevine. All Rights reserved. December 9, 2015 5
© 2015 Bridgevine. All Rights reserved. December 9, 2015 6
The Msg Struct
We share by communicating via a single Msg struct.
We’ve evolved to this format, but expect more changes.
Could end up going with a “net/context” approach, but must retain compiler
advantages.
interface{} and []byte type overuse is disadvantageous.
© 2015 Bridgevine. All Rights reserved. December 9, 2015 7
Pub/Sub Queue - NATS
http://nats.io/
Love the performance focus. Major reason for selection.
Love the simplicity.
Using standard messaging for config updates
Want all instances of an API to get the update
Message Queueing
Only want one instance of component to process.
Employed in request/reply processing.
Avoids duplicate logging.
© 2015 Bridgevine. All Rights reserved. December 9, 2015 8
Central Storage Engine - Elasticsearch
https://www.elastic.co/products/elasticsearch
Initially selected for components providing search
functionality.
Flexibility allows for a variety of use cases.
Used as the key/value store companion to NATS for storing
message payloads.
Want to keep the NATS messages small.
NATS Msg
© 2015 Bridgevine. All Rights reserved. December 9, 2015 9
© 2015 Bridgevine. All Rights reserved. December 9, 2015 10
NATS Msg struct
We will be referring to NATS Msg fields of Subject and Reply in the next few slides…
Here’s what the struct looks like.
Our Msg struct ends up being encrypted and stored in the Data field in the NATS Msg.
We don’t really deal directly with the NATS Msg too much. Client API methods are there
to handle the construction of this struct, but you can do it yourself too.
https://github.com/nats-io/nats/blob/master/nats.go#L1323
Request/Reply
© 2015 Bridgevine. All Rights reserved. December 9, 2015 11
© 2015 Bridgevine. All Rights reserved. December 9, 2015 12
Request/Reply Steps
Origin first subscribes to the reply subject it’s about to ask for. Important
to do this first.
Origin publishes message with a reply subject. The reply subject should
be a unique string.
https://github.com/nats-io/nats/blob/master/nats.go#L1357
Subscriber replies to origin by using origin’s msg.Reply as msg.Subject
in the message it publishes.
Origin will receive the message. That’s it.
Go client simplifies this with Request method.
https://github.com/nats-io/nats/blob/master/nats.go#L1337
Forwarding
© 2015 Bridgevine. All Rights reserved. December 9, 2015 13
© 2015 Bridgevine. All Rights reserved. December 9, 2015 14
Origin Step 1 Step 2
Forwarding Steps
Origin subscribes to reply subject. Important to do this first.
Origin then publishes Request/Reply message.
Step 1 Receives message and produces result.
Step 1 Publishes message with new subject and uses same reply as
the message from Origin.
Step 2 Receives message, processes and publishes using reply from
Step 1’s message as subject.
Origin will receive the message from Step 2.
Subscribe/QueueSubscribe
© 2015 Bridgevine. All Rights reserved. December 9, 2015 15
© 2015 Bridgevine. All Rights reserved. December 9, 2015 16
Subscribe when all subscribers should receive the message.
https://github.com/nats-io/nats/blob/master/nats.go#L1399
Configuration updates drive this use case.
QueueSubscribe when only one of the subscribers should receive the
message.
https://github.com/nats-io/nats/blob/master/nats.go#L1412
So far...everything else/
Limit processing to one instance of a component in a load
balanced environment.
Combo Time!
© 2015 Bridgevine. All Rights reserved. December 9, 2015 17
© 2015 Bridgevine. All Rights reserved. December 9, 2015 18
Combos are good!
Publish + Subscribe
Send configuration update to all instances of a component.
Request/Reply + QueueSubscribe
Can’t control subscribing from publishing side.
Use QueueSubscribe to have only one instance of a component
process the request.
Request/Reply + QueueSubscribe + Forwarding
Start with initial processing component.
Forward message to continue processing
Select components like “Provider Interfaces” always forward.
Select components like “Rules Engine” always reply.
Some depend on subject.
Timeouts
© 2015 Bridgevine. All Rights reserved. December 9, 2015 19
© 2015 Bridgevine. All Rights reserved. December 9, 2015 20
“NATS is a fire-and-forget messaging system. If you need higher
levels of service, you build it into the client”
- http://nats.io/documentation/concepts/nats-pub-sub/
Multiple levels of timeouts to provide higher level of service.
Originating request timeout - overall time we will wait before responding
to requestor.
During requests involving multiple responses - time to return regardless
of the response percentage. Must be less than request timeout.
Processing timeouts - ensure we kill long running processes. These
timeouts will be longer than transaction timeouts. Allows us to still
gather data without hastily throwing away information.
We may need to dynamically adjust to external conditions. If a provider
is experiencing latency issues, it may make more sense to wait a bit
longer than lose orders.
Queue
© 2015 Bridgevine. All Rights reserved. December 9, 2015 21
© 2015 Bridgevine. All Rights reserved. December 9, 2015 22
The rather obvious (now) ...
Wanted to do logging via NATS and started with a dedicated logging
package. Quickly realized this could/should be simplified.
All components use NATS for communication already and wanted
logging done via NATS. Was it as simple as adding a Log method to
our NATS pub/sub code?
Wanted to log the interaction with the central data store.
Store, Load, Delete
Wanted to keep messages small.
Need to provide consumers with a stable API.
Would like to tune cache use without major refactoring efforts.
The birth of Queue
Interfaces are good. Queue should define the interfaces it would need
implementations for to provide Messaging and Caching functionality.
Instance of Queue could be created with references to concrete types
satisfying the interface.
Concerns that were once combined got their own identity.
The Msg struct was now in its own repo and also defined Msg Handler
type. Things are making sense.
The NATS and Elasticsearch repos provided simple wrappers to client
libs. Don’t want to expose Clients to components.
© 2015 Bridgevine. All Rights reserved. December 9, 2015 23
© 2015 Bridgevine. All Rights reserved. December 9, 2015 24
Queue interface definitions
© 2015 Bridgevine. All Rights reserved. December 9, 2015 25
Queue API
Request, Publish, Subscribe, Load, Store, Delete, Log
Don’t force the consumers of the API to do what must be done:
Request, Publish
Store payload.
Set CacheKey on Msg.
Request, Subscribe, QueueSubscribe
If CacheKey present, retrieves payload from Cache
Add Payload to CacheData on Msg.
Load, Store, Delete
Log these events
Log
Use runtime.FuncForPC to get caller information
Close down
© 2015 Bridgevine. All Rights reserved. December 9, 2015 26
© 2015 Bridgevine. All Rights reserved. December 9, 2015 27
Would like to ultimately open source Queue and other potentially useful
packages. Have already started contributing back with some open
source projects:
https://github.com/Bridgevine/soap
https://github.com/Bridgevine/http
https://github.com/Bridgevine/xml
Help us build this and more?
More info on what we are building...
Bridgevine Company Website
Open Positions
Thank you! If you have questions:
andy.stone@bridgevine.com or @stonean

Contenu connexe

Tendances

Kubernetes Ingress to Service Mesh (and beyond!)
Kubernetes Ingress to Service Mesh (and beyond!)Kubernetes Ingress to Service Mesh (and beyond!)
Kubernetes Ingress to Service Mesh (and beyond!)
Christian Posta
 

Tendances (19)

NATS Connect Live | NATS as a Service Mesh
NATS Connect Live | NATS as a Service MeshNATS Connect Live | NATS as a Service Mesh
NATS Connect Live | NATS as a Service Mesh
 
NATS for Modern Messaging and Microservices
NATS for Modern Messaging and MicroservicesNATS for Modern Messaging and Microservices
NATS for Modern Messaging and Microservices
 
API World: The service-mesh landscape
API World: The service-mesh landscapeAPI World: The service-mesh landscape
API World: The service-mesh landscape
 
How Greta uses NATS to revolutionize data distribution on the Internet
How Greta uses NATS to revolutionize data distribution on the InternetHow Greta uses NATS to revolutionize data distribution on the Internet
How Greta uses NATS to revolutionize data distribution on the Internet
 
MRA AMA Part 6: Service Mesh Models
MRA AMA Part 6: Service Mesh ModelsMRA AMA Part 6: Service Mesh Models
MRA AMA Part 6: Service Mesh Models
 
Microservice design patterns
Microservice design patternsMicroservice design patterns
Microservice design patterns
 
Microservices
MicroservicesMicroservices
Microservices
 
Understanding the New Enterprise Multi-Cloud Backbone for DevOps Engineers
Understanding the New Enterprise Multi-Cloud Backbone for DevOps EngineersUnderstanding the New Enterprise Multi-Cloud Backbone for DevOps Engineers
Understanding the New Enterprise Multi-Cloud Backbone for DevOps Engineers
 
Kubernetes Ingress to Service Mesh (and beyond!)
Kubernetes Ingress to Service Mesh (and beyond!)Kubernetes Ingress to Service Mesh (and beyond!)
Kubernetes Ingress to Service Mesh (and beyond!)
 
Keynote - Oleg Barenboim - ManageIQ Design Summit 2016
Keynote - Oleg Barenboim - ManageIQ Design Summit 2016Keynote - Oleg Barenboim - ManageIQ Design Summit 2016
Keynote - Oleg Barenboim - ManageIQ Design Summit 2016
 
NGINX MRA Fabric Model Release and Ask Me Anything Part 4
NGINX MRA Fabric Model Release and Ask Me Anything Part 4NGINX MRA Fabric Model Release and Ask Me Anything Part 4
NGINX MRA Fabric Model Release and Ask Me Anything Part 4
 
Orchestration Patterns for Microservices with Messaging by RabbitMQ
Orchestration Patterns for Microservices with Messaging by RabbitMQOrchestration Patterns for Microservices with Messaging by RabbitMQ
Orchestration Patterns for Microservices with Messaging by RabbitMQ
 
The Truth About the Service Mesh Data Plane
The Truth About the Service Mesh Data PlaneThe Truth About the Service Mesh Data Plane
The Truth About the Service Mesh Data Plane
 
MANTL Data Platform, Microservices and BigData Services
MANTL Data Platform, Microservices and BigData ServicesMANTL Data Platform, Microservices and BigData Services
MANTL Data Platform, Microservices and BigData Services
 
Multicluster Kubernetes and Service Mesh Patterns
Multicluster Kubernetes and Service Mesh PatternsMulticluster Kubernetes and Service Mesh Patterns
Multicluster Kubernetes and Service Mesh Patterns
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices Architecture
 
O'Reilly 2017: "Introduction to Service Meshes"
O'Reilly 2017: "Introduction to Service Meshes"O'Reilly 2017: "Introduction to Service Meshes"
O'Reilly 2017: "Introduction to Service Meshes"
 
Service mesh
Service meshService mesh
Service mesh
 
Microservices With Istio Service Mesh
Microservices With Istio Service MeshMicroservices With Istio Service Mesh
Microservices With Istio Service Mesh
 

Similaire à NATS: Control Flow for Distributed Systems

MuleSoft Meetup Singapore #8 March 2021
MuleSoft Meetup Singapore #8 March 2021MuleSoft Meetup Singapore #8 March 2021
MuleSoft Meetup Singapore #8 March 2021
Julian Douch
 
DAY1- DAY2Netweaver gateway
DAY1- DAY2Netweaver gatewayDAY1- DAY2Netweaver gateway
DAY1- DAY2Netweaver gateway
Gaurav Ahluwalia
 

Similaire à NATS: Control Flow for Distributed Systems (20)

MuleSoft Meetup Singapore #8 March 2021
MuleSoft Meetup Singapore #8 March 2021MuleSoft Meetup Singapore #8 March 2021
MuleSoft Meetup Singapore #8 March 2021
 
MuleSoft Surat Virtual Meetup#18 - Persistent Queue, Object Store and Persist...
MuleSoft Surat Virtual Meetup#18 - Persistent Queue, Object Store and Persist...MuleSoft Surat Virtual Meetup#18 - Persistent Queue, Object Store and Persist...
MuleSoft Surat Virtual Meetup#18 - Persistent Queue, Object Store and Persist...
 
Sf bay area Kubernetes meetup dec8 2016 - deployment models
Sf bay area Kubernetes meetup dec8 2016 - deployment modelsSf bay area Kubernetes meetup dec8 2016 - deployment models
Sf bay area Kubernetes meetup dec8 2016 - deployment models
 
Cloud by dev
Cloud by devCloud by dev
Cloud by dev
 
RTBkit Meetup - Developer Spotlight, Behind the Scenes of RTBkit and Intro to...
RTBkit Meetup - Developer Spotlight, Behind the Scenes of RTBkit and Intro to...RTBkit Meetup - Developer Spotlight, Behind the Scenes of RTBkit and Intro to...
RTBkit Meetup - Developer Spotlight, Behind the Scenes of RTBkit and Intro to...
 
Who's Who in Container Land
Who's Who in Container LandWho's Who in Container Land
Who's Who in Container Land
 
Azure + DataStax Enterprise (DSE) Powers Office365 Per User Store
Azure + DataStax Enterprise (DSE) Powers Office365 Per User StoreAzure + DataStax Enterprise (DSE) Powers Office365 Per User Store
Azure + DataStax Enterprise (DSE) Powers Office365 Per User Store
 
DAY1- DAY2Netweaver gateway
DAY1- DAY2Netweaver gatewayDAY1- DAY2Netweaver gateway
DAY1- DAY2Netweaver gateway
 
stupid-simple-kubernetes-final.pdf
stupid-simple-kubernetes-final.pdfstupid-simple-kubernetes-final.pdf
stupid-simple-kubernetes-final.pdf
 
Introduction to MANTL Data Platform
Introduction to MANTL Data PlatformIntroduction to MANTL Data Platform
Introduction to MANTL Data Platform
 
Deploy prometheus on kubernetes
Deploy prometheus on kubernetesDeploy prometheus on kubernetes
Deploy prometheus on kubernetes
 
Containerized Storage for Containers
Containerized Storage for ContainersContainerized Storage for Containers
Containerized Storage for Containers
 
Containerized Storage for Containers
Containerized Storage for ContainersContainerized Storage for Containers
Containerized Storage for Containers
 
Multi-Tenancy
Multi-TenancyMulti-Tenancy
Multi-Tenancy
 
Understanding Platform as a Service
Understanding Platform as a ServiceUnderstanding Platform as a Service
Understanding Platform as a Service
 
Seven Criteria for Building an AWS Global Transit Network
Seven Criteria for Building an AWS Global Transit NetworkSeven Criteria for Building an AWS Global Transit Network
Seven Criteria for Building an AWS Global Transit Network
 
See Inside the Middleware Black Box
See Inside the Middleware Black Box See Inside the Middleware Black Box
See Inside the Middleware Black Box
 
modern-guide-to-container-monitoring-and-orchestration.pdf
modern-guide-to-container-monitoring-and-orchestration.pdfmodern-guide-to-container-monitoring-and-orchestration.pdf
modern-guide-to-container-monitoring-and-orchestration.pdf
 
Ymens - Bouncing off clouds - Rapid Development for Cloud Ready Applications...
Ymens - Bouncing off clouds - Rapid Development for Cloud Ready Applications...Ymens - Bouncing off clouds - Rapid Development for Cloud Ready Applications...
Ymens - Bouncing off clouds - Rapid Development for Cloud Ready Applications...
 
RTI Connext 5.2.0
RTI Connext 5.2.0RTI Connext 5.2.0
RTI Connext 5.2.0
 

Plus de Apcera

Plus de Apcera (20)

Gopher fest 2017: Adding Context To NATS
Gopher fest 2017: Adding Context To NATSGopher fest 2017: Adding Context To NATS
Gopher fest 2017: Adding Context To NATS
 
How Clarifai uses NATS and Kubernetes for Machine Learning
How Clarifai uses NATS and Kubernetes for Machine LearningHow Clarifai uses NATS and Kubernetes for Machine Learning
How Clarifai uses NATS and Kubernetes for Machine Learning
 
Modernizing IT in the Platform Era
Modernizing IT in the Platform EraModernizing IT in the Platform Era
Modernizing IT in the Platform Era
 
Debugging Network Issues
Debugging Network IssuesDebugging Network Issues
Debugging Network Issues
 
IT Modernization Doesn’t Mean You Leave Your Legacy Apps Behind
IT Modernization Doesn’t Mean You Leave Your Legacy Apps BehindIT Modernization Doesn’t Mean You Leave Your Legacy Apps Behind
IT Modernization Doesn’t Mean You Leave Your Legacy Apps Behind
 
Simple and Scalable Microservices: Using NATS with Docker Compose and Swarm
Simple and Scalable Microservices: Using NATS with Docker Compose and SwarmSimple and Scalable Microservices: Using NATS with Docker Compose and Swarm
Simple and Scalable Microservices: Using NATS with Docker Compose and Swarm
 
The Zen of High Performance Messaging with NATS
The Zen of High Performance Messaging with NATSThe Zen of High Performance Messaging with NATS
The Zen of High Performance Messaging with NATS
 
Implementing Microservices with NATS
Implementing Microservices with NATSImplementing Microservices with NATS
Implementing Microservices with NATS
 
Actor Patterns and NATS - Boulder Meetup
Actor Patterns and NATS - Boulder MeetupActor Patterns and NATS - Boulder Meetup
Actor Patterns and NATS - Boulder Meetup
 
Simple Solutions for Complex Problems - Boulder Meetup
Simple Solutions for Complex Problems - Boulder MeetupSimple Solutions for Complex Problems - Boulder Meetup
Simple Solutions for Complex Problems - Boulder Meetup
 
Patterns for Asynchronous Microservices with NATS
Patterns for Asynchronous Microservices with NATSPatterns for Asynchronous Microservices with NATS
Patterns for Asynchronous Microservices with NATS
 
NATS vs HTTP
NATS vs HTTPNATS vs HTTP
NATS vs HTTP
 
Micro on NATS - Microservices with Messaging
Micro on NATS - Microservices with MessagingMicro on NATS - Microservices with Messaging
Micro on NATS - Microservices with Messaging
 
Simple Solutions for Complex Problems
Simple Solutions for Complex Problems Simple Solutions for Complex Problems
Simple Solutions for Complex Problems
 
KURMA - A Containerized Container Platform - KubeCon 2016
KURMA - A Containerized Container Platform - KubeCon 2016KURMA - A Containerized Container Platform - KubeCon 2016
KURMA - A Containerized Container Platform - KubeCon 2016
 
Kubernetes, The Day After
Kubernetes, The Day AfterKubernetes, The Day After
Kubernetes, The Day After
 
Policy-based Cloud Storage: Persisting Data in a Multi-Site, Multi-Cloud World
Policy-based Cloud Storage: Persisting Data in a Multi-Site, Multi-Cloud WorldPolicy-based Cloud Storage: Persisting Data in a Multi-Site, Multi-Cloud World
Policy-based Cloud Storage: Persisting Data in a Multi-Site, Multi-Cloud World
 
Integration Patterns for Microservices Architectures
Integration Patterns for Microservices ArchitecturesIntegration Patterns for Microservices Architectures
Integration Patterns for Microservices Architectures
 
Microservices: Notes From The Field
Microservices: Notes From The FieldMicroservices: Notes From The Field
Microservices: Notes From The Field
 
Docker + App Container = ocp
Docker + App Container = ocpDocker + App Container = ocp
Docker + App Container = ocp
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

NATS: Control Flow for Distributed Systems

  • 1. NATS: Control Flow for Distributed Systems
  • 2. Focus © 2015 Bridgevine. All Rights reserved. December 9, 2015 2
  • 3. The Transaction Engine © 2015 Bridgevine. All Rights reserved. December 9, 2015 3
  • 4. © 2015 Bridgevine. All Rights reserved. December 9, 2015 4 Engine speak We refer to the outer circles as components, you’ll see that term later... Recently started referring to the center as the “queue”. It’s a combination of NATS and Elasticsearch. More on this later too... Elasticsearch is also the store used by History Recorder and the Cache components. Since everything communicates by messages, we wanted to use the same message struct format but retain flexibility for the different types of information the system will pass...
  • 5. Find your center © 2015 Bridgevine. All Rights reserved. December 9, 2015 5
  • 6. © 2015 Bridgevine. All Rights reserved. December 9, 2015 6 The Msg Struct We share by communicating via a single Msg struct. We’ve evolved to this format, but expect more changes. Could end up going with a “net/context” approach, but must retain compiler advantages. interface{} and []byte type overuse is disadvantageous.
  • 7. © 2015 Bridgevine. All Rights reserved. December 9, 2015 7 Pub/Sub Queue - NATS http://nats.io/ Love the performance focus. Major reason for selection. Love the simplicity. Using standard messaging for config updates Want all instances of an API to get the update Message Queueing Only want one instance of component to process. Employed in request/reply processing. Avoids duplicate logging.
  • 8. © 2015 Bridgevine. All Rights reserved. December 9, 2015 8 Central Storage Engine - Elasticsearch https://www.elastic.co/products/elasticsearch Initially selected for components providing search functionality. Flexibility allows for a variety of use cases. Used as the key/value store companion to NATS for storing message payloads. Want to keep the NATS messages small.
  • 9. NATS Msg © 2015 Bridgevine. All Rights reserved. December 9, 2015 9
  • 10. © 2015 Bridgevine. All Rights reserved. December 9, 2015 10 NATS Msg struct We will be referring to NATS Msg fields of Subject and Reply in the next few slides… Here’s what the struct looks like. Our Msg struct ends up being encrypted and stored in the Data field in the NATS Msg. We don’t really deal directly with the NATS Msg too much. Client API methods are there to handle the construction of this struct, but you can do it yourself too. https://github.com/nats-io/nats/blob/master/nats.go#L1323
  • 11. Request/Reply © 2015 Bridgevine. All Rights reserved. December 9, 2015 11
  • 12. © 2015 Bridgevine. All Rights reserved. December 9, 2015 12 Request/Reply Steps Origin first subscribes to the reply subject it’s about to ask for. Important to do this first. Origin publishes message with a reply subject. The reply subject should be a unique string. https://github.com/nats-io/nats/blob/master/nats.go#L1357 Subscriber replies to origin by using origin’s msg.Reply as msg.Subject in the message it publishes. Origin will receive the message. That’s it. Go client simplifies this with Request method. https://github.com/nats-io/nats/blob/master/nats.go#L1337
  • 13. Forwarding © 2015 Bridgevine. All Rights reserved. December 9, 2015 13
  • 14. © 2015 Bridgevine. All Rights reserved. December 9, 2015 14 Origin Step 1 Step 2 Forwarding Steps Origin subscribes to reply subject. Important to do this first. Origin then publishes Request/Reply message. Step 1 Receives message and produces result. Step 1 Publishes message with new subject and uses same reply as the message from Origin. Step 2 Receives message, processes and publishes using reply from Step 1’s message as subject. Origin will receive the message from Step 2.
  • 15. Subscribe/QueueSubscribe © 2015 Bridgevine. All Rights reserved. December 9, 2015 15
  • 16. © 2015 Bridgevine. All Rights reserved. December 9, 2015 16 Subscribe when all subscribers should receive the message. https://github.com/nats-io/nats/blob/master/nats.go#L1399 Configuration updates drive this use case. QueueSubscribe when only one of the subscribers should receive the message. https://github.com/nats-io/nats/blob/master/nats.go#L1412 So far...everything else/ Limit processing to one instance of a component in a load balanced environment.
  • 17. Combo Time! © 2015 Bridgevine. All Rights reserved. December 9, 2015 17
  • 18. © 2015 Bridgevine. All Rights reserved. December 9, 2015 18 Combos are good! Publish + Subscribe Send configuration update to all instances of a component. Request/Reply + QueueSubscribe Can’t control subscribing from publishing side. Use QueueSubscribe to have only one instance of a component process the request. Request/Reply + QueueSubscribe + Forwarding Start with initial processing component. Forward message to continue processing Select components like “Provider Interfaces” always forward. Select components like “Rules Engine” always reply. Some depend on subject.
  • 19. Timeouts © 2015 Bridgevine. All Rights reserved. December 9, 2015 19
  • 20. © 2015 Bridgevine. All Rights reserved. December 9, 2015 20 “NATS is a fire-and-forget messaging system. If you need higher levels of service, you build it into the client” - http://nats.io/documentation/concepts/nats-pub-sub/ Multiple levels of timeouts to provide higher level of service. Originating request timeout - overall time we will wait before responding to requestor. During requests involving multiple responses - time to return regardless of the response percentage. Must be less than request timeout. Processing timeouts - ensure we kill long running processes. These timeouts will be longer than transaction timeouts. Allows us to still gather data without hastily throwing away information. We may need to dynamically adjust to external conditions. If a provider is experiencing latency issues, it may make more sense to wait a bit longer than lose orders.
  • 21. Queue © 2015 Bridgevine. All Rights reserved. December 9, 2015 21
  • 22. © 2015 Bridgevine. All Rights reserved. December 9, 2015 22 The rather obvious (now) ... Wanted to do logging via NATS and started with a dedicated logging package. Quickly realized this could/should be simplified. All components use NATS for communication already and wanted logging done via NATS. Was it as simple as adding a Log method to our NATS pub/sub code? Wanted to log the interaction with the central data store. Store, Load, Delete Wanted to keep messages small. Need to provide consumers with a stable API. Would like to tune cache use without major refactoring efforts.
  • 23. The birth of Queue Interfaces are good. Queue should define the interfaces it would need implementations for to provide Messaging and Caching functionality. Instance of Queue could be created with references to concrete types satisfying the interface. Concerns that were once combined got their own identity. The Msg struct was now in its own repo and also defined Msg Handler type. Things are making sense. The NATS and Elasticsearch repos provided simple wrappers to client libs. Don’t want to expose Clients to components. © 2015 Bridgevine. All Rights reserved. December 9, 2015 23
  • 24. © 2015 Bridgevine. All Rights reserved. December 9, 2015 24 Queue interface definitions
  • 25. © 2015 Bridgevine. All Rights reserved. December 9, 2015 25 Queue API Request, Publish, Subscribe, Load, Store, Delete, Log Don’t force the consumers of the API to do what must be done: Request, Publish Store payload. Set CacheKey on Msg. Request, Subscribe, QueueSubscribe If CacheKey present, retrieves payload from Cache Add Payload to CacheData on Msg. Load, Store, Delete Log these events Log Use runtime.FuncForPC to get caller information
  • 26. Close down © 2015 Bridgevine. All Rights reserved. December 9, 2015 26
  • 27. © 2015 Bridgevine. All Rights reserved. December 9, 2015 27 Would like to ultimately open source Queue and other potentially useful packages. Have already started contributing back with some open source projects: https://github.com/Bridgevine/soap https://github.com/Bridgevine/http https://github.com/Bridgevine/xml Help us build this and more? More info on what we are building... Bridgevine Company Website Open Positions Thank you! If you have questions: andy.stone@bridgevine.com or @stonean