Brief of technology used - ReactJS for UI, python Server for API(FastAPI), and SQL Server as database. Here FastAPI uses pyodbc module to connect to the SQL Server database by the creation of a pool. Now the main aim is to update the React component upon changes in the database table.
The current approach: there is an API /api/get which fetches the current state of the database table. The React UI continuously polls this API to get new updates from the database on a fixed interval.
Is there any better approach to receive updates from the database in a more efficient manner?
TL;DR
Yes, use websockets.
Every time your UI checks for updates, it creates a new HTTP request. In the long run this will become costly, especially for frequent polls.
An alternative is to use websockets, which establish the connection once and then allow to communicate bidirectionally with the server (in this case, the fastAPI server).
See the docs for more information