SlideShare a Scribd company logo
1 of 19
Download to read offline
Integrated Computer Solutions Inc. www.ics.com
Communication Patterns
for Distributed Services
Matteo Brichese
June 25, 2020
Integrated Computer Solutions Inc. www.ics.com
Agenda
Introduction
1. The problem with communication
2. What distributed services mean to us?
Communication Patterns
1. 0MQ Quick Intro
2. Reliability, what does it mean to be reliable?
3. The basics: Request-Reply, Pub-Sub
4. RRR aka The Pirate Patterns
5. A P2P protocol
2
Integrated Computer Solutions Inc. www.ics.com
The Problem with Communication
● It’s hard
● It’s messy
● It’s centralized
3
Integrated Computer Solutions Inc. www.ics.com
What Does Distributed Service Mean to Us?
Wikipedia:
A distributed system is a system whose components are located on
different networked computers, which communicate and coordinate their
actions by passing messages to one another. The components interact with
one another in order to achieve a common goal [...]
A computer program that runs within a distributed system is called a
distributed program.
Is a program that runs between multiple processes a distributed system?
What if the processes are within the same machine?
4
Integrated Computer Solutions Inc. www.ics.com
0MQ Quick Intro
● ZMQ looks like an embeddable networking library, but acts like a concurrency framework.
● ZMQ does NOT provide any pre-made solutions
● ZMQ provides basic sockets to build your own communication infrastructure
The basics:
● REQ-REP, which connects a set of clients to a set of services.
● PUB-SUB, which connects a set of publishers to a set of subscribers.
● PUSH-PULL, which connects nodes in a fan-out/fan-in pattern that can have multiple steps and loops.
● PAIR, which connects two sockets exclusively. This is a pattern for connecting two threads in a process.
5
Integrated Computer Solutions Inc. www.ics.com
0MQ Quick Intro
During this webinar we will use:
● REQ-REP sockets
● PUB-SUB sockets
● DEALER-ROUTER sockets
A DEALER acts like an asynchronous REQ
A ROUTER acts like an asynchronous REP
6
Integrated Computer Solutions Inc. www.ics.com
Defining Reliability
What does it mean to build a reliable communication pattern
Common Failures:
1. Application code
2. Proxy code
3. Overflow
4. Network failure
5. Hardware failure
6. “Exotic” network failures
7. Connection/Datacenter failures
Protecting from 1 to 5 is our goal
7
Integrated Computer Solutions Inc. www.ics.com
Request-Reply
Request-Reply, a classic client-server
solution
● A REQ socket connects to a REP socket
● REQ sends a request
● REP replies to the request
● Everything works in lockstep, if REP hangs, REQ
hangs.
Pro: Easy to implement, easy to understand
Cons: Easy to break, not really useful for a
distributed scenario
8
Integrated Computer Solutions Inc. www.ics.com
Publisher-Subscriber
9
Publisher-Subscriber
● A SUB socket connects to a PUB socket
● PUB publishes
● SUB receives
Pro: Easy to implement, easy to understand,
perfect to deliver the same content to multiple
services
Cons: late-joiner problem
Integrated Computer Solutions Inc. www.ics.com
Reliable Request Reply patterns
How to improve on the Client-Server pattern?
1. Add a timeout on the client receive function
2. Rety the communication or abandon if no reply is received within the allotted
time
This is what’s known as Lazy Pirate Pattern
Note: Reliable Request Reply aka RRR - a pirate inside joke :)
10
Integrated Computer Solutions Inc. www.ics.com
Lazy Pirate Pattern
11
Request-Reply with retry
● A REQ socket connects to a REP socket
● REQ sends a request
● REP replies to the request
● If REP fails, REQ retries after a timeout
● After N retries REQ abandons
Pro: Easy to implement, easy to understand
Cons: REP is still a single point of failure
Integrated Computer Solutions Inc. www.ics.com
Simple Pirate Pattern
12
Request-Reply with retry and load
distribution
● A proxy is added to hold multiple
servers/workers
● Proxy distributes client load to an available
server
Pro: Added a failover system to Lazy Pirate
Cons: Proxy is now the single point of failure,
proxy doesn’t know of hanging/dead workers
Integrated Computer Solutions Inc. www.ics.com
Paranoid Pirate Pattern
13
Request-Reply with retry, load distribution
and worker management
● A heartbeat is added to the proxy to monitor
worker status
Pro: improved worker management
Cons: same as Simple Pirate
Integrated Computer Solutions Inc. www.ics.com
A Peer to Peer Protocol: Zyre
14
Integrated Computer Solutions Inc. www.ics.com
How Do We Find Other Nodes?
15
Pre-Emptive discovery:
● Use ping
● No need for node cooperation
● Need root privileges
● One node per IP address
Cooperative discovery:
● Use UDP
● Needs node cooperation
● No root privileges required
● Multiple node per IP address using
UUIDs
Integrated Computer Solutions Inc. www.ics.com
How Do We Know if a Node is Still Up?
16
UDP Heartbeat
Under high loads UDP may never reach the target, how do we ensure that
we don’t remove a node that is still up?
We can use a TCP Heartbeat once multiple UDP fails, if the TCP fails too,
the node is unreachable
Integrated Computer Solutions Inc. www.ics.com
How Do I Connect to All Other Nodes?
17
● A combination of PUB-SUB
● A combination of REQ-REP or DEALER-ROUTER
Zyre uses a combinations of one receiving ROUTER socket and multiple
sending DEALER sockets in what was called, the Harmony pattern
Integrated Computer Solutions Inc. www.ics.com
The Harmony Pattern
18
The high-level overview
● One ROUTER socket that we bind to a ephemeral port, which we
broadcast in our beacons.
● One DEALER socket per peer that we connect to the peer's ROUTER
socket.
● Reading from our ROUTER socket.
● Writing to the peer's DEALER socket.
Integrated Computer Solutions Inc. www.ics.com
Thank you!
19
All examples can be found at:
https://github.com/bricke/0mq-patterns
Any questions?

More Related Content

More from ICS

Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up ICS
 
Cybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfCybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfICS
 
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesMDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesICS
 
How to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionHow to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionICS
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsICS
 
IoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureIoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureICS
 
Basic Cmake for Qt Users
Basic Cmake for Qt UsersBasic Cmake for Qt Users
Basic Cmake for Qt UsersICS
 
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...ICS
 
Qt Installer Framework
Qt Installer FrameworkQt Installer Framework
Qt Installer FrameworkICS
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsICS
 
Overcome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyOvercome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyICS
 
User Experience Design for IoT
User Experience Design for IoTUser Experience Design for IoT
User Experience Design for IoTICS
 
Software Bill of Materials - Accelerating Your Secure Embedded Development.pdf
Software Bill of Materials - Accelerating Your Secure Embedded Development.pdfSoftware Bill of Materials - Accelerating Your Secure Embedded Development.pdf
Software Bill of Materials - Accelerating Your Secure Embedded Development.pdfICS
 
5 Key Considerations at the Start of SaMD Development
5 Key Considerations at the Start of SaMD Development5 Key Considerations at the Start of SaMD Development
5 Key Considerations at the Start of SaMD DevelopmentICS
 
An In-Depth Look Into Microcontrollers
An In-Depth Look Into MicrocontrollersAn In-Depth Look Into Microcontrollers
An In-Depth Look Into MicrocontrollersICS
 
Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6ICS
 
Leveraging Open Standards to Build Highly Extensible Autonomous Systems
Leveraging Open Standards to Build Highly Extensible Autonomous SystemsLeveraging Open Standards to Build Highly Extensible Autonomous Systems
Leveraging Open Standards to Build Highly Extensible Autonomous SystemsICS
 
Creating Advanced GUIs for Low-power MCUs with Qt
Creating Advanced GUIs for Low-power MCUs with QtCreating Advanced GUIs for Low-power MCUs with Qt
Creating Advanced GUIs for Low-power MCUs with QtICS
 
Safeguard Your Medical Devices from Cyber Threats
Safeguard Your Medical Devices from Cyber ThreatsSafeguard Your Medical Devices from Cyber Threats
Safeguard Your Medical Devices from Cyber ThreatsICS
 
Improving User Experience with Ubiquitous QuickBoot
 Improving User Experience with Ubiquitous QuickBoot Improving User Experience with Ubiquitous QuickBoot
Improving User Experience with Ubiquitous QuickBootICS
 

More from ICS (20)

Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up Secure Your Medical Devices From the Ground Up
Secure Your Medical Devices From the Ground Up
 
Cybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdfCybersecurity and Software Updates in Medical Devices.pdf
Cybersecurity and Software Updates in Medical Devices.pdf
 
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical DevicesMDG Panel - Creating Expert Level GUIs for Complex Medical Devices
MDG Panel - Creating Expert Level GUIs for Complex Medical Devices
 
How to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management SolutionHow to Craft a Winning IOT Device Management Solution
How to Craft a Winning IOT Device Management Solution
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory Teams
 
IoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with AzureIoT Device Fleet Management: Create a Robust Solution with Azure
IoT Device Fleet Management: Create a Robust Solution with Azure
 
Basic Cmake for Qt Users
Basic Cmake for Qt UsersBasic Cmake for Qt Users
Basic Cmake for Qt Users
 
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
Software Update Mechanisms: Selecting the Best Solutin for Your Embedded Linu...
 
Qt Installer Framework
Qt Installer FrameworkQt Installer Framework
Qt Installer Framework
 
Bridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory TeamsBridging the Gap Between Development and Regulatory Teams
Bridging the Gap Between Development and Regulatory Teams
 
Overcome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case StudyOvercome Hardware And Software Challenges - Medical Device Case Study
Overcome Hardware And Software Challenges - Medical Device Case Study
 
User Experience Design for IoT
User Experience Design for IoTUser Experience Design for IoT
User Experience Design for IoT
 
Software Bill of Materials - Accelerating Your Secure Embedded Development.pdf
Software Bill of Materials - Accelerating Your Secure Embedded Development.pdfSoftware Bill of Materials - Accelerating Your Secure Embedded Development.pdf
Software Bill of Materials - Accelerating Your Secure Embedded Development.pdf
 
5 Key Considerations at the Start of SaMD Development
5 Key Considerations at the Start of SaMD Development5 Key Considerations at the Start of SaMD Development
5 Key Considerations at the Start of SaMD Development
 
An In-Depth Look Into Microcontrollers
An In-Depth Look Into MicrocontrollersAn In-Depth Look Into Microcontrollers
An In-Depth Look Into Microcontrollers
 
Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6Introduction to the Qt State Machine Framework using Qt 6
Introduction to the Qt State Machine Framework using Qt 6
 
Leveraging Open Standards to Build Highly Extensible Autonomous Systems
Leveraging Open Standards to Build Highly Extensible Autonomous SystemsLeveraging Open Standards to Build Highly Extensible Autonomous Systems
Leveraging Open Standards to Build Highly Extensible Autonomous Systems
 
Creating Advanced GUIs for Low-power MCUs with Qt
Creating Advanced GUIs for Low-power MCUs with QtCreating Advanced GUIs for Low-power MCUs with Qt
Creating Advanced GUIs for Low-power MCUs with Qt
 
Safeguard Your Medical Devices from Cyber Threats
Safeguard Your Medical Devices from Cyber ThreatsSafeguard Your Medical Devices from Cyber Threats
Safeguard Your Medical Devices from Cyber Threats
 
Improving User Experience with Ubiquitous QuickBoot
 Improving User Experience with Ubiquitous QuickBoot Improving User Experience with Ubiquitous QuickBoot
Improving User Experience with Ubiquitous QuickBoot
 

Recently uploaded

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
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
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech studentsHimanshiGarg82
 
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
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfryanfarris8
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
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
 
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
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
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
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...software pro Development
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionOnePlan Solutions
 

Recently uploaded (20)

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
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
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
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
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
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
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
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
 
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
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
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 ...
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 

Communication Patterns for Distributed Services

  • 1. Integrated Computer Solutions Inc. www.ics.com Communication Patterns for Distributed Services Matteo Brichese June 25, 2020
  • 2. Integrated Computer Solutions Inc. www.ics.com Agenda Introduction 1. The problem with communication 2. What distributed services mean to us? Communication Patterns 1. 0MQ Quick Intro 2. Reliability, what does it mean to be reliable? 3. The basics: Request-Reply, Pub-Sub 4. RRR aka The Pirate Patterns 5. A P2P protocol 2
  • 3. Integrated Computer Solutions Inc. www.ics.com The Problem with Communication ● It’s hard ● It’s messy ● It’s centralized 3
  • 4. Integrated Computer Solutions Inc. www.ics.com What Does Distributed Service Mean to Us? Wikipedia: A distributed system is a system whose components are located on different networked computers, which communicate and coordinate their actions by passing messages to one another. The components interact with one another in order to achieve a common goal [...] A computer program that runs within a distributed system is called a distributed program. Is a program that runs between multiple processes a distributed system? What if the processes are within the same machine? 4
  • 5. Integrated Computer Solutions Inc. www.ics.com 0MQ Quick Intro ● ZMQ looks like an embeddable networking library, but acts like a concurrency framework. ● ZMQ does NOT provide any pre-made solutions ● ZMQ provides basic sockets to build your own communication infrastructure The basics: ● REQ-REP, which connects a set of clients to a set of services. ● PUB-SUB, which connects a set of publishers to a set of subscribers. ● PUSH-PULL, which connects nodes in a fan-out/fan-in pattern that can have multiple steps and loops. ● PAIR, which connects two sockets exclusively. This is a pattern for connecting two threads in a process. 5
  • 6. Integrated Computer Solutions Inc. www.ics.com 0MQ Quick Intro During this webinar we will use: ● REQ-REP sockets ● PUB-SUB sockets ● DEALER-ROUTER sockets A DEALER acts like an asynchronous REQ A ROUTER acts like an asynchronous REP 6
  • 7. Integrated Computer Solutions Inc. www.ics.com Defining Reliability What does it mean to build a reliable communication pattern Common Failures: 1. Application code 2. Proxy code 3. Overflow 4. Network failure 5. Hardware failure 6. “Exotic” network failures 7. Connection/Datacenter failures Protecting from 1 to 5 is our goal 7
  • 8. Integrated Computer Solutions Inc. www.ics.com Request-Reply Request-Reply, a classic client-server solution ● A REQ socket connects to a REP socket ● REQ sends a request ● REP replies to the request ● Everything works in lockstep, if REP hangs, REQ hangs. Pro: Easy to implement, easy to understand Cons: Easy to break, not really useful for a distributed scenario 8
  • 9. Integrated Computer Solutions Inc. www.ics.com Publisher-Subscriber 9 Publisher-Subscriber ● A SUB socket connects to a PUB socket ● PUB publishes ● SUB receives Pro: Easy to implement, easy to understand, perfect to deliver the same content to multiple services Cons: late-joiner problem
  • 10. Integrated Computer Solutions Inc. www.ics.com Reliable Request Reply patterns How to improve on the Client-Server pattern? 1. Add a timeout on the client receive function 2. Rety the communication or abandon if no reply is received within the allotted time This is what’s known as Lazy Pirate Pattern Note: Reliable Request Reply aka RRR - a pirate inside joke :) 10
  • 11. Integrated Computer Solutions Inc. www.ics.com Lazy Pirate Pattern 11 Request-Reply with retry ● A REQ socket connects to a REP socket ● REQ sends a request ● REP replies to the request ● If REP fails, REQ retries after a timeout ● After N retries REQ abandons Pro: Easy to implement, easy to understand Cons: REP is still a single point of failure
  • 12. Integrated Computer Solutions Inc. www.ics.com Simple Pirate Pattern 12 Request-Reply with retry and load distribution ● A proxy is added to hold multiple servers/workers ● Proxy distributes client load to an available server Pro: Added a failover system to Lazy Pirate Cons: Proxy is now the single point of failure, proxy doesn’t know of hanging/dead workers
  • 13. Integrated Computer Solutions Inc. www.ics.com Paranoid Pirate Pattern 13 Request-Reply with retry, load distribution and worker management ● A heartbeat is added to the proxy to monitor worker status Pro: improved worker management Cons: same as Simple Pirate
  • 14. Integrated Computer Solutions Inc. www.ics.com A Peer to Peer Protocol: Zyre 14
  • 15. Integrated Computer Solutions Inc. www.ics.com How Do We Find Other Nodes? 15 Pre-Emptive discovery: ● Use ping ● No need for node cooperation ● Need root privileges ● One node per IP address Cooperative discovery: ● Use UDP ● Needs node cooperation ● No root privileges required ● Multiple node per IP address using UUIDs
  • 16. Integrated Computer Solutions Inc. www.ics.com How Do We Know if a Node is Still Up? 16 UDP Heartbeat Under high loads UDP may never reach the target, how do we ensure that we don’t remove a node that is still up? We can use a TCP Heartbeat once multiple UDP fails, if the TCP fails too, the node is unreachable
  • 17. Integrated Computer Solutions Inc. www.ics.com How Do I Connect to All Other Nodes? 17 ● A combination of PUB-SUB ● A combination of REQ-REP or DEALER-ROUTER Zyre uses a combinations of one receiving ROUTER socket and multiple sending DEALER sockets in what was called, the Harmony pattern
  • 18. Integrated Computer Solutions Inc. www.ics.com The Harmony Pattern 18 The high-level overview ● One ROUTER socket that we bind to a ephemeral port, which we broadcast in our beacons. ● One DEALER socket per peer that we connect to the peer's ROUTER socket. ● Reading from our ROUTER socket. ● Writing to the peer's DEALER socket.
  • 19. Integrated Computer Solutions Inc. www.ics.com Thank you! 19 All examples can be found at: https://github.com/bricke/0mq-patterns Any questions?