A design question I encounter often is if a system should be designed in an event-based fashion or in a batch-based fashion.
As an illustrative example, let's say we need to synchronise parts of an internal CRM system with an external marketing system. Specifically, we need to sync customers from the CRM into the Marketing system.
There are at least two questions we can ask about the sync during the design.
*Question 1: What is the trigger for the sync?*
- The sync could be triggered periodically, let's say every 10 minutes.
- The sync could be triggered based on an event, let's say every time a customer is added/modified/deleted in the CRM.
*Question 2: What is the scope of the sync?*
- The sync could sent all changes (the delta) after the previous sync.
- The sync could sent the current snapshot of all customers
- The sync could sent full snapshots of all changed customers
To decide on the design, here are some considerations I've stumbled upon (structured according to the [[Map of risks]]):
- **Value**:
- Event-based sync would typically propagate data sooner, which might be desirable from business value perspective
- **Feasibility**:
- Which sync options are technically available?
- With event-based triggers, how to technically execute the initial sync?
- **Maintenance**:
- Pragmatically, idempotent batch-based sync might be easier to reason about (and maintain) with compared to the event-based sync. For example, syncing all changes:
- with batch: usually straightforward (fetch all changes since Jan01)
- with event-based: execute a sync on each CRUD operation, plus take care of the initial load:
- In the event-based triggers, there could be concurrency issues that needs to be taken care of. For example, during the handling of the CustomerCreated event, the CRM confusingly triggers also a CustomerUpdated event.
- In the event-based triggers, one needs to think about unhappy paths, that is, what happens if there's an error or an exception during the sync? How to retry the execution with respect to other possible events happening at the same time?
- In general, with event-based trigger, I'd recommend [[EventStorming]] to get full cross-silo clarity on all relevant events
- **Operating costs:**
- Periodic batch might be resource intensive, and thus more costly, or even hurting usability of the CRM system.
- Event-based systems seems generally cheaper and faster, not hurting the CRM usability.