We have a database, where we insert data into table whenever we receive an order from our services.

We use auto_increment to generate the ID and assign the order with the same. This is usually same everywhere.

But the problem is, since this information is passed to third party vendors, they are able to trace, how many orders we are receiving per day. By sending a request in the early morning and sending another request in midnight and count the difference in the ID.

This is giving insight information of our services. Since it's bit complex system, we can't do complex operation that can randomise this.

My initial idea is to generate auto_increment numbers in bit random fashion way.


I guess it should be simple, as Mysql runs out of cache, generate next sequence by appending some random number.

How to achieve this without impacting the performance?

  • What information are you passing exactly? Only the IDs? If these vendors can send arbitrary queries to the database, they can always run SELECT * FROM Orders; or SELECT COUNT(*) FROM Orders WHERE Date >= CURRENT_DATE(); and get this info. – ypercubeᵀᴹ Jul 24 '14 at 7:31
  • May be you can try using UUID instead od Auto_Increment. – Abdul Manaf Jul 24 '14 at 7:55
  • @ypercube, they don't have access to database. I will send the order confirmation with the generated id. Since we do operations over 0.1 million every day, we can't use UUID too as it can be quite huge and our customer care will not be able to answer – Reddy Jul 24 '14 at 8:02
  • 3
    I see. So any of these vendors, can get a an idea about the size of the orders of a day by the IDs of their orders only. I think that adding a UUID column (and hiding the actual ID from vendors) might be your best option. The customer care will still be able to check things using a probably altered query (so by the UUID and not the ID). This will need only a new column and an index on it. And (I suppose you use InnoDB) you'll want to keep the clustered index on ID and all the other table's FKs untouched. – ypercubeᵀᴹ Jul 24 '14 at 8:07

Here is an overview of methods to generate random unique ids in mysql, by Rick James: http://forums.mysql.com/read.php?24,425424,425491

The overview is quite comprehensive, gives 5 different strategies, lists pros and cons for every one.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.