About 5 years ago, I was running a startup that had Raspberry Pis (we really need a better plural) deployed to numerous customers, and SD card corruption was a big problem. If I remember correctly the problem generally happened when there was a power loss during writes to the SD card.
I ended up creating a RAM disk and only writing to that. Once every 5 minutes or so I would flush anything that needed to be permanent to a partition on the SD card. And once every hour I'd save anything really important to an s3 bucket. SQLite also performed much better running in memory than it did directly from on the SD card.
That mostly solved the problem, but I still shipped every unit with an extra SD card and instructions on swapping it out just in case.
I ended up creating a RAM disk and only writing to that. Once every 5 minutes or so I would flush anything that needed to be permanent to a partition on the SD card. And once every hour I'd save anything really important to an s3 bucket. SQLite also performed much better running in memory than it did directly from on the SD card.
That mostly solved the problem, but I still shipped every unit with an extra SD card and instructions on swapping it out just in case.