Skip to main content
Version: Current

Timestamps - GenesisFlake

When you generate a database on the Genesis low-code platform, every table in the database is given a TIMESTAMP field. This contains a timestamp value that is generated automatically by GenesisFlake every time a change is made to the database. The TIMESTAMP field in GenesisFlake represents the creation time of a record, not the last modified time.

To create these values, GenesisFlake generates IDs in a similar manner to Twitter’s snowflake. It is able to generate these IDs without having to perform database-level synchronisation - which ensures high performance.

An ID includes:

  • a node number (which represents the node id within a Genesis cluster)
  • a sequence number (used to differentiate IDs generated within the same millisecond)

Timestamps are essential if you use Optimistic Concurrency.

Format

The GenesisFlake timestamp is made up of:

  • epoch time in milliseconds
  • node id
  • sequence id

The timestamp itself is stored in the most significant bits of a LONG variable, leaving the least significant bits to node id and sequence number.

A raw ID value looks like this, for example: 6626101958220449352.

You can extract the timestamp component using bitwise right-shift operations. For example:

The result in decimal corresponds to 1579785813861, which can be checked in https://www.epochconverter.com/

Finding the most recent change to a table

To find the most recent change to table in your database:

  1. Add an index on the TIMESTAMP field for the table.
  2. Perform a getRangeFromEnd for that index. This returns all the records, beginning with the most recent.
  3. Keep only the first record.