SELECTED ANSWER
replied on September 13, 2018
This error is actually originating with your SQL server and not within workflow. For me, I have run into this when I have many workflows using the same datasource that end up running at/near the same time. For instance, I had workflows that ran a database insert after forms were being submitted. My forms routing service had an error at some point, and I ended up restarting it, which triggered 5 or 6 queued instances of the form to submit essentially at the same time. I saw this deadlocking error on 2 of those instances.
There may be some SQL configuration or modifications to your query that you could try to alleviate the problem. Typically, SQL uses Table Locking, which means that when a resource is writing to a table, it temporarily locks the entire table until the transaction is complete (this is for only update/insert/delete statements, not select). You can try to use Row Locking instead, which causes the database to only lock the rows that are actively affected by the transaction you are running, but does not prevent other operations that may write to the same table. One way to do this would be to use a Custom Query activity and try using the hint "WITH (ROWLOCK)" to force row locking.