FAQ - What is difference between update and replace?


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.