Per normal bulkification standards, the batches run in increments of 200 records at a time, and I have set to use 6 threads at a time. However, I am getting a lot of locking errors on my records, and this is because I am trying to create all of these records as the child of the same parent record.
I have some some research and found out that when a child record is updating (after inserting, I have an extensive flow and some custom apex running on the records to update certain pieces), it will put a lock on the parent as well. As a result, if a sibling record in a different batch attempts to update, it will experience a lock error because it was unable to put the necessary lock on the parent record.
For the most part, this makes sense to me. However, there are a couple things I don't understand. First, why do I not experience lock records with batches? For example, if every one of the records I am uploading required lock access to the SAME parent record, then I would expect some sort of problems within the individual batches of 200 records. However, when I run the process with a single thread, all the batches process fine. So, it appears that these lock errors only apply across batches, and not within batches? Is this a correct understanding, and if so, why does this locking error not happen within a single batch when all the records (200) are trying to access a single parent record?
Also, it seems odd to me that this functionality exists from the perspective of attempting to upload a large group of data all to a single parent record (for example, I have a List object which is the parent, and I want to upload all the List Entries at once, which are all children of the same List record). It seems like this would be a pretty common use case, so is there some better method of accomplishing this than what I am trying?