# Mitigating Deadlocks in high concurrency environments

DevFeed: [Mitigating Deadlocks in high concurrency environments](<https://devfeed.tech/articles/mitigating-deadlocks-in-high-concurrency-environments-1494.md>)

Original publisher: [Read original article](<https://shopify.engineering/mitigating-deadlocks-in-high-concurrency-environments>)

Author: Elson Oliveira

Published: 2024-08-14T16:31:20Z

Content type: article

Language: en

Sources: [Shopify Engineering](<https://devfeed.tech/sources/shopify-engineering.md>), [Shopify Engineering - Shopify Engineering](<https://devfeed.tech/sources/shopify-engineering-shopify-engineering.md>)

Topics: [Deadlock](<https://devfeed.tech/topics/deadlock.md>)

Tags: [batch](<https://devfeed.tech/tags/batch.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [data](<https://devfeed.tech/tags/data.md>), [mysql](<https://devfeed.tech/tags/mysql.md>), [performance](<https://devfeed.tech/tags/performance.md>), [update](<https://devfeed.tech/tags/update.md>)

## AI overview

The article explains how concurrent MySQL upserts can create gap-lock overlaps and deadlocks, and proposes composite primary keys to better align storage with update patterns.

## Source excerpt

The problem In order to guarantee data integrity, MySQL requires locks prior to updating existing records. If multiple processes update data in the same table in parallel, deadlocks can occur depending on how the data is stored in disk and managed by MySQL. That can happen even if the different processes target different records. This blog post explores the problem of deadlocks in MySQL while updating data, and illustrates how composite primary keys can effectively mitigate this issue.