Understanding data skew
If you are seeing update operations take a while and/or seeing UNABLE_TO_LOCK_ROW
exceptions during inserts or updates, data skew issues could be the reason. Data skew is a database anti-pattern that occurs when a significant number of records are dependent on one single record. For instance, many Contacts are children of the same Account.
When a child record is then updated, the platform locks the parent to ensure data integrity during the update. Normally, this happens very fast and does not cause any issues. However, as data volumes grow, updating children of the same parent may become very slow and, when done in different threads, some of the updates may fail.
Salesforce recommends keeping the number of child records related to the same parent under 10,000 to avoid performance and locking issues. So, if you must relate many child records to the same parent, create additional parents to keep the number of children under 10,000. You may also want to...