Question
Why is there a delay between the originalTimestamp and sentAt timestamp for events sent from Segment's mobile libraries?
Product
Segment
Environment
Segment Console
Answer
The delay between the originalTimestamp and sentAt timestamp occurs because Segment mobile libraries queue events on the device and send them in batches to optimize network usage and battery life. If a user closes their app before the queue is flushed, events remain stored and are sent the next time the app is opened. This batching behavior can result in events being delivered hours or days after they occur.
Additional Information
More information on how Segment calculates timestamps can be found here. Default batching occurs every 30 seconds or after 20 events have queued. There are several options that can be utilized to reduce these delays:
- All mobile libraries have a
flushAtandflushIntervalconfiguration option available to change these defaults. - You can call
flush()manually anytime to ensure an event is sent downstream. - Plugin architecture in the new mobile libraries allows for a background flush policy to be implemented to flush events when the app is being moved into the background.