# Transactions exceptions in sharded cluster

**URL:** <https://forums.percona.com/t/transactions-exceptions-in-sharded-cluster/30526>\
**Category:** Percona Operator for MongoDB\
**Created:** [May 23, 2024, 9:48pm UTC](https://forums.percona.com/t/transactions-exceptions-in-sharded-cluster/30526 "2024-05-23T21:48:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Semantic](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/semantic/32/9104_2.png) [@Semantic](https://forums.percona.com/u/Semantic)\
**Post date:** [May 23, 2024, 9:48pm UTC](https://forums.percona.com/t/transactions-exceptions-in-sharded-cluster/30526/1 "2024-05-23T21:48:50Z")

</div>

Getting lots of transaction exceptions in my sharded cluster

```auto
cannot continue txnId 27087 for session uuid - base64 - - with txnRetryCounter 0 cannot continue txnId 27086 for session

```

The transaction eventually completes, but seems to be random.

---

<div class="post-metadata">

**Author:** ![Semantic](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/semantic/32/9104_2.png) [@Semantic](https://forums.percona.com/u/Semantic)\
**Post date:** [May 23, 2024, 9:59pm UTC](https://forums.percona.com/t/transactions-exceptions-in-sharded-cluster/30526/2 "2024-05-23T21:59:31Z")

</div>

The problem actually occurs due to the service acting as a load balancer in front of the mongos pods. When a transaction is executed, all of its operations need to happen against the same mongos pod, which becomes random depending on where the operation is routed through.

As a resolution, I set the `servicePerPod` param to `true` on the mongos config in order for my services requiring transactional writes to specifically select a single one and eliminate the randomness creating those errors.

There doesn’t seem to be an option to enable services both per-pod and for all of them out of the box. However since creating an additional service for the mongos is trivial, you can easily get the best of both worlds.

Hope it helps 😃

Reference [1](https://github.com/mongodb/specifications/blob/master/source/transactions/transactions.md#mongos-pinning), [2](https://github.com/zookzook/elixir-mongodb-driver/issues/61#issuecomment-633972608), [3](https://jira.mongodb.org/browse/CSHARP-3301), [4](https://finisky.github.io/2021/01/13/dontuseloadbalancerinfrontofmongos.en).
