Aerospike Application Logic and Data Migration: Ensuring Rollback Safety During Bin Evolution
0 reputation · 01 May 2020, 03:15 UTC
0 reputation · 01 May 2020, 03:15 UTC
Aerospike employs a schema-less architecture where record structures are defined at the application layer rather than the server level. When evolving data models, developers often implement an "Expand and Contract" pattern to transition from an old bin to a new bin without downtime.
A critical challenge arises during the transition phase where the application must maintain backward compatibility to allow for a safe rollback. If the application logic is reverted to a previous version, it must be able to retrieve the most current state of the data, even if that data was written to a new bin by the failed deployment.
The uncertainty lies in managing the consistency of these dual-written bins and the eventual cleanup of orphan bins without impacting performance or risking data loss during a version revert.
32775 reputation · 01 May 2020, 10:27 UTC
To ensure read-consistency when rolling back to an application version that is unaware of new bins, you must implement Dual-Write synchronization. The application version introducing the new bin must write updates to both the legacy bin and the new bin simultaneously.
The recommended approach follows a strict sequence to ensure that no version of the application ever encounters a "missing" value for a required field:
If a rollback occurs during Phase 1 or 2, the previous application version will continue reading from the old bin, which has been kept current by the dual-write logic of the failed deployment.
Orphan bins (legacy bins no longer used by the current application logic) should be removed only after the rollback window has closed. Because Aerospike is schema-less, these bins occupy space per record and can impact read latency if the record size increases significantly.
aql or astool to sample records and confirm that the new bin is populated and the old bin is no longer being updated.To verify that dual-writes are functioning before proceeding to the "Contract" phase, use aql to inspect a record:
# Check if both bins exist and contain the expected values
aql -c "SELECT * FROM test.demo WHERE pk = 'user123'"
Are you using Aerospike Check-and-Set (CAS) or optimistic locking for these updates? If not, concurrent writes during the migration phase may lead to the legacy bin containing a newer value than the new bin (or vice versa), breaking the consistency required for a safe rollback.
Use comments to ask for clarification. Post a solution as an answer.
32,775 reputation · 01 May 2020, 09:49 UTC
Choosing a new bin name instead of modifying an existing bin type gives the application an immediate fallback path if the new version fails the old version continues reading the untouched original bin
To manage orphan bins without impact pair this with a time-boxed cleanup window. After the new version is validated and a throttled background scan populates the new bin for a configurable record majority the legacy bin can be formally retired via a controlled Aerospike scan avoiding sudden storage bloat