Logical Clock in Distributed System
Logical Clocks refer to implementing a protocol on all machines within your distributed system, so that the machines are able to maintain consistent ordering of events within some virtual timespan. A logical clock is a mechanism for capturing chronological and causal relationships in a distributed system. Distributed systems may have no physically synchronous global clock, so a logical clock allows global ordering on events from different processes in such systems. Example : Suppose, we have more than 10 PCs in a distributed system and every PC is doing it’s own work but then how we make them work together. There comes a solution to this i.e. LOGICAL CLOCK. Method-1: This means that if one PC has a time 2:00 pm then every PC should have the same time which is quite not possible. Not every clock can sync at one time. Then we can’t follow this method. Method-2: Taking the example into consideration, this means if we assign the first place as 1, second place as 2, third place as 3 and so on. Then we always know that the first place will always come first and then so on. Similarly, If we give each PC their individual number than it will be organized in a way that 1st PC will complete its process first and then second and so on. BUT, Timestamps will only work as long as they obey causality. What is causality ? Properties Derived from Happen Before Relationship –
If we go outside then we have made a full plan that at which place we have to go first, second and so on. We don’t go to second place at first and then the first place. We always maintain the procedure or an organization that is planned before. In a similar way, we should do the operations on our PCs one by one in an organized way.
To order events across process, try to sync clocks in one approach.
Another approach is to assign Timestamps to events.
Causality is fully based on HAPPEN BEFORE RELATIONSHIP.
If, TS(A) <TS(B) and TS(B) <TS(C), then TS(A) < TS(C)
a->b, this means that a is occurring before b and if there is any changes in a it will surely reflect on b.
This means that not every process occurs one by one, some processes are made to happen simultaneously i.e., A || B.


