# Transaction using aerospike

**URL:** <https://discuss.aerospike.com/t/transaction-using-aerospike/4495>\
**Category:** Operations\
**Created:** [August 16, 2017, 10:57am UTC](https://discuss.aerospike.com/t/transaction-using-aerospike/4495 "2017-08-16T10:57:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucky](https://avatars.discourse-cdn.com/v4/letter/l/e9c0ed/32.png) [@lucky](https://discuss.aerospike.com/u/lucky)\
**Post date:** [August 16, 2017, 10:57am UTC](https://discuss.aerospike.com/t/transaction-using-aerospike/4495/1 "2017-08-16T10:57:11Z")

</div>

Hi experts,

I am a newbie on Aerospike world. please help me with following query.

What is the best way to handle transaction on aerospike and which client should be the preferred one?

What is my transaction?

1. Get the current value of the given key
2. Check the given value is greater then or equal to current value.
3. If the answer is yes from point (2) deduct the given value with current value.

## I can perform the above steps using lua scripts but the performance of lua script is not great. is there is any alternative to it.

Preferred client ? golang or node js.

---

<div class="post-metadata">

**Author:** ![kporter](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/kporter/32/515_2.png) [@kporter](https://discuss.aerospike.com/u/kporter)\
**Post date:** [August 16, 2017, 7:35pm UTC](https://discuss.aerospike.com/t/transaction-using-aerospike/4495/2 "2017-08-16T19:35:09Z")

</div>

I believe you are looking for the “Read-modify-write” pattern: [http://www.aerospike.com/docs/client/java/usage/kvs/write.html#read-modify-write](http://www.aerospike.com/docs/client/java/usage/kvs/write.html#read-modify-write)

This is also discussed here:

> [@Significance of generation field in Write Policy](https://discuss.aerospike.com/t/significance-of-generation-field-in-write-poilicy/4463):
>
> Hi, While writing a record to database there is a field in WrietePolicy , which is generation. If I am explicitly setting it to 0 or 1 and next I am trying fetch the record I see the generation is incremented value equal to number of times the record is updated. Is this generation value decides different version of records in the device file (persisted records to file or ssd) ? Can client change this generation value to 1 always. I am not clear on the use of this generation field in WritePolicy…
