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

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
 
Qt 6 Chat - Are You Ready?
Qt 6 Chat - Are You Ready?Qt 6 Chat - Are You Ready?
Qt 6 Chat - Are You Ready?ICS
 

More from ICS (20)

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
 
Qt 6 Chat - Are You Ready?
Qt 6 Chat - Are You Ready?Qt 6 Chat - Are You Ready?
Qt 6 Chat - Are You Ready?
 

Recently uploaded

Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 

Recently uploaded (20)

Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 

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?