Preserving state of variables in RAM on Power Failure
You need to do a read-modify-write (RMW) operation, in which you read out the entire 512-byte page to RAM, change the value(s) that need to be updated, then erase and rewrite the flash page.

There is a concern that power could fail while this procedure is executing, so more elaborate schemes that "bounce" the data between two separate flash pages have been designed that are much more robust against this. However, the system overall must still handle the possibility that the update may or may not have happened before the power failure.

This is especially critical when the data in question is the processor's own instructions (i.e., remote firmware update). You must guarantee that no matter where in the process the power fails, the system can always get back to a working state, running either the original firmware or the new firmware. Otherwise, you end up "bricking" the system.