I apologize in advance for the lack of knowledge. Please feel free to edit this question to use the appropriate terminology if it is not correct.
I recently wrote a .NET core application that is supposed to continuously grab new data from an OData feed using HTTP requests and then write the data to an SQL Server database. However, despite having pretty solid exception logging and HTTP non-success code management, the application regularly misses roughly 1/500 records. I have thought about why this could be for a really long time and have done some research, but I haven't been able to find a fix. I am asking for possible solutions, but any general suggestions on how to improve the application's design are also appreciated.
Here is the general flow of the application.
- A watchdog service runs this whole application repeatedly. Before each run, the watchdog reads from a table that stores some table and program metadata and gets the last time the program succeeded.
- Now for the main application. First, the application does some setup (things like setting up DI and connections)
- Then the application checks the metadata table to see when the last time each table was successfully updated.
The following then is done for each table, asynchronously:
- Create an empty temp table with the same schema as the target table.
- An HTTP request is sent to get the first batch of records along with the count of the total records to fetch. The records are filtered to only include records with a created time stamp greater than or equal to the last successful application completion datetime (and the count reflects this filter). If there are any records, write them to the temp table.
- Get the remaining batches using the exact same filter but with a "skip" clause to separate them.
- Generate an SQL statement to insert the records from the temp table into the target table and run the statement.
- Truncate the temporary table.
- Do the same process, but this time filter by the modified time stamp. On completion, update the matching records in the target table.
- Drop the temp table.
- If there were any exceptions, they get logged and re-thrown. The top level of this application catches them and returns a negative exit code depending on the exception.
Back in the watchdog:
- If the exit code signals success (and as a secondary measure if there were no logs higher than information), only then does the application update the metadata for application success, and it records the time the application started. This is to be able to catch any records that might've been uploaded during the run.
Unfortunately, I have to keep polling this feed instead of using a publish-subscribe sort of pattern. There are also no 'flags' in the feed that signal whether records have been deleted (they just disappear). I have another routine that deletes records in the SQL database, but that seems to be working appropriately.
Even in times where there are no logged exceptions, it still seems to miss records. I can't see why this happens. Again, any advice would greatly help. Thanks very much.