Distributed system TYPED NOTES
Distributed system TYPED NOTES
Architectural Models
The architecture of a distributed system defines how its components interact. Common models
include:
1. Client-Server Model:
– The server provides services (e.g., a database server), and the client requests
them (e.g., a web browser).
2. Peer-to-Peer (P2P) Model:
– All nodes (computers) have equal roles and share resources directly without a
centralized server (e.g., torrent systems).
3. Layered Architecture:
– Organizes the system into layers (e.g., application layer, middleware layer,
network layer) for better manageability.
Fundamental Models
Fundamental models define the basic properties and behaviors of a distributed system:
1. Interaction Model:
– Describes how components communicate. For example, components may send
messages over a network.
2. Failure Model:
– Describes possible failures like crash failures, omission failures (missing data), or
timing failures (delays).
3. Security Model:
– Defines security measures like encryption, authentication, and secure data access
to protect the system from attacks.
By understanding these concepts, one can grasp the essence of distributed systems and their
real-world applications while appreciating the challenges involved in their development and
management.
Logical Clocks
Logical clocks are mechanisms to order events in a distributed system where there is no global
clock. They provide a way to determine the sequence of events (happened-before relationship)
in a distributed environment. Logical clocks are essential for achieving consistency in distributed
systems.
Lamport introduced a logical clock (L) for each process to track events:
1. Rule 1 (Internal Events): For every event ( e ) within a process ( P ), increment ( L(P) ) by 1.
– ( L(P) = L(P) + 1 ).
2. Rule 2 (Send Event): When ( P ) sends a message, it includes its current timestamp.
3. Rule 3 (Receive Event): When ( Q ) receives a message, update ( L(Q) ) to:
– ( L(Q) = \max(L(Q), L(P)) + 1 ).
Vector Clocks
Vector clocks enhance Lamport's Logical Clocks by tracking causal relationships between
events. Each process maintains a vector of timestamps, one for each process in the system.
1. Structure:
– ( V[i] ) represents the logical clock of process ( i ).
2. Rules:
– Internal Event: Increment the local clock of the process:
• ( V[i] = V[i] + 1 ).
– Send Event: Before sending a message, increment the local clock and attach the
vector clock.
– Receive Event: When a process ( Q ) receives a message, update its vector clock:
• ( V[Q][j] = \max(V[Q][j], V[P][j]) ) for all ( j ), and increment ( V[Q][Q] ).
Vector clocks provide more precision than Lamport clocks by identifying causally related and
concurrent events.
• If process ( P ) sends message ( M1 ) and then ( M2 ), and both are sent to ( Q ), ( Q ) must
deliver ( M1 ) before ( M2 ).
Vector clocks help achieve causal ordering by timestamping messages with their causal
dependencies.
Global State
The global state of a distributed system is the combined state of all processes and the
communication channels at a particular point in time. Capturing the global state is challenging
due to the lack of a global clock.
Termination Detection
Termination detection determines when a distributed computation has completed. This is tricky
in distributed systems because processes operate independently and asynchronously.
Summary
• Logical Clocks (Lamport & Vector): Provide ways to order events in a distributed system.
• Message Passing Systems: Handle causal and total ordering of messages.
• Global State: Represents the system's snapshot at a given moment.
• Termination Detection: Ensures the system knows when all work is done.
Understanding these concepts is crucial for designing and analyzing distributed systems,
especially in applications like cloud computing and real-time systems.
UNIT 2
1. Token-Based Algorithms:
– A unique token is used to grant access to the critical section.
– Only the process holding the token can enter the critical section.
– Examples: Token ring algorithm.
2. Non-Token-Based Algorithms:
– Processes use a request and reply mechanism to ensure mutual exclusion.
– Messages are exchanged between processes to decide who gets access.
– Examples: Ricart-Agrawala algorithm.
3. Hybrid Algorithms:
– Combine features of token-based and non-token-based approaches for better
performance or fault tolerance.
1. Safety:
– At most one process can be in the critical section at any time.
2. Liveness:
– A process requesting access to the critical section will eventually be granted
access (no starvation).
3. Fairness:
– Requests are handled in the order they are made (FIFO order).
4. Fault Tolerance:
– The algorithm should handle failures (e.g., of processes or communication links)
gracefully.
Token-Based Algorithms
In token-based algorithms, a unique token circulates in the system, granting access to the
critical section.
Non-Token-Based Algorithms
In non-token-based algorithms, processes communicate using messages to request and release
access to the critical section.
Ricart-Agrawala Algorithm:
1. Structure:
– Each process keeps a logical clock (Lamport or vector clock).
2. Operation:
– When a process wants to enter the critical section:
• It sends a request message (with its timestamp) to all other processes.
– Other processes:
• Reply immediately if they are not in the critical section or not requesting
it.
• Delay their reply if they are in the critical section or have a request with a
lower timestamp.
– The process enters the critical section once it receives replies from all other
processes.
3. Advantages:
– No token is needed, so there's no risk of token loss.
– Fair ordering is ensured using timestamps.
4. Disadvantages:
– High message overhead: ( 2(n-1) ) messages for every critical section request,
where ( n ) is the number of processes.
Performance Metrics
To evaluate and compare distributed mutual exclusion algorithms, the following performance
metrics are considered:
1. Message Complexity:
– The number of messages exchanged per critical section access.
– Token-based: Low (1 message to pass the token).
– Non-token-based: High (at least ( 2(n-1) )).
2. Synchronization Delay:
– The time taken to grant access to the critical section after a request.
– Token-based: Low, as the token is directly passed.
– Non-token-based: Higher, as it requires replies from all processes.
3. Fault Tolerance:
– Ability to handle failures.
– Token-based: Token loss requires regeneration, which is complex.
– Non-token-based: More resilient, as no token is used.
4. Fairness:
– Ensures processes are granted access in the order of their requests.
– Both token-based and non-token-based algorithms can maintain fairness with
proper design.
5. Throughput:
– The number of critical section accesses completed in a given time.
– Token-based algorithms generally have higher throughput due to low overhead.
System Model
The system can be represented as a Resource Allocation Graph (RAG):
1. Nodes:
– Processes (P1, P2, ...).
– Resources (R1, R2, ...).
2. Edges:
– Request edges: ( P1 \rightarrow R1 ) (process requests resource).
– Assignment edges: ( R1 \rightarrow P1 ) (resource assigned to process).
In distributed systems:
While effective, prevention can be too restrictive and lead to low resource utilization.
Deadlock Avoidance
Deadlock avoidance ensures the system remains in a safe state where deadlock cannot occur:
Advantages:
• Simplicity.
• Easier to implement and debug.
Disadvantages:
Advantages:
Disadvantages:
• Complex algorithms.
• Communication overhead due to message exchanges.
1. Procedure:
– Each node sends its dependency paths to other nodes.
– When a node receives a path, it extends it with its dependencies and propagates
it further.
– If a path returns to the originating node, a cycle (deadlock) is detected.
2. Example:
– Process P1 → P2 → P3 → P1 indicates a deadlock.
3. Advantages:
– Simple conceptually.
– Effective for detecting cycles.
4. Disadvantages:
– High communication overhead due to long paths.
1. Procedure:
– When a process ( P1 ) is waiting on ( P2 ), it sends a probe message to ( P2 ).
– The message includes:
• Information about the initiator (e.g., ( P1 )).
• The dependency chain so far.
– If the probe returns to the initiator ( P1 ), a deadlock is detected.
2. Advantages:
– Low communication overhead compared to path pushing.
– More efficient in detecting cycles.
3. Disadvantages:
– Requires careful handling of probe messages.
– More complex to implement.
Summary
Distributed deadlock detection is a challenging but essential aspect of managing resources in
distributed systems. It involves identifying and resolving deadlocks caused by resource or
communication dependencies. Centralized methods are simpler but less robust, while
distributed methods, such as path pushing and edge chasing, offer scalability and resilience at
the cost of complexity. Choosing the right approach depends on the system's size,
requirements, and fault tolerance needs.
UNIT 3
Introduction
Distributed systems consist of multiple nodes that must often agree on a shared value or
decision, such as committing a transaction, synchronizing clocks, or electing a leader. However,
achieving agreement in such systems is challenging due to:
Requirements:
1. Agreement: All non-faulty nodes agree on the same value.
2. Validity: If all non-faulty nodes propose the same value, they must agree on that value.
3. Termination: All nodes must reach a decision in a finite time.
Challenges:
• Difficult to distinguish between a slow node and a faulty one.
• Malicious nodes can send conflicting information to different nodes.
Solution:
The Byzantine Agreement problem can be solved if:
Consensus Problem
Definition:
Consensus involves all nodes in a distributed system agreeing on a single value, despite failures.
Requirements:
1. Agreement: All non-faulty nodes agree on the same value.
2. Validity: If a value is proposed by a non-faulty node, the agreed-upon value must be one
of the proposed values.
3. Termination: All nodes decide within a finite time.
Solutions:
• Paxos Algorithm: Ensures consensus in an asynchronous system with crash faults.
• Raft Algorithm: Simplified version of Paxos, widely used in distributed systems.
Requirements:
• Each node must agree on the same value for every other node, ensuring consistency.
Example:
In a flight control system, interactive consistency ensures all controllers have the same state of
the aircraft's position.
Solution to Byzantine Agreement Problem
Key Techniques:
1. Message Authentication:
– Use cryptographic methods to detect tampering or malicious messages.
2. Redundancy:
– Exchange messages multiple times to verify consistency.
3. Majority Voting:
– Rely on the majority to determine the correct value.
Algorithm Example:
Oral Messages Algorithm:
Techniques:
1. Two-Phase Commit (2PC):
– Phase 1: Coordinator asks all nodes if they can commit.
– Phase 2: Based on responses, the coordinator sends a commit or abort decision.
– Drawback: Blocking nature if the coordinator crashes.
2. Three-Phase Commit (3PC):
– Adds an intermediate phase to avoid blocking.
– Ensures safety in case of coordinator failure.
Summary
Agreement protocols play a critical role in distributed systems by enabling nodes to reach
consistent decisions despite failures or malicious behavior. These protocols ensure reliability
and consistency across diverse applications, such as distributed databases, fault-tolerant
systems, and blockchain networks. Techniques like Byzantine Agreement, Consensus, and
Atomic Commit provide robust solutions tailored to specific system models and requirements.
A Distributed File System (DFS) is a system that manages and provides access to files stored on
multiple servers or machines, which can be located in different geographical locations. The goal
of a DFS is to provide users with a unified interface to access these files, despite the underlying
distribution of data.
a. Transparency:
Transparency refers to hiding the complexity of the distributed system from the user. In the
context of distributed file systems, there are several types of transparency:
• Access Transparency: Users should not need to know whether they are accessing a file
stored locally or on a remote machine.
• Location Transparency: Users should not need to know where the files are physically
stored. The system should handle the details of file location automatically.
• Replication Transparency: Users should not need to know whether a file has multiple
replicas, or if some replicas are unavailable.
• Concurrency Transparency: The system should manage concurrent access to files so
that users can read/write data without conflicts or data corruption.
b. Fault Tolerance and Reliability:
In a distributed file system, nodes and communication links can fail. A robust DFS must handle
failures without compromising data integrity and availability. Issues related to fault tolerance
include:
• Crash Recovery: Ensuring that the system can recover from crashes without losing data.
• Replication: Files should be replicated across multiple servers to ensure that even if one
server fails, the data is still available.
• Consistency: The system must maintain consistency across replicas, ensuring that
changes made to one replica are reflected in others.
• File Locking: To prevent conflicting operations, the system must provide mechanisms
for locking files or parts of files.
• Write Propagation: Changes made to a file must be propagated to all replicas in a
consistent manner.
• Consistency Models: The DFS must decide whether to use strong consistency (where all
nodes see the same data at the same time) or eventual consistency (where updates are
propagated asynchronously, leading to temporary discrepancies).
d. Performance:
Performance is a critical issue in distributed file systems. The system should be able to handle
large-scale data access with low latency and high throughput. Key factors that affect
performance include:
• Data Locality: Storing files near the users or processes that access them most
frequently.
• Caching: Using caches to store frequently accessed files or parts of files locally, reducing
the need for repeated access over the network.
• Load Balancing: Distributing the file access load evenly across the system’s resources to
avoid bottlenecks.
• Data Distribution: The system should be able to scale horizontally, adding more nodes
and distributing the data evenly across them.
• Directory Management: The system must efficiently manage metadata (file locations,
access permissions, etc.) even as the number of files and users grows.
• Global Naming Space: A common naming scheme used across all machines in the
distributed system, which ensures that file names are unique and globally recognized.
• Directory Services: The system must maintain a global directory that maps file names to
their physical locations (usually a directory server or metadata server).
• Data Replication: Storing multiple copies of data on different nodes so that if one node
fails, another can take over.
• Primary-Backup Replication: One replica is the primary copy, and other replicas are
backups. If the primary fails, a backup is promoted.
• Quorum-based Systems: A minimum number of replicas must agree on a read or write
operation to ensure consistency.
• Erasure Coding: Data is split into pieces and encoded with redundancy. This reduces the
storage overhead compared to full replication.
c. Caching:
Caching improves performance by storing frequently accessed data locally. The system should
have mechanisms to manage cached data, such as:
• Write-through Cache: Changes to the cache are immediately written to the underlying
storage.
• Lazy Write Cache: Changes are written to the storage at a later time, which improves
performance but may introduce consistency issues.
• Cache Invalidation: When a file is updated, all cached copies must be invalidated or
updated to maintain consistency.
• Distributed Locking: A mechanism to ensure that only one client or process can access a
file or portion of a file at a time. Locks can be applied at various granularity levels (e.g.,
file-level, block-level).
• Leases: A lease is a time-limited lock granted to a client for exclusive access to a file.
After the lease expires, the lock is released, allowing other clients to access the file.
• Versioning: Each update to a file can be stored as a new version, allowing clients to work
on different versions and later merge them.
e. Consistency Models:
The DFS must decide which consistency model it will implement. Some common models
include:
• Strict Consistency: All replicas are updated instantly and seen consistently by all clients.
• Sequential Consistency: Operations on the file system appear to happen in some
sequential order, but not necessarily instantaneously across replicas.
• Eventual Consistency: Updates to the system are propagated asynchronously, meaning
that at any given point, different replicas might be inconsistent, but they will eventually
converge to the same value.
Summary
• Distributed File Systems (DFS) are essential for providing access to data stored across
multiple machines in a distributed environment.
• Key issues in DFS include ensuring transparency, fault tolerance, consistency,
concurrency control, and performance.
• Mechanisms for building DFS include file naming and location management, data
replication, caching, distributed locking, concurrency control, and consistency models.
• Effective DFS design focuses on achieving scalability, availability, and resilience to
failures, ensuring that users can access files reliably even in large-scale, distributed
systems.
By addressing these issues and employing these mechanisms, a distributed file system can
provide a robust and efficient infrastructure for managing and sharing files across a distributed
network.
2. Data Consistency
• Consistency Model: Ensuring that all nodes have a consistent view of the shared
memory.
– Strict Consistency: All memory operations appear to execute instantaneously at a
single point in time.
– Sequential Consistency: Operations appear in the same order across all nodes
but may not be instantaneous.
– Causal Consistency: Operations maintain cause-and-effect relationships.
– Eventual Consistency: Changes are eventually propagated to all nodes but not
immediately.
3. Synchronization
• Mechanisms like locks, semaphores, or barriers are required to synchronize access to the
shared memory.
• Minimizing contention when multiple processes try to access the same memory
simultaneously is crucial.
4. Memory Coherence
• Ensuring that if multiple copies of the same data exist in different nodes, they are
updated consistently when changes occur.
5. Fault Tolerance
• Handling node or network failures while maintaining data integrity and availability.
6. Communication Overheads
• DSM requires communication between nodes to synchronize and update data.
Minimizing the frequency and size of these communications is critical for performance.
7. Scalability
• DSM should work efficiently as the number of nodes increases.
8. Transparency
• DSM should provide:
– Access Transparency: Abstract details of data location.
– Replication Transparency: Abstract how data copies are managed.
– Concurrency Transparency: Abstract the complexity of simultaneous access.
1. Centralized Algorithm
• A single node (or server) is responsible for managing the shared memory.
• Advantages:
– Simple design.
– Easier to maintain consistency.
• Disadvantages:
– Single point of failure.
– Scalability issues due to bottlenecks.
2. Distributed Algorithm
• Memory management responsibilities are distributed across all nodes.
• Advantages:
– Better scalability.
– No single point of failure.
• Disadvantages:
– Increased complexity in maintaining consistency and coherence.
• Each object has a manager node that tracks its location and ownership.
• Nodes requesting access to the object communicate with the manager to retrieve or
update it.
Advantages of DSM
1. Simplifies programming by abstracting inter-process communication.
2. Provides a unified view of memory across distributed nodes.
3. Reduces development time for distributed applications.
Disadvantages of DSM
1. Overhead in maintaining consistency and coherence.
2. Potential for increased latency due to network communication.
3. Scalability issues if not designed efficiently.
Conclusion
DSM is a powerful abstraction for distributed systems, enabling nodes to share memory
seamlessly. However, its design involves addressing challenges related to consistency,
synchronization, fault tolerance, and performance. Algorithms like page-based or object-based
DSM play a key role in implementing these systems efficiently.
2. Forward Recovery
• Definition: The system moves forward by correcting the errors without rolling back to a
previous state.
• Use Case: Used when the error can be isolated and corrected directly.
• Steps:
a. Analyze and identify the impact of the failure.
b. Apply corrective actions to bring the system to a consistent state.
c. Continue operations without significant downtime.
Challenges:
1. Synchronization Issues: Concurrent processes often share resources, leading to
difficulties in maintaining a consistent state during recovery.
2. Order of Execution: Ensuring that operations maintain their intended order after
recovery.
3. Deadlocks: Recovery might introduce deadlocks that need resolution.
Solutions:
• Consistent Checkpoints: Ensure all processes save their states at a globally consistent
point.
• Message Logging: Record communication between processes to replay messages during
recovery.
Challenges:
1. Process Dependencies: States of interdependent processes may become inconsistent.
2. Non-Deterministic Events: Random events or failures may disrupt checkpointing.
Techniques:
1. Coordinated Checkpointing:
– All processes coordinate to save their states simultaneously.
– Ensures a global consistent checkpoint.
– Disadvantage: May cause delays as all processes must synchronize.
2. Uncoordinated Checkpointing:
– Each process independently saves its state.
– Relies on message logging to resolve inconsistencies.
– Disadvantage: May lead to the domino effect, requiring multiple rollbacks.
3. Incremental Checkpointing:
– Only changes since the last checkpoint are saved.
– Reduces overhead but requires additional mechanisms to manage partial state
updates.
4. Consistent Snapshot Algorithm (e.g., Chandy-Lamport Algorithm):
– Captures the global state of the system.
– Achieved by marking the state of processes and the messages in transit.
Challenges:
1. Network Partitions: Nodes might lose communication temporarily.
2. Transaction Dependencies: Transactions running across multiple nodes might become
inconsistent.
3. Concurrency Control: Coordinating recovery among multiple concurrent transactions.
Techniques:
1. Logging:
– Maintain logs (undo logs, redo logs) of all database operations.
– Use these logs to roll back or reapply operations during recovery.
2. Checkpointing:
– Save consistent snapshots of the database at regular intervals.
– Combine checkpointing with logs for faster recovery.
3. Two-Phase Commit (2PC):
– Ensures atomicity across distributed transactions.
– Phases:
i. Prepare Phase: All nodes agree to commit or abort.
ii. Commit Phase: Commit is executed only after all nodes confirm
readiness.
– Disadvantage: Can block progress during failures.
4. Three-Phase Commit (3PC):
– Enhances 2PC by adding a third phase to reduce blocking.
– Ensures system remains consistent even in case of node failures.
5. Replication:
– Maintain copies of data on multiple nodes.
– Use replication protocols (e.g., Paxos, Raft) to ensure consistency during
recovery.
Conclusion
Failure recovery in distributed systems is essential to maintain reliability and consistency.
Techniques like backward and forward recovery, checkpointing, and specialized database
recovery mechanisms address different challenges posed by distributed environments. Proper
recovery strategies depend on the system’s design goals, performance requirements, and the
types of failures anticipated.
Fault Tolerance in Distributed Systems
Fault tolerance refers to the ability of a distributed system to continue functioning correctly in
the presence of hardware, software, or network failures. It ensures system reliability, availability,
and consistency despite failures.
Commit Protocols
Commit protocols are used to ensure that distributed transactions maintain atomicity (all-or-
nothing property) despite failures.
Voting Protocols
Voting protocols ensure consistency and fault tolerance by requiring a majority or quorum of
nodes to agree on an operation or decision.
Example Algorithm:
1. A transaction or operation is proposed.
2. Nodes cast votes based on their current voting power.
3. If the quorum is met (e.g., majority of votes), the operation is committed.
4. If the quorum is not met, the operation is aborted or retried.
Advantages:
• Allows progress even in systems with frequent failures or recoveries.
• Reduces the risk of blocking.
Disadvantages:
• Complex to implement and manage.
Conclusion
Fault tolerance is a critical aspect of distributed systems, ensuring reliability and consistency in
the presence of failures. Techniques like commit protocols, voting, and dynamic voting provide
mechanisms to handle failures effectively, each with its trade-offs in terms of complexity,
performance, and resilience.
Transactions and Concurrency Control in Distributed Systems
Distributed systems often involve multiple processes or users accessing shared data.
Transactions and Concurrency Control mechanisms are used to maintain consistency, isolation,
and atomicity in such systems, even when multiple transactions execute concurrently.
1. Transactions
A transaction is a sequence of operations performed as a single logical unit of work. It ensures
the ACID properties:
1. Atomicity: Either all operations of the transaction are completed, or none are.
2. Consistency: A transaction transforms the system from one consistent state to another.
3. Isolation: Transactions operate independently without interfering with each other.
4. Durability: Once a transaction is committed, its changes persist, even in case of a failure.
Types of Transactions
• Flat Transactions: A single transaction with no internal structure.
• Nested Transactions: A transaction that contains sub-transactions, providing a
hierarchical structure.
2. Nested Transactions
Nested transactions allow greater modularity and fault tolerance. They consist of a parent
transaction and multiple child transactions.
Characteristics:
• Child transactions can execute independently.
• If a child transaction fails, it can roll back without affecting other child transactions.
• The parent transaction only commits when all child transactions successfully commit.
Use Cases:
• Complex distributed systems where operations can be divided into subtasks.
• Database systems for distributed queries.
3. Concurrency Control
Concurrency control ensures the correctness of transactions that execute simultaneously. It
resolves issues like:
1. Types of Locks:
– Shared Lock (Read Lock): Allows multiple transactions to read but not write.
– Exclusive Lock (Write Lock): Prevents other transactions from reading or writing.
2. Two-Phase Locking (2PL):
– Growing Phase: A transaction acquires locks but cannot release them.
– Shrinking Phase: A transaction releases locks but cannot acquire new ones.
– Guarantees serializability but may cause deadlocks.
3. Deadlock Handling:
– Deadlock Prevention: Avoid situations where circular waiting occurs.
– Deadlock Detection: Periodically check for deadlocks and resolve them by
aborting transactions.
6. Summary
• Transactions ensure atomicity, consistency, isolation, and durability in distributed
systems.
• Nested Transactions enhance fault tolerance by allowing partial rollbacks.
• Concurrency Control mechanisms like locking, OCC, and timestamp ordering resolve
conflicts and maintain correctness during concurrent executions.
• Each method has trade-offs and should be chosen based on system requirements such
as read-write patterns, conflict frequency, and the need for deadlock prevention.
Distributed Transactions
Distributed transactions occur across multiple systems or nodes in a distributed environment,
where each participating node (or database) may execute different parts of the transaction.
Ensuring that distributed transactions are atomic (all-or-nothing), consistent, isolated, and
durable (ACID properties) is more complex in distributed systems due to challenges like network
failures, system crashes, and concurrent access to shared data.
1. Flat and Nested Distributed Transactions
a. Flat Distributed Transactions
• In flat transactions, all operations involved in the transaction are executed in a single
sequence, typically across multiple nodes or systems.
• Characteristics:
– It has a single scope, where all sub-transactions are treated as a whole.
– Typically follows the Two-Phase Commit (2PC) protocol for atomic commit.
– If any operation fails at any node, the entire transaction is aborted.
• Example: A financial transaction that updates accounts in two different databases. If one
of the updates fails, the entire transaction is rolled back.
• Involves an additional phase called Pre-Commit between the Prepare and Commit
phases.
• Phases:
a. CanCommit: The coordinator checks if all participants are ready to commit.
b. PreCommit: The coordinator sends a pre-commit signal to participants.
c. Commit: The coordinator sends a final commit signal after all participants are
pre-committed.
• Advantages:
– Non-blocking in case of coordinator failure.
• Disadvantages:
– More complex and overhead than 2PC.
c. Timestamp Ordering
• Each transaction is assigned a timestamp. Transactions are ordered based on their
timestamps, and their operations are executed in timestamp order.
• Advantages:
– Simple and ensures serializability.
• Disadvantages:
– Risk of transaction aborts due to timestamp violations.
4. Distributed Deadlocks
Deadlocks in distributed systems occur when transactions are stuck in a waiting state due to
resource contention, and no transaction can make progress.
a. Detection
• Distributed systems use algorithms to detect deadlocks by analyzing the dependencies
between transactions.
– Centralized Deadlock Detection: One node (centralized controller) monitors
transactions and detects deadlocks.
– Distributed Deadlock Detection: Multiple nodes coordinate to detect deadlocks,
typically using algorithms like path pushing or edge chasing.
b. Resolution
• Once deadlock is detected, the system must resolve it, typically by aborting one or more
transactions to break the cycle.
5. Transaction Recovery
Transaction recovery ensures that distributed transactions can be restored to a consistent state
after a failure, without violating ACID properties.
a. Checkpoints
• A checkpoint is a snapshot of the system at a particular point in time, recording the state
of the transactions and data.
• When a failure occurs, the system can roll back to the last checkpoint, ensuring that no
partially completed transactions are left behind.
b. Log-Based Recovery
• The system maintains a log of all operations performed by the transactions.
• In case of failure, the system can redo or undo operations based on the log:
– Redo: Reapplies committed transactions.
– Undo: Rolls back uncommitted transactions.
Summary
• Distributed Transactions involve coordinating multiple systems to ensure the ACID
properties are maintained across various nodes.
• Flat transactions are simple, while nested transactions allow more modular,
hierarchical operations.
• Atomic Commit Protocols, like 2PC and 3PC, are essential for ensuring atomicity and
consistency across nodes.
• Concurrency Control ensures transactions execute without conflicts, using techniques
like locking, optimistic concurrency control, and timestamp ordering.
• Distributed Deadlocks are handled by detection algorithms and resolution strategies to
prevent transactions from being stuck.
• Transaction Recovery uses techniques like checkpoints and log-based recovery to
restore consistency after a failure.
• Nodes: These are the machines or servers that store replicas of data.
• Replica: A copy of a piece of data that is stored on multiple nodes.
• Primary (Master) and Replica (Slave) Nodes: A primary node holds the original version
of the data, while replica nodes hold copies of the data.
• Quorum: In some systems, a minimum number of nodes must agree on a change before
it is committed, ensuring consistency.
• Consistency Level: Defines how many replicas need to be updated before a transaction is
considered committed. Different consistency levels include:
– Strong Consistency: All replicas are identical after each update (e.g.,
linearizability).
– Eventual Consistency: Updates propagate over time, but replicas might
temporarily differ (e.g., used in systems like Cassandra).
2. Group Communication
Group communication is the foundation of replication in distributed systems. It refers to the
coordination of messages between multiple processes or nodes in a group, ensuring that
messages are delivered to all members in the group in a consistent and reliable manner.
• Total Order: Ensures that all members of the group receive messages in the same order.
• Causal Order: Guarantees that if one message causally influences another, they are
delivered in the correct order.
• FIFO (First In First Out) Order: Messages from a single sender are delivered in the order
they were sent, but there’s no guarantee across different senders.
• Recovery: The ability to restore a system to a consistent state after a failure. In the
case of replication, this could mean restoring the primary data from a replica or
reintegrating a failed replica.
– Primary-backup replication: One replica is designated as the primary, and others
as backups. If the primary node fails, one of the backups is promoted to primary.
– Quorum-based Replication: A quorum defines a minimum number of replicas
that must participate in any read or write operation. A quorum helps to maintain
data consistency and ensures that a majority of nodes can make decisions
independently, even if some nodes are down.
d. Split-Brain Problem:
• The split-brain scenario occurs when there is a network partition, and multiple replicas
think they are the primary replica. This leads to inconsistent data and can cause major
issues in the system. Protocols like Quorum-based replication and Raft can help avoid
this problem by ensuring that only one replica is allowed to be the primary at any given
time.
5. Applications of Replication
• Distributed Databases: Replication helps maintain consistency and availability in
distributed databases like MongoDB, Cassandra, and HBase.
• Cloud Services: Cloud providers use replication to ensure that data is highly available,
even in case of failures. Services like Amazon S3 and Google Cloud Storage rely on
replication.
• Distributed File Systems: Systems like HDFS (Hadoop Distributed File System)
replicate data across multiple nodes to ensure that files are available even if one or more
nodes fail.
• Content Delivery Networks (CDNs): CDNs use replication to store copies of data at
multiple locations, reducing latency and improving access speed for users across the
globe.
Summary
• Replication in distributed systems involves storing multiple copies of data across
different nodes to improve availability, fault tolerance, and performance.
• The system model for replication ensures that data is consistent and reliable, and group
communication ensures that updates to replicas are coordinated across all nodes.
• Fault tolerance in replicated systems is achieved through redundancy, failure detection,
and recovery mechanisms, and protocols like Paxos and Raft ensure consistency despite
failures.
• Challenges in replication include ensuring consistency (CAP Theorem), handling network
partitions, and managing the performance overhead of maintaining multiple replicas.