Firebase Realtime Database offline persistence loses write timestamps during concurrent client updates
0 reputation · 13 Jun 2021, 06:59 UTC
0 reputation · 13 Jun 2021, 06:59 UTC
The goal is to understand whether locally queued writes retain their original client‑generated timestamps when multiple clients update the same location while offline and later reconnect.
When network connectivity is lost, the SDK persists each write in an offline queue. Upon reconnection, the server reconciles these queued operations. It is unclear whether the SDK preserves the timestamp supplied by the client’s set() or transaction call, or if it replaces it with a server‑assigned time, potentially altering the expected order of concurrent updates.
Does the Firebase Realtime Database SDK retain the original client‑generated timestamp when persisting writes offline and reconciling after network loss? How does concurrent write conflict resolution interact with timestamp preservation? Are there SDK methods or configuration options that can force client timestamp retention during offline sync?
35275 reputation · 13 Jun 2021, 12:31 UTC
When a client writes a literal numeric timestamp while offline, the Realtime Database SDK stores that exact value in the local write cache and sends it unchanged to the server when connectivity is restored. The original timestamp is therefore preserved.
When the write uses ServerValue.TIMESTAMP, the placeholder is only replaced with the server‑assigned value at the moment the operation reaches the server. The client‑side placeholder is not kept in the offline queue.
ServerValue.TIMESTAMP, the server’s generated time becomes the authoritative value used for ordering.There is no flag or configuration that forces the SDK to keep a ServerValue.TIMESTAMP placeholder during offline sync. The only way to guarantee a client‑generated value survives is to write the numeric timestamp directly (e.g., Date.now()) instead of the placeholder.
firebase.database().setPersistenceEnabled(true) (JavaScript) or the equivalent in Android/iOS.ref.set(Date.now()).ref.set(firebase.database.ServerValue.TIMESTAMP); after reconnection the value will be the server timestamp, not the placeholder.To tailor a more precise recommendation, could you confirm whether you are currently writing numeric timestamps or using ServerValue.TIMESTAMP in your application?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.