We have several disparate systems. These systems assign ORDER numbers. Basically, these are sequential numbers. They are NOT database ID numbers. These order numbers are like "A01457" or "Z4T456", etc. The problem is that each application issues its own order number and obviously order numbers can (and are) duplicated. Business has grown and now management want's the numbers to be unique across all systems because they want to roll orders up to a warehouse server.

The requirement is to develop an autonomous application (web service) that will accept simultaneous requests for an order number. The new application will generate and issue a unique order number to each request. Generating the order number is not the problem.

The problem is how to ensure that the order numbers are issued sequentially during multiple simultaneous requests?

What is the best practice for this type of implementation?

We prefer to use apache + php.

  • 7
    Presumably each system generates order numbers that are unique to that system. Why not prefix each with a couple of characters that identify the source system? You could probably manage those manually without building a single point of failure Order Number Generator. – Dan Pichelman Aug 12 '15 at 17:26
  • If you end up going the single point of failure ONG route as mentioned above, I would recommend staying away from message queuing as you become responsible for synchronization and order of messages. It may be as easy as creating a small service that has a lock or semaphore around a critical section of code where a "last id" variable is updated and its value returned? – moarboilerplate Aug 12 '15 at 17:59
  • 3
    To ensure a unique number, all you have to do is grab the primary key from the order numbers table in the database of your new web service, assuming it is an "autoincrement" type of field. But I'm with @Dan; just prefix your numbers and avoid the web service entirely. – Robert Harvey Aug 12 '15 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.