ryanwinchester / uuidv7

UUIDv7 for Elixir (and Ecto)
MIT License
34 stars 3 forks source link

Considering replacing ETS usage. Ideas here (please share yours, too) #9

Open ryanwinchester opened 6 months ago

ryanwinchester commented 6 months ago

Share ideas on how to replace the ETS table.

Requirements:

  1. We need to be able to atomically increment a randomly-seeded 18-bit counter.
  2. Reset+reseed every time we have a different millisecond timestamp.
  3. Reset it to next millisecond at rollover.
  4. Not have it grow infinitely.

Arguments:

  1. current millisecond timestamp and
  2. a 17-bit random integer for a seed.

Current implementation:

We have an ETS table that has timestamps as the key, and updates a counter.

  defp update_counter(timestamp, seed) do
    :ets.update_counter(__MODULE__, timestamp, 1, {timestamp, seed})
  end

Once it hits the 18-bit threshold we then increment the millisecond timestamp key to avoid rollover.

We also delete old keys on a recurring interval.

ryanwinchester commented 6 months ago

Current idea I want to explore is to use a NIF.

NIF ideas to explore