Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Amazon generate its order number?

Note: I have already read through older questions like What is the best format for a customer number, order number? , however my question is a little more specific.

Generating pseudo-random numbers encounter the "birthday problem" before long. For example, if I am using a 27-bit field for my order number, after 15000 entries, the chances of collision increase to 50%.

I am wondering whether large ecommerce businesses like Amazon generates its order number in any other way - for example :

  • pre-generate the entire set and pick from them randomly (a few hundred GB of database)
  • Use lexicographical "next_permutation" starting from a particular seed number
  • MD5 or SHA-1 hash of the date, user-id, etc parameters, truncated to 14 digits
  • etc

All I want is a non-repeating integer (doesnt need to be very random except to obfuscate total number of orders) of a certain width. Any ideas on how this can be achieved ?

like image 928
Sandeep Avatar asked Aug 22 '12 04:08

Sandeep


1 Answers

Suggest starting with the date in reverse format then starting at 1, followed by a check (or random) digit. If you are likely to never exceed 100 orders per day you need add two digits plus a check/random digit.

The year need include only the final two digits, possibly only the final digit, depending on how long you keep records of orders: 7 years or so is usually enough, meaning the records from 2009 (beginning with 9) could be deleted during 2018 in preparation to use the order numbers again in 2019. You could use mmdd for the next 4 digits, or simply number the days through the year and use just 3 digits - it depends how human-friendly you want the number to be. It's also possible just to omit the day of the month and restart the sequential numbers at the start of each month, rather than every day.

Today is 2 Nov 2017, let's suppose this is order no 16 today, your order no would be 71102168 (where the 8 is a check digit or random digit). If you're likely to have up to, but not exceeding a thousand, you'll need an extra digit, thus: 711020168. To avoid limiting yourself the number of digits, you might prefer to use a hyphen: 71102-168 … you could include another hyphen before the check/random digit if you wish: 71102-16-8.

If you have several areas dealing with orders, you may wish to include a depot number, perhaps at the beginning or after the date, allowing you to use the sequence numbers at each depot - eg depot 5 might be: 5-71102-168, 71102-5-168 or 711025168. Again, if you don't use hyphens, you'll need to assess whether you need up to ten, a hundred or a thousand (etc) possible depot numbers. I hope this helps!

like image 139
ColinT Avatar answered Dec 31 '22 20:12

ColinT