Reputation: 5976
Recently encountered this interview question and wasn't sure about the answer:
In a synchronous request from a browser, how do you get results if you have to access two different databases?
I feel as if the answer will have something to do with Hibernate and the Spring Framework, but I don't have a ton of experience with either.
Upvotes: 0
Views: 193
Reputation: 20520
I'm not sure I see the complexity here. If it's a synchronous request then you need to find the result as quickly as possible and send it back. So you
The only optimisation possible, as far as I can see, is that if the query you're sending to B is independent of the result from A, then you should do (1) and (2) concurrently (in separate threads).
Even if they're not independent, you might still be able to optimise to some extent. For instance, if you're retrieving a boolean from A, you might be able to do this concurrently with two queries to B, one that will be useful if A returns true, and one that will be useful if it returns false. This might still be quicker than waiting for the result from A, especially if B is being accessed over a faster network link.
If this is an interview question, and it's that generic in terms of implementation, I certainly wouldn't mention Hibernate and Spring as part of the solution.
Upvotes: 1