1

Currently, I'm developing an application based on spring boot. One of the requirements is that the application should be real-time and I need some kind of unique data structure based on InvertedRadixTree(not exactly this but data strucutre is using the tree to answer the queries). I developed an admin UI for crud operations. The number of cruds are not so much and basically will be done by OPs employees. the data structure that I developed is thread safe and is synchronized by database(which is mongodb) and since this is the only app using this database, I'm not worried about the other apps messing up with the data. The only problem that I have is that if we have multiple instances of this app, and one of them do some crud operations on mongodb; although the data structure of this instance will get updated, the other instance will not be updated. I created an scheduler to update the data structure from database every 12 hours, but I'm looking for another solution like sharing data structure between all the instances. I really appreciate every suggestions.

EDIT: After searching around, I found that updating the whole data structure doesn't take to much. I wrote some test cases and put around a million record of my class inside mongodb and fetched the whole collection. Fetching and data structure creation took less than a second. So I ended up using this method instead of using some sophisticated method for synchronizing memory and database.

Reza
  • 1,516
  • 14
  • 23
  • what about declaring the data-structure as static??? – Haseeb Anser Dec 01 '15 at 08:04
  • you could receive push updates when the db is updated : http://stackoverflow.com/questions/9691316/how-to-listen-for-changes-to-a-mongodb-collection, this would prevent you from polling it all the time. – Paul K. Dec 01 '15 at 08:37
  • @HaseebAnser: By instance I don't mean "Object" versus class. You can consider instance two different server/machine/computer running the same program! – Reza Dec 01 '15 at 15:01
  • @PaulK. Thank you. This is not what I'm looking for. Intersting idea though. – Reza Dec 01 '15 at 15:06
  • @HaseebAnser: Like when we have two different servers each has its own tomcat server and runs the same war file. – Reza Dec 01 '15 at 15:08

2 Answers2

0

One of the suggestion can be that you can use a shared database. Every time there is an update by any of the APP,It should be updated in the database.And every time you have to use the data you will have to load the fresh data from the database.This is the easiest way as far as i think ..!!!

Haseeb Anser
  • 494
  • 1
  • 5
  • 19
0

I would use something like redis http://redis.io/topics/pubsub , and listen to an event fired for the instance that make the change and use some local cache on every instance if the data is not frequently updated

dgofactory
  • 348
  • 5
  • 13