ScyllaDB University Live | Free Virtual Training Event
Learn more
ScyllaDB Documentation Logo Documentation
  • Server
  • Cloud
  • Tools
    • ScyllaDB Manager
    • ScyllaDB Monitoring Stack
    • ScyllaDB Operator
  • Drivers
    • CQL Drivers
    • DynamoDB Drivers
  • Resources
    • ScyllaDB University
    • Community Forum
    • Tutorials
Download
ScyllaDB Docs ScyllaDB C# driver Features Query timestamps

Query timestamps¶

In Apache Cassandra, each mutation has a microsecond-precision timestamp, which is used to order operations relative to each other.

The timestamp can be provided by the client or assigned server-side based on the time the server processes the request.

Letting the server assign the timestamp can be a problem when the order of the writes matter: with unlucky timing (different coordinators, network latency, etc.), two successive requests from the same client might be processed in a different order server-side, and end up with out-of-order timestamps.

Client-side generation¶

Using a timestamp generator¶

When using Apache Cassandra 2.1+ or DataStax Enterprise 4.7+, it’s possible to send the operation timestamp in the request. Starting from version 3.3 of the C# driver, the driver uses AtomicMonotonicTimestampGenerator by default to generate the request timestamps.

You can provide a different generator when building the ICluster instance:

var cluster = Cluster.Builder()
                     .WithTimestampGenerator(generator)
                     .AddContactPoint("host1")
                     .Build()

To implement a custom timestamp generator, you must implement ITimestampGenerator interface.

In addition, you can also set the default timestamp on a per-execution basis in the query options using the IStatement.SetTimestamp() method.

Accuracy¶

The driver provides 2 built-in implementations:

  • AtomicMonotonicTimestampGenerator that uses DateTime.UtcNow.Ticks to generate timestamps. The precision of UtcNow is system dependent and unspecified, which in summary can be around 15.6ms.

  • AtomicMonotonicWinApiTimestampGenerator that uses Win API’s GetSystemTimeAsFileTime() to generate timestamps. This method call is only available when running on Windows 8+ / Windows Server 2012+ and according to the documentation, the precision is higher than 1us.

Monotonicity¶

AtomicMononoticTimestampGenerator and AtomicMonotonicWinApiTimestampGenerator implementations also guarantee that the returned timestamps will always be monotonically increasing, even if multiple updates happen under the same millisecond.

Note that to guarantee such monotonicity, if more than one thousand timestamps are generated within the same millisecond, or in the event of a system clock skew, the implementation might return timestamps that drift out into the future. When this happens, the built-in generator logs a periodic warning message. See their non-default constructors for ways to control the warning interval.

Provide the timestamp in the query¶

Alternatively, if you are using a lower server version, you can explicitly provide the timestamp in your CQL query:

session.Execute("INSERT INTO my_table (c1, c2) VALUES (1, 1) USING TIMESTAMP 1482156745633040");

Was this page helpful?

PREVIOUS
Parameterized queries
NEXT
Query warnings
  • Create an issue
  • Edit this page

On this page

  • Query timestamps
    • Client-side generation
      • Using a timestamp generator
        • Accuracy
        • Monotonicity
      • Provide the timestamp in the query
ScyllaDB C# driver
  • master
    • master
  • Features
    • Address resolution
    • Authentication and Authorization
    • Automatic failover
    • Column Encryption
    • Driver components
      • ADO.NET
      • Core component
        • Statements
          • Batch statements
          • Per-query keyspace
          • Prepared statements
          • Simple statements
      • Linq component
        • Batch statements with LINQ
      • Mapper component
        • Batch statements with the Mapper
    • Connection heartbeat
    • Connection pooling
    • CQL data types to C# types
      • Date and time representation
      • Nulls and unset
    • Execution Profiles
    • Graph support
    • Cluster and schema metadata
    • Metrics
      • App.Metrics Provider
      • List of metrics
    • Native protocol
    • OpenTelemetry
    • Result paging
    • Parameterized queries
    • Query timestamps
    • Query warnings
    • Request Tracker
    • Routing queries
    • Speculative query execution
    • TLS/SSL
    • Tuning policies
    • User-defined functions and aggregates
    • User-defined types
    • Vector support
  • FAQ
  • Upgrade Guide
  • Examples
  • API Reference
Docs Tutorials University Contact Us About Us
© 2025 ScyllaDB | Terms of Service | Privacy Policy | ScyllaDB, and ScyllaDB Cloud, are registered trademarks of ScyllaDB, Inc.
Last updated on 01 Aug 2025.
Powered by Sphinx 7.4.7 & ScyllaDB Theme 1.8.7
Ask AI