Problem:
- I am trying to design a system which takes requests from customers in real time and log them in a database. For example - request to purchase an item.
- The customer then gets a unique request-ids for his request and also is asked to wait for 'X' days because the request is being processed.
- Then the system notifies the item providers by batching all these requests in one single email periodically (lets say 4 hours).
- Item providers update items in their repository and publish them to customers. And then customer gets a notification that item providers have responded for his request.
Design:
I'm thinking of using a workflow based system for this use case. With following components (high level) -
Synchronous API:
- Receive request from customer.
- Record the request in the database.
- Also start an asynchronous workflow, return request id as a response.
Workflow does the following :
Workflow Step 1:
- Get the list of item providers
- Notify them
Workflow Step 2: (This workflow steps gets executed after "X" days)
- Send a response email back to the customer
But I'm having hard time to support the batching use-case. Is there any way I can efficiently batch the customer requests and send notification every 4 hours without having to write a cron job separately?
I'd appreciate any suggestions/help on this.