So I have a scheduled task which will be processed on every 27th. The task is very simple just collect the product information and calculate the profit (price * totalSold) then send the report to another service, but I’m afraid that how much resource (cpu, ram, threads) a saga is required because I have a lot of products (around 4k-5k) and I create a saga for each product. Let’s say I have 4k of products which means on the 27th every products will be processed and send report at the same time. I’m not sure if my cloud server will be able to handle it.
// I have products around 4k-5k
class ProductProfitReporterSaga {
@Autowired
private lateinit var eventScheduler: EventScheduler
@Autowired
private lateinit var reporterService: ReporterService
@StartSaga
@SagaEventHandler(associationProperty = "productId")
fun on(event: ProductCreatedEvent){
// other task
val scheduledDay = reporterService.getScheduledDay()
val event = ProfitReportedEvent(
productId = event.productId
)
eventScheduler.schedule(scheduledDay, event)
}
// every 27th
@SagaEventHandler(associationProperty = "productId")
fun on(event: ProfitReportedEvent){
reporterService.sendReport(
productId = event.productId,
..some_params..
)
val scheduledDay = reporterService.getScheduledDay()
eventScheduler.schedule(scheduledDay, event)
}
@EndSaga
@SagaEventHandler(associationProperty = "productId")
fun on(event: ProductDeleted){
eventScheduler.cancelSchedule(..token..)
}
}