liveBook · Manning

Timestamp

As explained in ScyllaDB in Action

A timestamp is a value representing the time assigned to a database write or cell value for conflict resolution.

A timestamp represents a specific moment in time. ScyllaDB uses TIMESTAMP for date-and-time values, storing a UTC-based instant as milliseconds since the Unix epoch. Separately, each non-primary-key cell receives a microsecond-precision write timestamp used for conflict resolution. section 4.3 section 6.1.2

Choose the timestamp-related representation that matches the requirement:

  • Use TIMESTAMP when both the date and time identify the value; use DATE when only a date matters. section 4.3.3
  • Use TIME for a time without a date and DURATION for a length of time. section 4.3
  • Treat the latest write timestamp as decisive: ScyllaDB converges on the value with the highest timestamp, regardless of replica count. section 6.1.2
  • Inspect a cell’s write timestamp with WRITETIME and override the query timestamp with USING TIMESTAMP. section 6.1.2

Concurrent author edits

Edith updates an author bio at QUORUM, then Emily writes a different bio at ONE milliseconds later. Emily’s higher timestamp wins and eventually replicates to all replicas. A deliberately old USING TIMESTAMP value, such as 1, cannot replace the newer bio. section 6.1.2

Table 4.6 Table times
Type
Stored as
Acceptable forms
TIMESTAMP
BIGINT representing the number of milliseconds since the Unix epoch (1970-01-01 00:00:00+0000)
1687654894759, '2023-06-24 21:02:00+0000' and other ISO-8601 compliant timestamps
DATE
32-bit unsigned integer representing the number of days since the Unix epoch (1970-01-01), with the epoch in the center of the range (2^31)
'2023-06-24', 641
TIME
64-bit signed integer representing the number of nanoseconds since midnight
'21:07:12.123' with either second, millisecond, microsecond, or nanosecond precision, 76032123000
DURATION
Three integers representing the number of months, the number of days, and the number of nanoseconds
1y4mo3w5d3h6m19s400ms20us141ns or any combination of the units

Compare TIMESTAMP, DATE, TIME, and DURATION by stored representation and accepted input forms. section 4.3

How ScyllaDB in Action covers it

How deep it goes
Explains representations, type selection, cell-level conflict resolution, inspection, and manual timestamp overrides.
Examples
Demonstrates timestamps through article-date type selection and competing edits to an author bio.
What it assumes
Assumes basic ScyllaDB columns and writes while distinguishing dates, times, durations, and cell values.
What you can do after
Evaluate which time type fits a field and diagnose write conflicts with WRITETIME and USING TIMESTAMP.
How it connects
Connects TIMESTAMP with DATE, TIME, DURATION, WRITETIME, last-write-wins, conditional updates, and distributed locking.

Also explained in

Compare how 10 books explain timestamp →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ScyllaDB in Action. The section links point to the parts of the book it draws on.