October 25, 2024
Chicago 12, Melborne City, USA
java

The most efficient way to check data existence in db with spring jdbc template


I’m working on a highload service in which I’m recieving batch messages from kafka (about 500 at once). Those messages represent entities in db. To simplify, lets imagine entity A like this:

create table A (
id varchar references B(id),
serial_num varchar,
is_actual boolean
)

Where a combination of id and serial num is unique.

So when the array of messages recieved from kafka – I’m parsing those messages to entities and then I need to check if such an entity already exists in table A by id and serial_num and if it is not, then I need to update all entities by id and set is_actual to false, otherwise do nothing. After updating – I need to insert new entity. So, for updating and inserting I am using Spring Jdbc Template butchUpdate() method. But how to check if the entities are exist in most efficient way? If I will check them one by one – then I’m losing the adventage of getting message batch from kafka.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video