python python-datetime distributed-system
Updated Sun, 25 Sep 2022 03:38:07 GMT

Get timestamps with the same time_zone from all nodes in distributed system with Python

I am building a mechanism to store information with the timestamp in a distributed system. Assuming that the information from all nodes in a distributed system will be merged together and sorted according to timestamp, how to make sure that all the timestamps from all systems refer to the same time_zone in Python?

From my research, time.time() returns the time since Epoch, but it might return different results depending on the platform:

Does Python's time.time() return a timestamp in UTC?

Another solution that comes to my mind is to use datetime.utcnow() from datetime package. If I use datetime.utcnow() in all nodes, from my understanding all nodes will be using the same time_zone (UTC), hence the timestamps between all the nodes will be in sync. Can anyone confirm if I am correct in my logic?


If you want synchronize data with time, System time is not good idea for distributed systems. In distributed systems, system time is unreliable. There are many different scenarios where a simple failure. Example scenarios:

  • Someone can change local time on machine(or accidentally)
  • Out-of-date machine joining a cluster
  • synchronized clocks drifting at slightly different rates

That can cause not-traceable anomalies. NTP can help to you. You can synchronize times with this protocol. These strategies named Global Clock. It is not easy for implement and increase latency.

As far as I know Cassandra is using NTP for synchronize data.