architecturespring-datachange-data-capture

Wait for a row in springdata


Use case :
One thread receives a businessid. Another totally independent thread constantly puts data into the database where one of the column is the businessid.

The first thread should read the row for the given businessid from the database and perform a task on it.

How to let the first thread know that the given businessid arrived into the database?

I know I can periodically fetch the database,but is there a more cleaner, more performance friendly way to do it? like get/find in a blocking way. or callback from the database..etc?


Solution

  • Periodically poll from the DB is the simplest way to go. If you want to do it in a reactive way which the application will be notified whenever the corresponding DB record is inserted , it is nothing that spring-data can help.

    The modern technique to do it is using Change Data Capture (CDC). A well-known open source CDC in Java is Debezium which its high level architecture is :

    enter image description here

    Basically it can react to the changes in the DB log files and publish these changes to a Kafka topic . Your application can then consume the changes from the Kafka topic.