Posting Instruction Batches
Atomicity and Consolidation of Batches
As a general rule, keep the number of batches instructed in a hook to a minimum (ideally one).
Why
A single PostingInstructionBatch is processed atomically. Either all PostingInstruction in the batch are accepted and committed or all are rejected and not committed. Instructing multiple PostingInstructionBatch breaks this atomicity and can lead to scenarios where some PostingInstruction are accepted and others are rejected, despite them coming from the same hook execution. This in turn introduces complex scenarios to debug and remediate.
Committing directives is also typically one, if not the longest part of contract execution. As the postings processor has a finite throughput reducing the number of batches to be committed helps with this.
How
There are many ways to accidentally instruct multiple PostingInstructionBatch. One common anti-pattern is