Single Notification for a number of events

Hello,
I am looking for ideas about how to send a daily summary for certain events.
There is a monolith and a notification service. In this instance, let’s say I’m a user who belongs to ACME and Widgets, Inc. is added as a 3rd Party Connection (akin to accepting a friend request) in the monolith and then sometime later in the day (could be 5 minutes), Gadgets, LLC is added. I want to send 1 email later that day letting me know that both companies have been added. Currently, for some of our other notifications, when something happens in the monolith, we publish a command with the bits of info specific to the message along with the intended recipients, etc… and the message sending/event publishing process is kicked off right away.

I’m thinking that there’s some kind of event listener that adds the detail to a queue that’s partitioned by the company (eg. ACME, etc…) and then a deadline is scheduled to execute later.

I also posed the question to chat and this is what it came back with. It leaves some bits to the imagination. eg. Do I need an aggregate for this? :person_shrugging:

Proposed Flow

  1. Capture Events: As events occur throughout the day, store them in a database or an event store.
  2. Scheduled Job: At a specific time each day, a scheduled process retrieves the relevant events.
  3. Generate & Send Summary Email: The process compiles the events into an email and sends it.
  4. Publish Event: After sending the email, publish an event (DailySummaryEmailSentEvent).
@EventHandler
public void on(SomeEvent event, DeadlineManager deadlineManager) {
    eventRepository.save(event);

    if (!deadlineManager.hasScheduledDeadline("daily-summary")) {
        Instant midnight = LocalDate.now().plusDays(1).atStartOfDay(ZoneId.systemDefault()).toInstant();
        deadlineManager.schedule(deadlineName, midnight, null);
    }
}

@DeadlineHandler(deadlineName = "daily-summary")
public void sendDailySummary() {
    List<Event> events = eventRepository.findEventsForToday();
    if (!events.isEmpty()) {
        String summary = generateEmailContent(events);
        emailService.sendEmail(summary);
        eventBus.publish(new DailySummaryEmailSentEvent(events.size()));
    }
}