Question

This is more of a conceptual question but answers specific to opensource products like (JBoss, etc) are also welcome.

If my enterprise app needs to scale and I want to choose the scale-out model (instead of the scale-up) model, how would the multiple app server instances preserve the singleton semantics of a piece of code/data?

Example: Let's say, I have an ID-generation class whose logic demands that it be instantiated as a singleton. This class may or may not talk to the underlying database. Now, how would I ensure that the singleton semantics of this class are maintained when scaling out?

Secondly, is there a book or an online resource that both lists such conceptual issues and suggests solutions?

EDIT: In general, how would one handle generic, application state in the app server layer to allow the application to scale out? What design patterns, software components/products, etc I should be exploring further?

Was it helpful?

Solution

The further you scale out, the less able you are going to be to manage global static atomically. In other words, if you have 100 servers that need to share state (knowing which ID is next in an ID generating singleton class), then there is no technology I know of that will quickly and atomically get that ID for you.

Data has to travel from machine to machine in regards to the ID generation.

There are a few options I can think of for the scenario you mentioned:

  1. Wait for all machines to catch up/sync before accepting a new ID. You could generate the ID locally and then check that it's good across other machines - or - run a job to get the next ID across all machines (think map/reduce).

  2. Think sharding. With sharding you can generate IDs "locally" and be guaranteed to have uniqueness. So if you had 100 machines, machines 1-10 are for users in California, machines 11-20 are for users in New York, etc. Picking a sharding key can be tough.

  3. Start looking to messaging systems. You would create/modify your object locally on a machine and then send the result to a service bus/messaging system and the other machines subscribe to a topic/queue and can get the object and process it.

  4. Pick a horizontally scalable database to manage objects. They've already solved the issues of syncing and replication.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top