We are building order processing system. We have a cluster of processing servers. We need to assign readable numbers to the orders (e.g. ORD-000001, ORD-000002).
Main problem that this is hard for us to implement system wide lock. I am thinking about schemas with lock expiration. But everything comes in mind still have bottlenecks.
We are approaching DDD, so direct access to database is hard. We are using NHibernate. And we use UnitOfWork.
Pls, help with some ideas. Every idea will be valuable. Any links to something to read on topic?
I want to stress, that I need sequential numbers. And so cannot use hi/low algorithms. At this time I am ivestigating scenario when
- I assign "probably good number";
- Push it to database;
- If fail, try to assign another "probably good number";
- If success, commit;
But I cannot find goot technology for it.
Are you trying to make sure all the orders have unique numbers, but without having a central location that coordinates the number distribution?
Here are two options for you.
Let's say you expect to have, at most, ten servers in any realistic period of time. Have each server hand out sequential numbers of the form ORD-XXXXXN. N is the number of the server. So server 0 hands out ORD-000000, ORD-000010, ORD-000020, etc. Server 6 hands out ORD-000006, ORD-000016, ORD-000026, etc.
Hand out blocks of numbers, 10000 at a time. Each server uses up all numbers in a block before retrieving more from a little server running in the background somewhere. The little server just runs through all the blocks, one by one, passing them out one at a time. The first block to be handed out is 0-9999, the second is 10000-19999, the third is 20000-29999, etc.