Distributed Computing
Real Examples
REAL EXAMPLE: MongoDB, Apache Kafka
C++ libs: MQTT (Message querying elementary transport)- mosquitto
Distributed Systems
Distributed System - is a network of computers that communicate with each other in order to achieve a certain goal
Messages – pieces of information transferred from one computer to another over a network,
tell other computers to execute procedures with particular arguments,
send an receive packets of data
- The computers on a distributed system communicates via messages
- Fail independently
- Operate Concurrently
Different types of distributed system
- Distributed Information System - distribute information accross multiple machines
- Distributed Pervasive System - use embedded computer devices (sensors, mobile devices)
- Distributed Computing System - computers on a network communicating via messages
Client/Server Systems
A way of getting a service to run on a central source.
Clients make requests, the server then serves those requests, and makes a response, so that the client can do a certain task.

Example: A browser requesting for a webpage off the website server, the website server will respond by sending the (HTML and CSS...) and the browser will then show the user that page.
OR your mouse and keyboard to your program (client)
Server - a unit that provides a service, possibly to multiple clients simultaneously
Client - a unit that consumes the service
The clients do not need to know the details of how the service is provided, or how the data they are receiving is stored or calculated, and the server does not need to know how the data is going to be used.
Disadvantage
- Single point of failure
- Not enough server resources if there are too many clients, since it cannot change size with demand
Peer-to-Peer Systems
Peer-to-Peer - a network where all systems have equal labour divided between them

- Is typically used for data-transfer and data-storage
- Data-storage is achieved by, storing parts of the file on different computers
- All computers must know the locations of the other computers on the network
- Some networks have dedicated devices to help with the health of the network, helping devices stay connected, help new devices when they join the network
Advantage
- As the network grows so does the computational resources
Master Slave

Master node has complete information about the system and controls the decision making.
Message Passing
Content
- Sender - so the recipient knows who it was sent from
- Recipient - so other computers on the network knows who to send it to
- Content - data, signal, instructions
Architecture
- In the messaging passing architecture, publishers publish messages into topics that can be subscribed by multiple subscribers.
- Each device in the network can have one or more subscribers and publishers.
For example, a smart camera may publish the image frames into a topic and subscribe to the configuration parameters (e.g. resolution, speed, etc) from a different topic.

The message passing architecture only requires a message broker that is responsible manage the messages being published into the topics.
- Dispatch Function - the function that sends the message
- sender and recever are identified
- sender and recever are encoded into the message
- data also attached
- dispatch function then sends the message over the network
Message Protocol - set for rules for encoding and decoding messages
Messsage Protocols are not typically a lib, but just a set of rules
CAP Theorem
Defining the constraints on a distributed system in terms of the attributes that can guarantee. Essentially a distributed system cannot have all three.

Consistency – every read receives the most recent right or an error
Availability – every read receives a non-error response even if it may not be the most recent wright
Petition tolerance – the system continues to function even if a part of the network fails
Cons of Distributed
- Has to choose between consistency and availability
- Data Distribution: complex algorithms to efficiently partition data and later combine the data
- Coordination: complexe protocols to coordinate
Cloud vs Distributed
Distributed
- Spreads tasks across many machines
- Aims to create a clubs resource sharing and providing size and geographical stability
Cloud
- Uses network hosted service for storage, processing and data management
- Cloud computing is about delivering and OnDemand environment using transparency, monitoring and security
- Is less reliable since relies on other services, thus giving you less control
Decentralised vs Distributed
Decentralised - Distributed on a technical level, but usually decentralised system is not owned by a single source
Therefore it is harder to manage a decentralised system, Since you can't manage all the participants
Distributed dash single course design where one tram/company owns all the
Benefits of a Distributed system
Scaling – distributed system allows you to scale horizontally so you can account for more traffic (baso you can put machines in parallel, and not have to replace the entire system (vertical))
Modular growth – there is almost no cap to how much you can scale
Fault tolerance – distributed systems are more fault tolerant than a single machine
Cost-effective – the initial cost is higher than a traditional system, but because of their stability, they quickly become more cost-effective
Low latency – uses have a node in multiple locations, so traffic will hit the closest node
Efficiency - distributed systems break complex data into small pieces
Parallelism – multiple processes divide up into a complex problem into pieces
Deficits of a Distributed system
Failure handling – since multiple processes are running the same function, if one function fails the others will carry on running, this is good if you are doing a large data set and don't want the entire system to fail, but is a pain in the arse when troubleshooting
Concurrency – there is an issue when several clients attempt to access the same shared resource at the same time, must ensure that all resources are in a safe concurrent environment
Security issues – data security and sharing have increased risks and distributed to computer systems, the network has to be secured and users must be able to safely access replicated data across multiple locations
Higher initial infrastructure costs – it is cheaper to vertically increase the size of a system at first, but eventually it is cheaper to upgrade horizontally