Student Name: Đỗ Hoàng Thuấn
Student ID: 20176883
# Distributed system - Chapter 1: Introduction and Architecturesof Distributed Systems
## Question 1: What is the roles of middleware in a distributed system?
In a distributed system, the middleware has the role is make application development easier. It provides common programming abstractions, masking the heterogeneity and the distribution of the underlying hardware and OS, hide the low-level programming details.
## Question 2: Explain what is meant by (distribution) transparency, and give examples of different types of transparency
Distributed system is the work of hiding some aspects of the system, that make the users think they are using a single system.
Appear as single computer system -> transparent
Types of transparency
- Access: Hide differences in data representation and how a resource asscessed eg. hide the database
- Location: Hide where a resouce is located eg. hide the server location, database location
- Migration: Hide that a resouce may move to another location eg. hide the migration of server, or hide migration process from one database to another
- Relocation: Hide the a resouce may be move to another location while in use
- Replication: Hide the a resource is replicated eg. hide the database replication
- Concurrency: Hide that a resource may be shared by competitive users
- Failure: Hide the failure and recovery of a resource eg. hide the server die, data lost and use backupped data to restore the data.
- Persistence: Hide how the persistence work eg. read data from cache instead of database
## Question 3: Why is it sometimes so hard to hide the occurrence and recovery from failures in a distributed system?Question?
Because we cannot detect whether a server is acctually down or that it is simply slow in respondind. In reality, it’s impossible to distinguish between a node that has failed, and a very slow network or some other pause (JVM garbage collection pause, or hanging on writing a log file to a slow disk to give two common problems). This means that in practice we have to set some sort of timeout or threshold for non-responsiveness that signals a node is down, whether or not it actually is. Once we get a time-to-wait, we have a user perceivable artifact from a failure.
## Question 4: Why is it not always a good idea to aim at implementing the highest degree of transparency possible?
Aiming at the highest degree of transparency may lead to a considerableloss of performance that users are not willing to accept.
## Question 5: What is an open distributed system and what benefits does openness provide?
Open distributed system is the distributed system that is design so that it is easy to expand. We can add, place and integrate new components in open system.
Benifits:
- Expand the system will not interupt the users because of the well designed interfaces in the systems
- Quick adapt with requirement change
## Question 6: Describe precisely what is meant by a scalable system.
Scalable system is the system that has ability to cope with increased load. The term `load` in this situation means the traffic of server, the size of payload for each requests, eg.
## Question 7: Scalability can be achieved by applying different techniques. What arethese techniques?
Some techniques that can be applied to scalable system.
- Add more resouce for server - vertical scale
- Add more server (microservices) - horizontal scale
- Optimize server source code
## Question 8: If a client and a server are placed far apart, we may see network latency dominating overall performance. How can we tackle this problem?
Some ways to tackle this problem:
- Caching data on the client - i.e. avoiding to make request again if possible.
- Segment: Client will combine several request into one, this help reduce the number of requests to server
- Compress: Compress the request before it sent, help reduce size of request
- Use other protocol (UDP for faster packet sending)
- Use CDN (Content delivery networks) for static data
## Question 9: What is a three-tiered client-server architecture?
Three-tier architecture is a well-established software application architecture that organizes applications into three logical and physical computing tiers:
- Presentation tier or user interface where user interact with the application by mobile app, website or destop app
- Application tier, where data is processed
- Data tier, where the data associated with the application is stored and managed.
Refs:
- https://www.ibm.com/cloud/learn/three-tier-architecture
## Question 10: What is the difference between a vertical distribution and a horizontal distribution?
- Vertical distribution refers to the distribution of the different layers in a multitiered architecture across multiple machines.
- Horizontal distribution deals with the distribution of a single layer across multiple machines, such as distributing a single database.
Refs:
- https://stackoverflow.com/questions/5845459/what-is-the-vertical-and-horizontal-distribution#:~:text=Vertical%20distribution%20refers%20to%20the,as%20distributing%20a%20single%20database.
## Question 11: In a structured overlay network, messages are routed according to the topology of the overlay. What is an important disadvantage of this approach?
When a message is routed, we need to file the shortest path of logical service, but this path may be not the best shortest path in physical.
If the topology pre-process the message before it sent, it may create an incompatible between the pre-processing algorithm of the overlay layer and the message
## Question 12: Consider a chain of processes P1 , P2 , ..., P n implementing a multitiered client-server architecture. Process Pi is client of process Pi+1, and Pi will return a reply to Pi−1onlyafter receiving a reply from Pi+1. What are the main problems with this organization when taking a look at the request-reply performance at process P1?
- The P1 client need to wait `n - 1` clients, this will cause big latency for P1.
- Because of sequetial of dependencies, so if `Pj` clints fail, `P1` will not recive the reply
## Question 13: Considering that a node in CAN knows the coordinates of its immediate neighbors, a reasonable routing policy would be to forward a message to the closest node toward the destination. How good is this policy?

In our example from the given figure. If node (0.2,0.3) follows this policy for the message destined for node (0.9,0.6), it would send it off to node (0.7,0.2). It not the best route because the route (0.2, 0.3) -> (0.7, 0.6) -> (0.9, 0.6) has shorter Euclidean distance. This policy is help to reduce the time of estimating distance.
## Question 14: What are the benefits of Microservices architecture compared to monolithic architecture?
Benifits of Microservices architecture compared to monothonic architecture:
- **Independent components**: Firstly, all the services can be deployed and updated independently, which gives more flexibility. Secondly, a bug in one microservice has an impact only on a particular service and does not influence the entire application. Also, it is much easier to add new features to a microservice application than a monolithic one.
- **Easier understanding**: Split up into smaller and simpler components, a microservice application is easier to understand and manage. You just concentrate on a specific service that is related to a business goal you have.
- **Better**: Another advantage of the microservices approach is that each element can be scaled independently. So the entire process is more cost- and time-effective than with monoliths when the whole application has to be scaled even if there is no need in it. In addition, every monolith has limits in terms of scalability, so the more users you acquire, the more problems you have with your monolith. Therefore, many companies, end up rebuilding their monolithic architectures
## Question 15: Design yourself an e-commerce system using Microservices architecture?
My e-commerce system architecture contains *4* services:
- Product Service: This service provide product's information such as name, price, categories, eg.
- Order Service: This service takes care the purchase process including add a product to cart, create an order, create a product delivery.
- Product Recommendation Service: This service uses Deep Learning to give most related products for a product.
- User Service: Authen user, handle user action such as comment, review a product.