TrueTime API in Spanner

Learn about the TrueTime API methods and how it ensures external consistency.

TrueTime is a highly available distributed clock service. With TrueTime, applications can produce timestamps that increase monotonically. For example, if the generation of the timestamp TT ends before that of the timestamp TT' begins, then the resultant timestamp TT'will be bigger than the previous timestamp TT (with in an error bound). This is guaranteed for all servers and at any given time.

Spanner assigns timestamps to each transaction using the TrueTime API. The timestamp is the exact time Spanner considered the transaction to commit. Spanner's multi-version concurrency control guarantees the ordering of transactions on timestamps. It allows clients to execute consistent reads over the database, even when spread across different cloud regions, without blocking writes.

Let's dive into the details of the TrueTime API.

TrueTime API methods

As per Spanner's published paperCorbett, James C., Jeffrey Dean, Michael Epstein, Andrew Fikes, Christopher Frost, Jeffrey John Furman, Sanjay Ghemawat et al. "Spanner: Google’s globally distributed database." ACM Transactions on Computer Systems (TOCS) 31, no. 3 (2013): 1-22., the methods that the TrueTime API allows are as follows:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.