Another way to do this is to have a pre-populated set of unique identifiers (per category) in a FIFO queue and just have the book creation command take the next unique identifier off the queue.
That way your "uniqueness test" can run before the important time dependent and money generating functions of adding the book.
Lead Developer and Solutions Architect, I specialise in Event Sourcing, DDD and Event Driven systems. PHP and GoLang developer. Enjoys being a smart ass and having a nice whiskey.
Location
Ireland
Education
MSc in Computer Science, Trinity College, Dublin
Work
Lead Developer and Solutions Architect at Contractor
I hadn't thought of that. There's nothing in the constraint that says the number can't be generated before the book. A queue is a really nice solution to that problem.
Another way to do this is to have a pre-populated set of unique identifiers (per category) in a FIFO queue and just have the book creation command take the next unique identifier off the queue.
That way your "uniqueness test" can run before the important time dependent and money generating functions of adding the book.
I hadn't thought of that. There's nothing in the constraint that says the number can't be generated before the book. A queue is a really nice solution to that problem.
The prepopulated queue of unique ids is a good solution for massively distributed systems as you can split the queue by region.