Instacart Kaushik Gopal Sep 12, 2016

Offline First: Introducing TrueTime for Swift and Android

Article Summary

Instacart shoppers were losing minutes in grocery store dead zones. The culprit? You can't trust device clocks when every second counts.

Instacart open sourced TrueTime, an NTP library for Swift and Android that solves a deceptively tricky problem: getting accurate time on mobile devices. This is part one of their offline-first architecture series.

Key Takeaways

Critical Insight

When you're promising one-hour delivery, you need millisecond precision that survives spotty networks and user clock tampering.

The real story is why Instacart needed this for their offline-first architecture (hint: batch processing comes next).

About This Article

Problem

Instacart's shopper app had trouble reliably timestamping critical order events. iOS and Android don't provide a way to get time that isn't affected by user timezone changes or clock drift, which can span several minutes.

Solution

Kaushik Gopal's team built TrueTime to solve this. It queries NTP servers once when the app starts, calculates the delta between device uptime and server response, then applies that offset to all subsequent time requests.

Impact

The open-source library lets Instacart guarantee millisecond-precision timestamps for one-hour delivery orders on both Android and iOS. The RxJava extension supports parallel UDP requests with automatic retry logic.