Actually serial/bigserial
create a sequence underneath and use that to generate unique ids.
Sequences do generate unique values even in distributed systems.
You also need to use caching for better performance which lowers number of rpcs to generate new values: https://docs.yugabyte.com/latest/api/ysql/commands/ddl_create_sequence/#cache
The uniqueness is enforced on the database side by a primary-key, unique-index, constraint. In this case it's also better for the id column to be the primary key.
So, use BIGINT
column with a sequence with a big cache, and make the id
a primary key.