• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Frits Walraven
  • Himai Minh

Question on multiple JVM synchronization and multiple database intances

Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was asked this question in a recent interview which I could not answer so was hoping to get some answers. I might not have got the question correctly maybe because I lack the understanding of the concepts like - database cluster, multiple JVM synchronization, load balancing. I will try my best to recall the question. Here it is:

1. There are two instances of an application (let's say A1 & A2) running on two different JVMs and two instances of a similar database (D1 & D2).
2. The application instances will try to insert a record in a DB instance. What I mean is that A1 will insert in D1 and A2 will insert in D2.
3. A server load balancer decides which of these app instances will run at a given time and this load balancer is a typical server load balancer not under our control.

Problem : At a given time only on of these application instances should be allowed to do a insert in a corresponding DB. This is required to avoid both the app instances to run at the same time and insert the same record in its database instances. How to achieve this ?

Wrong answers I gave:
1. Synchronize the code (Not possible because the app are running on different JVMs)
2. Try some database lock (Not possible because these two database instances can't talk to each other)

Hope I have explained the problem clearly. I have also attached an ugly looking architecture image. Thanks in advance for all replies.
[Thumbnail for Problem.png]
Posts: 9
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are confusions.
  • Who receives the input; load balancer or both the instance?
  • If load balancer receives it and delegates to one of the instance, then is not the whole question becomes pointless?
  • If both the instance receives the input, then what the load balancer is for?

  • In a typical clustered environment the request actually comes to the load balancer and gets delegated to a specific instance bearing minimal load at current time. Therefore if a load balancer is in place, then the whole given scenario becomes useless, since the situation can never occur!!
    If there is no load balancer and request comes to both the instances, only then the question makes sense. In such a scenario, the best choice would be to use JMX communication between two instances to sync up and decide who will handle the persistence operation.

    You showed up just in time for the waffles! And this tiny ad:
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
      Bookmark Topic Watch Topic
    • New Topic