If you don’t need all the records to be persisted in the same transaction you can chain multiple
ask calls using
thenApply. However, you’ll need to be mindful of how to handle failures in the chain of calls. If call 7 of 10 fails, do you care, and if so how do you respond? The saga pattern might be useful if you need them to all succeed or fail.
Alternatively, you can change the bounded context of your aggregate. Change your
PersistentEntity to model a collection of records (that are related in some way). This way all the records can be sent to a single
PersistentEntity and be persisted in a single transaction. Determining the right bounded context can be tricky, so you’ll need to be thoughtful about whether this change makes sense for your domain. Larger aggregates make complex transactions simpler, but can hurt scalability.