Permanent data in a stable memory, not really permanent

My answer below assumes you’re using Motoko. I’ll let someone else who’s more familiar with the Rust options (i.e. stable data structures, etc.) provide a follow-up.

If you’re using Motoko, I’d recommend reading this tutorial Stable variables and upgrade methods | Internet Computer, for which the stable keyword does the work of serialization/deserialization under the hood for you instead of needing to write your own preupgrade and postupgrade to perform this serialization.

If you need to migrate a stable data variable or data structure (say your data schema has evolved), then you need to write the code that migrates that stable data structure. Data migrations are probably the biggest headache on the IC, but there are various data migration patterns that have been developed by the Motoko community.