ElixirConf EU 2026 in Krakow, Poland focuses on production Elixir patterns across distributed systems, Phoenix real-time features, and BEAM performance. UUID v7 sessions address the shift from binary UUID v4 to time-ordered identifiers in high-throughput OTP applications. See UUID in Elixir for implementation details.

Ecto schema with UUID v7

defmodule Shop.Orders.Order do
  use Ecto.Schema
  import Ecto.Changeset

  @primary_key {:id, :string, autogenerate: false}
  @foreign_key_type :string

  schema "orders" do
    field :customer_id, :string
    field :total,       :decimal
    field :status,      :string, default: "pending"
    timestamps()
  end

  def changeset(order, attrs) do
    order
    |> cast(attrs, [:customer_id, :total])
    |> validate_required([:customer_id, :total])
    |> put_uuid_v7()
  end

  defp put_uuid_v7(changeset) do
    case get_field(changeset, :id) do
      nil -> put_change(changeset, :id, Uniq.UUID.uuid7())
      _   -> changeset
    end
  end
end

Phoenix LiveView stream with UUID v7 ordering

defmodule ShopWeb.OrdersLive do
  use ShopWeb, :live_view
  alias Shop.Orders

  def mount(_params, _session, socket) do
    orders = Orders.list_recent(limit: 50)
    # UUID v7 IDs sort chronologically — stream maintains insertion order
    {:ok, stream(socket, :orders, orders)}
  end

  def handle_info({:new_order, order}, socket) do
    # Prepend or append based on UUID v7 sort
    {:noreply, stream_insert(socket, :orders, order, at: -1)}
  end
end

Cursor pagination with Ecto

defmodule Shop.Orders do
  import Ecto.Query
  alias Shop.Repo

  def list_orders(cursor \\ nil, limit \\ 20) do
    query =
      from o in Order,
        order_by: [asc: o.id],
        limit:    ^(limit + 1)

    query =
      case cursor do
        nil    -> query
        cursor -> from o in query, where: o.id > ^cursor
      end

    orders    = Repo.all(query)
    has_more  = length(orders) > limit
    items     = Enum.take(orders, limit)
    next_cursor = if has_more, do: List.last(items).id, else: nil
    {items, next_cursor}
  end
end

mix.exs dependency

defp deps do
  [
    {:uniq,    "~> 0.6"},
    {:phoenix, "~> 1.7"},
    {:ecto_sql, "~> 3.11"},
    {:postgrex, "~> 0.17"}
  ]
end

Further reading

External references

Frequently asked questions

How do I use UUID v7 as a primary key in Ecto?

Define your schema with @primary_key {:id, :string, autogenerate: false} and generate the ID in a changeset: change(changeset, id: Uniq.UUID.uuid7()) using the uniq hex package. Alternatively, use a custom Ecto.Type that calls Uniq.UUID.uuid7() on insert. See UUID in Elixir for the full guide.

Does Phoenix LiveView work with UUID v7 record IDs?

Yes. Phoenix LiveView uses record IDs in stream keys and DOM IDs. UUID v7 strings are valid DOM IDs (with a letter prefix if needed) and work as LiveView stream item keys. The time-ordered property means Enum.sort_by(&(&1.id)) returns records in creation order. See UUID v7 in Phoenix LiveView.

What is the uniq hex package?

uniq is an Elixir hex package implementing UUID v1, v4, v6, and v7 per RFC 9562. Call Uniq.UUID.uuid7() for a UUID v7 string. It also provides Uniq.UUID.to_raw(uuid) for 16-byte binary storage in PostgreSQL :uuid columns. See What is a UUID.