A cached batch of ids that lowers but does not close the gap risk.

Postgres sequences hand out numbers with a cache

A sequence answers one number at a time under a lock, so caching turns many small locked calls into occasional large jumps. That single decision — correctness through a short lock, speed through batching — explains every sequence surprise: gaps after restarts, interleaved ids under concurrency, missing numbers in audit-sensitive tables. None of it is a bug; all of it follows from treating the sequence as a fast unique-number dispenser rather than an odometer. ...

August 2, 2027 · 4 min · XB Field Notes