Timestamp Values
When writing an application it is often useful to store a timestamp in a document. This can be used to calculate how much time has elapsed since it was created, or to construct a query that syncs documents within a certain time range.
In a traditional database with a single server there is only one clock so all the timestamps in the database are perfectly accurate relative to each other. In a Ditto mesh, different devices may be responsible for inserting different documents and using their own system clocks to fill in the timestamp field. This can result in receiving a document where the timestamp appears to be in the future, or documents that were created simultaneously in the real world have timestamps seconds apart.
Developers using timestamps in documents should be aware of the potential for time skew and handle situations that might seem “impossible”.
Even if a device has clock synchronization turned on then it may not be accurate enough. Ditto engineers have observed that iOS is typically within 100 ms of the correct time but Android devices can be several seconds fast or slow.
If an app requires more precise timing information then each device should query an Internet time server directly to calculate a correction, which can continue to be applied if the Internet becomes unavailable. NTP libraries are available for many platforms.