Time and clocks in Distributed System

Migo·2024년 12월 21일
0

Distributed system

목록 보기
1/12

Problem

Distributed system is Partial failure + unbounded latency
for both, we have zero control over it.

To deal with the problem, "time" and "clocks" are suggested in computing.

What would they mean by the way?

Clocks

Clocks are to mark a particular point in time. For example, "Migo starts writing this post at 7:49 GST." In this sense, timeout is duration or intervals of time.

However, human-friendly time-of-day clocks are not suitable for a distributed system because they require synchronization with a network time protocol(NTP) and are bad for measuring duration or intervals of time.

Why time-of-day clocks are bad?

1) Time-of-day time can jump back and forth either due to daylight saving time.

2) we may need more find-grained resolution to prevent specific races. But that's also OS-specific. (Imagine how horrible it would be when some nodes in the system are spun up in Windows and others on Linux and they have different resolutions)

If you are curious about what would happen if you use something like "Utc.Now()" all the time and how it can introduce bugs, check out the blog from CloudFlare

What about monotonic clocks?

So perhaps monotonic clocks like Unix timestamps are recommended?

Well, it is absolutely good for marking duration or interval, it doesn't allow for marking a point in time like "now it's 8:16 GST".

Simply put, we don't have a good way of achieving both marking points in time and duration with "physical clocks".

We need a different notion of the clock in a distributed system called a "logical clock."

Logical clocks

To be fair, logical clocks don't measure time of day and they don't measure elapsed time either. They instead measure the order of events.

What it cares is which event happened before another.

Suppose A happened before B.
A->B

What does this tell me about causality?

  • A could have caused B
  • B could not have caused A.

Things that happens-before reasoning is good for:

  • Debugging
  • Designing systems
    • if you can design the system in a way that if you know that event A happened before B, then your system will never allow users to observe event B before an event A.
profile
Dude with existential crisis

1개의 댓글

comment-user-thumbnail
2025년 7월 9일

Migo님, 분산 시스템에서 시간과 시계에 대한 흥미로운 글을 공유해 주셔서 감사합니다! 실시간 시계와 단조 시계에 대한 당신의 언급은 정말 중요합니다. 추가로, 시간과 기간을 계산하는 데 유용한 도구를 찾고 있다면 time calculator를 참고해 보세요. 분산 시스템에서 시간을 보다 효율적으로 관리하는 데 도움이 될 수 있습니다!

답글 달기