# What's the simplest solution to my use case?

**URL:** <https://forums.foundationdb.org/t/whats-the-simplest-solution-to-my-use-case/3086>\
**Category:** Using FoundationDB\
**Tags:** bindings\
**Created:** [December 17, 2021, 10:31am UTC](https://forums.foundationdb.org/t/whats-the-simplest-solution-to-my-use-case/3086 "2021-12-17T10:31:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Djoak](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/djoak/32/1260_2.png) [@Djoak](https://forums.foundationdb.org/u/Djoak)\
**Post date:** [December 17, 2021, 10:31am UTC](https://forums.foundationdb.org/t/whats-the-simplest-solution-to-my-use-case/3086/1 "2021-12-17T10:31:54Z")

</div>

I’m using FDB to do these things:

1. set a key and increment it’s counter
2. if the key already exists in FDB, don’t increment the counter

When I use C bindings and run it concurrently, the transaction conflict occurs.

My codes like:

```auto
void put_key(std::string_view key, std::string_view value)
{
  auto tr = make_txn();
  if (tr.get(key)) {
    tr->add_counter_for_key(key); // using fdb_transaction_atomic_op and FDB_MUTATION_TYPE_ADD
  }
  tr->set(key, value);
  tr->commit();
}

```

Looks like other transactions may write the key when a transaction is reading the key, so there’s conflict.

Is there any problem for my codes, or my solution is not suitable?

---

<div class="post-metadata">

**Author:** ![jkominek](https://sea1.discourse-cdn.com/foundationdb/user_avatar/forums.foundationdb.org/jkominek/32/140_2.png) [@jkominek](https://forums.foundationdb.org/u/jkominek)\
**Post date:** [December 20, 2021, 7:03pm UTC](https://forums.foundationdb.org/t/whats-the-simplest-solution-to-my-use-case/3086/2 "2021-12-20T19:03:38Z")

</div>

I can’t figure out what it is you’re doing. Is `add_counter_for_key` operating on a key that’s actually `key + "counter"`, or something similar?

Are the transaction conflicts that big of a problem? You should be retrying the operation in the event of a conflict; occasional conflicts are to be expected.

If you’re writing stuff in C(++) you’ll want to write yourself some sort of handler which can retry transactions. Something like:

> <https://github.com/jkominek/fdbfs/blob/aaa4c29f75681b902f6705f989fce5f824cd0c25/util.h#L119>
