How much resource does a saga requires

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..)
  }
}

Hello @Werapon_Pat ,

Is there a special reason why you need a Saga in this case? Looking at it, it seems that the (Product) Aggregate can also be used to Schedule the event.

Best Yvonne

Yes, actually in order to create report it requires some parameters from another event so for example let’s say CustomerFeedbackEvent will gives some information about how the use feel about our products and I will need to include this parameter within the report.

Couldn’t you use a stateless event handler for that and update a query model? When the ProfitReportedEvent (or ProfitReportRequestedEvent) is published from the Aggregate, the report can be generated from the data in the query model. It is not forbidden to do simple calculations in event Handlers.

In that case, you don’t need the overhead of a Saga.

Yvonne