Thrifty: alternate between VPSes and snapshots in cloud providers


Some time ago, I wrote this small utility to save costs when running a pet development VPS in Digital Ocean, and recently expanded it to work with Hetzner.

In both of these providers, the price of snapshots is cheaper than that of an active server. So, for small stateful development servers that don’t need to be online all the time, it pays to take a snapshot and destroy the server whenever it’s not being used, say, during night hours. You can restore the server from the snapshot when you need it again.

The code is not exactly the best but I’m pleased with the overall architecture of the app, in particular how it enables multiple providers. I used Backpack without an urgent need, just for the hell of it. The retry mechanism was implemented using streaming. optparse-applicative is great for creating command line parsers with sub-commands.

One thing I tried to avoid is naive From/ToJSON deriving, which makes keys of serialized JSON objects dependent of record field names. I either wrote explicit parsers, or specified field aliases using a sop-core based method.