I'm on a project asking for high performances... And I was told to use as a few database calls as possible, and to use more objects in the JVM memory. Right.
So... It didn't shock me at first, but now I'm questioning the approach.
How can I know which is best ?
On the one hand I would have :
- static Map <id1, id2>
- static Map <id2, ObjectX>
Object X
- id2
- map <id1, ObjectY>
Object Y
- id1
So basically, this data structure would help me to get an ObjectY from an id1. And I would be able to send back the whole ObjectX as well when needed.
You gotta know that the structure is filled by a service call (A). Then, updates to objects ObjectY can happen through another service (B). Finally, another service can send back an ObjectX (C). Which makes three services using the data.
On the other hand, I could have :
- db table for ObjectY T1
- db join table associating id1s and id2s T2
- db table for Object X T3
Service A would make an insert in the tables. Service B would make an update in table T1 Service C would make a join between T2 and T1 to get all ObjectY objects for an ObjectX
In my opinion, the db version is more flexible... I am unsure about the performances, but I would say the db version shouldn't be slower than the "memory" version. Finally, hasn't the "memory" version got some risks ?
I hope it seems obvious to some of you I should choose one version and why... I'm hoping this not to be a debate. I'm looking for ways to know what's quicker...