Search code examples
c#amazon-web-servicestimewindows-serverntp

time difference 1 second between AWS (amazaon web service) and Microsoft server


There is a difference in 1 second between server (windows 2016 synchronized with time.windows.com) and third party web service (deployed on AWS - amazon web service).

The problem is: i send a request with a date parameter Date = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ") to TPS (third party service) and get a response with a date less than sent (difference up to 1 second). Date in request is a creation date of request and same in response, creation date of response.

request : "timestamp":"2018-10-24T01:33:12Z"

response : "timestamp":"2018-10-24T01:33:11.0000138Z"

Could someone explain the time difference ? and how to fix this issue correctly


Solution

  • Network latency, and different NTP servers between the 2 platforms could explain a 1s difference. You are likely using 2 different time references in your above setup. That alone could account for the drift.

    Certainly different apps or use cases would require more or less precision. 1 to 2 seconds could be unacceptable for some setups. In my experience 100ms sync precision/jitter can be achieved via normal NTP using the same reference clock.

    See https://serverfault.com/questions/724409/how-accurate-can-we-get-computer-clocks-synchronized-in-a-local-network-of-any-n for a good discussion on issues impacting NTP time sync precision.

    See also https://aws.amazon.com/blogs/aws/keeping-time-with-amazon-time-sync-service/ on how AWS manages their reference NTP clocks.

    For an overview of NTP Network Time Protocol see https://en.m.wikipedia.org/wiki/Network_Time_Protocol