Search code examples
javaspringrect

how can i keep backend Data synced with frontend


I have a "user" class which contains a status attribute, I want to display this attribute in a dashboard. when the backend changes this attribute I want the frondEnd to display the new value directly without reloading the page . I use Spring and React


Solution

  • You can use a pub-sub mechanism to achieve this. for example, a kafka topic can be used to sync your changes with the front end. sample data flow

    1. while inserting a record in your backend DB, push a message to user-kafka-topic.
    2. add a user-kafka-consumer in your front-end application. It would consume messages from the user-kafka-topic at runtime.
    3. you can plan to add you own front-end DB and update the front-end DB.
    4. use observer pattern in your frontend to to update your UI as soon as your json data for the page changes.