Read the full deadlock detail in the server log.

Check what is currently blocked.

Make both code paths lock in a consistent order.

Shorten the transactions.

Add a bounded retry for the rolled back transaction.