Time in Distributed Systems
Time in distributed systems: challenges and concepts.
Time in distributed systems is a mechanism used to order events and reason about causality across multiple machines that do not share a global clock. There are two fundamental types of time: 1. Physical Time (Wall Clock Time) 2. Logical Time (Event Ordering Time)
Physical Time (Wall Clock Time) Physical time is the actual clock time shown on a machine (e.g., 10:30:01 AM). Each server maintains its own physical clock. To synchronize clocks, systems use: Network Time Protocol (NTP) Precision Time Protocol (PTP)
Logical Time (Event Ordering Time) Logical time does not measure real-world time. It measures order of events.
Understand Time
When we move from a single machine to multiple machines: There is no global clock Each server has its own time Network delays exist Clocks drift Events happen concurrently
machine1: 10:00:05
machine2: 09:59:58
User Name: Alex User Send Request: Machine 1: Alicia: 10:00:05 User Send Request: Machine 2: Alice: 09:59:58 - (it is 7 seconds behind.) DB HISTORY: id ,userId ,name , time 1 ,123 ,Alex , 07:00:03 2 ,123 ,Alicia , 10:00:05 - TIME ERROR 3 ,123 ,Alice , 09:59:58 - TIME ERROR Select * from user_name_history where userId = 123 order by time desc limit 1;
LOAD BALANCER
event A > Event B