TU BCA Distributed Systems Master Guide: RPC, Java RMI, Lamport Logical Clocks & Distributed Mutual Exclusion
Author: Bhuban Subedi | Subject: Distributed System (CACS352) | Semester: Sixth Semester
Modern cloud computing, distributed databases (like Google Spanner and Apache Cassandra), and blockchain networks rely fundamentally on distributed systems theory. In the Tribhuvan University BCA sixth semester, Distributed System (CACS352) teaches students how collections of autonomous computing nodes communicate over networks to appear as a single coherent system.
In the final 60-mark TU board examination, examiners heavily emphasize Remote Procedure Calls (RPC) vs. Java Remote Method Invocation (RMI), Lamport’s Logical Clocks (Happens-Before relation $\to$), Vector Clocks, and Distributed Mutual Exclusion Algorithms (Ricart-Agrawala, Centralized, Token Ring).
In this guide, I will break down these distributed computing concepts with clear diagrams and mathematical order relations.
1. Centralized vs. Distributed System Architectures
+-------------------+-----------------------------------+-----------------------------------+
| Feature | Centralized System | Distributed System |
+-------------------+-----------------------------------+-----------------------------------+
| **Nodes** | Single central mainframe/server. | Multiple independent nodes. |
+-------------------+-----------------------------------+-----------------------------------+
| **Memory** | Shared central memory. | Distributed / Separate memory. |
+-------------------+-----------------------------------+-----------------------------------+
| **Failure Mode** | Single Point of Failure (SPoF). | Fault-tolerant; partial failures. |
+-------------------+-----------------------------------+-----------------------------------+
| **Scalability** | Vertical scaling (Expensive RAM). | Horizontal scaling (Add nodes). |
+-------------------+-----------------------------------+-----------------------------------+
2. Remote Procedure Call (RPC) vs. Java RMI
+-------------------------------------------------------------------------------+
| RPC (REMOTE PROCEDURE CALL) WORKFLOW |
| |
| 1. Client Application calls local Client Stub with parameters. |
| 2. Client Stub marshals (serializes) parameters into a network message packet.|
| 3. Operating System / Socket transmits packet over network to Server. |
| 4. Server OS passes packet to Server Skeleton / Stub. |
| 5. Server Skeleton unmarshals parameters and invokes actual local procedure. |
| 6. Procedure executes, results are marshaled and transmitted back to Client. |
+-------------------------------------------------------------------------------+
+-------------------+-----------------------------------+-----------------------------------+
| Parameter | Remote Procedure Call (RPC) | Java RMI (Remote Method Invoc) |
+-------------------+-----------------------------------+-----------------------------------+
| **Paradigm** | Procedural (Functions/C-style). | Object-Oriented (Objects/Methods).|
+-------------------+-----------------------------------+-----------------------------------+
| **Language** | Language-independent via IDL | Java-specific (Passes objects by |
| | (Interface Definition Language). | value or reference). |
+-------------------+-----------------------------------+-----------------------------------+
| **Garbage Coll** | Manual memory management. | Distributed Garbage Collection. |
+-------------------+-----------------------------------+-----------------------------------+
3. Clock Synchronization & Lamport’s Logical Clocks
In a distributed network, physical quartz clocks drift, making synchronized wall-clock time unreliable. Leslie Lamport introduced Logical Clocks based on the Happens-Before Relation ($\to$):
Lamport’s Clock Rules:
- If events $a$ and $b$ occur within the same process and $a$ occurs before $b$, then $C(a) < C(b)$.
- If event $a$ is the sending of a message by one process and event $b$ is the receipt of that message by another process, then $C(a) < C(b)$.
- Updating Rule on Receipt: When process $P_j$ receives a message with timestamp $T_m$, it updates its clock:
$$C_j = \max(C_j, T_m) + 1$$
Process P1: (1) ───[Send Msg: T=2]────────────────────────┐
│
Process P2: (1) ──────► (2) ──────► [Recv Msg: T=2] ──────► (max(2, 2)+1 = 3)
4. Distributed Mutual Exclusion: Ricart-Agrawala Algorithm
When distributed nodes need to access a shared Critical Section (CS) without a central coordinator, the Ricart-Agrawala Algorithm achieves mutual exclusion using message timestamps:
- When a node wants to enter the Critical Section, it multicasts a
REQUEST(Timestamp, Node_ID)message to all other nodes. - When a node receives a request:
- If it is not in the CS and does not want the CS: It replies with
OK. - If it is currently in the CS: It queues the request.
- If it also wants to enter the CS: It compares timestamps. The request with the lowest timestamp wins; if timestamps are equal, the lower
Node_IDbreaks the tie. - The node enters the CS once it receives
OKfrom all other nodes.
Frequently Asked Questions (FAQ)
Q1: What is the CAP Theorem in distributed databases?
The CAP Theorem states that a distributed data store can simultaneously provide at most two of the following three guarantees: Consistency (C), Availability (A), and Partition Tolerance (P).
Q2: What is the purpose of Distributed Garbage Collection (DGC) in Java RMI?
DGC tracks remote object references across JVM boundaries using lease timers to reclaim memory when remote clients no longer reference an object.



