The approach that I have seen that seems to work best is to have a SQL db server with a single integral IDENTITY column to issue the ID's, which you need to do before actually even create the entity (when create the commands for example if you're using CQRS too). This approach is actually quite simple to do and support and only requires one additional table (or not even that) in your db. This is not an uncommon practice and relieves your bc from the responsibility of owning logic of ID generation (in certain case this can be quite useful).
CAUTION: as with all things in our software world this has a number of trade-offs:
- It can guarantee ordering but the sequence of id's may have gaps if a certain operation with one id fails and you retry your action. This is only important if you care about ordering the creation of your entities :)
- This impacts performance as you have a single bottleneck (honestly you need to have a really large traffic for this to be a noticeable problem so I would not consider this a big problem)
- It may be a security concern in certain contexts depending on how this id is used.
I have to say that all points above are quite niche and I don't expect to really be a problem.
For reference and more information about this practice you can read about Twitter's Snowflake project. Snowflake generated sequential guid-like 64-bit integral id's but a lot, if not all, of the principles still apply in this case. There are a lot of information and best practices about this practice in a lot of articles discussing Snowflake.
Regards,
Savvas