• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to generate unique reference number with clustering without DB  RSS feed

 
Ramy Nady
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dears ,

At our banking application , there is a requirements to send unique reference number for some payment transaction.
How can I do this at Prod while we have three app servers and we don't have DB at our end (front end site)?

Thanks in advance.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not much information to go on, but the first thing that comes to mind is using milliseconds as part of the number. You could create a utility class and synchronize the method that generates the millisecond part it so only one server can call it at a time.

[edit] It just so happens that there is a good discussion on synchronization going on here.
 
Ramy Nady
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ,

You could create a utility class and synchronize the method that generates the millisecond part it so only one server can call it at a time.


Can you please explain how can I implement this on our environment with three servers ?
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you need a unique reference number.

What are the constraints for this number? Do they have to be in a specific order? Unique forever? Are there any size constraints you have to deal with?
How many are being generated per day? per hour? per minute?

One thing you could do is model it off of Oracle Sequences.

Have one central service which hands out "Unique identifiers"
All three of your front end servers go to this service to get their identifiers.
You could quite easily batch this so that your front end retrieves a set of unique identifiers - i.e. give me 100 identifiers, and I'll come back for more when I've used them up.
 
Tim Holloway
Bartender
Posts: 18716
71
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The industry standard unique reference number is the UUID/GUID, famed for being used for things like Windows access rule IDs, Windows OLE interface IDs and in a whole bunch of places in the Linux file and device systems.

There's a small difference between UUID and GUID, but for practical purposes we can use the terms interchangeably, so I'll use UUID.

A GUID was once described as a hash value whose probability of being generated by 2 different generation attempts has roughly the same odds of all the atoms in an area of space spontaneously flying together to form a small walnut. And yes, there are actual odds on that.

To obtain a truly unique ID you either need a reference server that tracks the IDs as they are handed out or you need a generation algorithm that can generate truly unique numbers. Or you need a generation algorithm that can generate "sufficiently unique" numbers. Which is what UUIDs are. They're basically hash codes designed to be virtually impossible to collide.

An identifier generated solely off a high-resolution clock is good, but inevitably will generate hash collisions. The UUID algorithm avoids that by using additional inputs, such as the MAC address of the generating computer. Since every MAC address must be unique - they consist basically of vendor ID codes concatenated with product serial IDs - they make a good basis.

Now the downside of UUIDs is that they're fairly long numbers. And their very unlikelihood of collision makes them poor choices for database keys, since you aren't likely to be able to generate an effective hash index for them. But the generator algorithm comes as part of the basic JDK class package set and often as an OS service as well.

One thing I would note, however, is that when you're generating unique transaction IDs, not only is is useful to have shorter values (imagine someone reading back a 100-bit hexadecimal code to you over the phone!), but that serial IDs will index better. So it's worth getting them from a central service that is able to work with a backend database or equivalent key state engine. You don't need full database access to request an ID. Just a web service call would do.
 
prasad guna
Ranch Hand
Posts: 46
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tim

Yes correct logic is good, but in a way there is a only one app server with different cluster, how we achieve because i faced the duplicates for this scenario. I fixed but i knew that's not a good way. if any other ways to handle this.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!