Postgres sequences can commit out-of-order
blog.sequinstream.com
blog.sequinstream.com
People throw Kafka or Event Hub at everything, but really, if you do not need to offload your DB for storage/access of massive amounts of events, you may not need them...
I have a lot of experience with this approach on MS SQL (https://github.com/vippsas/mssql-changefeed), interesting to see the same thing on postgres.
Hope databases gets these things built in (i.e., supported more directly) in the future.
-- If no locks are found, return the maximum possible bigint value
if max_seq is null then
return 9223372036854775807;
end if;
Would be a race here by returning a big number to the caller, then more data is written in between? Should instead check the current max sequence number before checking the locks?