FAQ - What is difference between update and replace?

The Aerospike Knowledge Base has moved to https://support.aerospike.com. Content on https://discuss.aerospike.com is being migrated to either https://support.aerospike.com or https://docs.aerospike.com. Maintenance on articles stored in this repository ceased on December 31st 2022 and this article may be stale. If you have any questions, please do not hesitate to raise a case via https://support.aerospike.com.

FAQ - What is the difference between an update and a replace when writing a record?

The REPLACE policy will create the record or replace it entirely if a previous version of the record already existed. This will delete potential already existing bins for this record.

The UPDATE policy will create the record or update the record if it already exists. This will merge previously existing bins with the new bins being written.

UPDATE is the default behaviour.

Other policy values can force records to only be created (fail if the record already exists) or only be updated/replaced (fail if the record doesn’t already exist).

Policy values

To replace a record:

writePolicy.recordExistsAction = RecordExistsAction.REPLACE

To update a record:

writePolicy.recordExistsAction = RecordExistsAction.UPDATE

Performance impact

Since the UPDATE policy requires a read in order to merge the bins, it will generally be slower.

If secondary indices are defined, then even the REPLACE wil have to do a read operation in order to update the secondary index, based on the values of the previously existing bins.

For XDR, the behavior is controlled through the xdr-ship-bins configuration option.

What about single-bin?

For single-bin, the entire record will be replaced. UPDATE and REPLACE would behave the same way in such case.

References

https://www.aerospike.com/apidocs/java/com/aerospike/client/policy/RecordExistsAction.html

https://www.aerospike.com/apidocs/python/client.html#write-policies

Keywords

CLIENT UPDATE REPLACE

Timestamp

08/28/2018