Physical Time vs Logical Time in Distributed Systems
You'll learn why wall-clock time fails us in distributed systems and why we need a different notion of ordering events.
The Problem with Physical Clocks
In a distributed system, each node has its own physical clock (like the system time on your laptop). You might think: "Just timestamp each event and compare them!" But here's the catch: physical clocks drift. Even with Network Time Protocol (NTP) synchronization, clocks on different machines can be milliseconds—or even seconds—out of sync.
Imagine two nodes processing events:
- Node A timestamps an event at
10:00:00.100 - Node B timestamps an event at
10:00:00.095
Did A's event really happen after B's? Maybe... or maybe B's clock is just 10ms fast. You can't be certain which event actually occurred first, and this uncertainty breaks causality—the foundation of correct distributed behavior.
Enter Logical Time
Logical time abandons trying to measure "real" time and instead focuses on event ordering. It answers: "Did event X happen before event Y?" without caring about wall-clock timestamps.
Think of it like versioning in a collaborative document. You don't need to know the exact second each edit happened—you just need to know which edit came before which, so you can merge changes correctly.
Logical clocks (like Lamport timestamps or vector clocks, which you'll learn soon) use counters and message-passing rules to determine causality. They guarantee that if event A causally influenced event B, the logical clock reflects that ordering.
When to Use Each
Use physical time for: human-readable logs, metrics, TTLs, rough coordination.
Use logical time for: determining causality, ordering operations, detecting conflicts, ensuring correctness.
Key Takeaway: Physical clocks are unreliable across distributed nodes due to drift and synchronization limits; logical time provides consistent event ordering based on causality, not wall-clock measurements.