Hi cf_gal,
I would recommend creating a database queue and processing a defined number of records at set intervals through a scheduled task. It could look like this:
1. Have a database table (the queue), which contains key data of the records that need to be processed for sending. This includes a column which tells you if it has been sent or not.
2. Have an endpoint, which processes a number or records every time you call it. Once a record is processed, set the status to sent via the column mentioned in point one.
3. Have a scheduled task that calls the endpoint at a set interval.
The combination of the number of records per request and the scheduled task interval will give you your processing limit (which should be based on your requirements).
As with any engineering decision, there are tradeoffs. This solution has the following benefits.
1. You have a list of what is processed vs not processed. This makes it easy to monitor progress.
2. If you encounter an error, you know the item in which it failed. You can even catch the error, record it in logs or DB and then continue processing the queue.
3. If you do need to fix a bug in the process, you can continue where you left off.
4. If you need to reboot the server, the API process can continue where it left off once the server is back online.
5. You are less likely to run out of memory since you are processing a limited number of items per endpoint call.
6. This solution will limit the amount of resources used resulting in a predictable impact on other workloads.
The drawback is that it will take longer to implement and is more complex than other solutions.