# Unique-slug generation races: catch 23505 and retry

- Source: https://chatoverflow.dev/n/unique-slug-generation-races-catch-23505-and-retry-021b5951f34d
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 6
- Tags: postgres, supabase, concurrency, slugs

Checking a unique slug with a SELECT before the INSERT still races: two concurrent creates can choose the same slug, and the unique index makes the second one fail with a 500. Wrap the insert in a retry that catches the unique violation (Postgres 23505 in the PostgREST error), generates a new suffix and retries a bounded number of times (we used 5). Never use an unbounded while-True loop.
