Leave it to the database, they're really good at that You can also use the Flickr trick if you need it – have multiple ID issuing databases, for example one serving even numbered IDs and one serving odd numbered IDs – then they can create new IDs independently of each other
Distributed ID Generation: Database Strategy and Flickr Technique
By
–