Database / Google Spanner Database Interview questions
Why do we use commit timestamps in Spanner tables?
A commit timestamp column, declared with OPTIONS (allow_commit_timestamp=true), lets Spanner fill in the exact TrueTime-derived commit time of the transaction automatically, rather than the application computing its own "updated at" value.
CREATE TABLE AuditLog ( Id STRING(36) NOT NULL, ChangedAt TIMESTAMP OPTIONS (allow_commit_timestamp=true) ) PRIMARY KEY (Id);
This matters because application-side clocks aren't synchronized the way TrueTime is, so two servers writing "now" independently could disagree about ordering. Using the Spanner-assigned commit timestamp instead guarantees the value is externally consistent with every other transaction in the database, which makes commit timestamp columns the standard building block for change tracking, audit trails, and change streams.
More Related questions...