Having used Azure on and off for a bit, I’m now looking into the GCP (Google Cloud Platform) for a project and whilst this might not be to everyone’s interest, there’s a very interesting youtube video “Google Cloud Platform on a shoestring budget (Google I/O ’18)” on cost savings on GCP (especially interesting for start-ups or smaller developers but also for larger scale development).
Anyway, one interesting cost saving mentioned is, if your application runs on a compute engine/VM but you are okay with GCP killing your instance if/when it requires further resources, then cost savings (according to the video) can be from $24.67 per month down to $7.30 per month (costs may have changed since the video) running on an n1-standard1.
Why this is interesting is that, when writing for mobile, for example, we have a similar design paradigm to be aware of. The mobile application may be running but then at some point the OS wishes to free up space and stops the application. With the GCP scheduler’s pre-emptive capability we need to design our cloud solution in the same way as our mobile. i.e.
- We’re informed for GCP (or OS on mobile) that the application is being suspended
- We need to store our state somewhere, in the case of GCP we have approx. 30 seconds to do this
- When GCP (or mobile OS) decides it can restart our application we need to read back our stored state get our applications back into the state they were prior to suspending
Note: If we run a load balancer in front of our compute engine we can better handle spinning up compute power when required.
In reality, unlike a mobile application, the notification of shutdown of your application is done at an OS level, through ACPI G2 Soft Off, so it’s generally better (from what I can see) to run your code in a stateless, almost serverless way. For example, we might run jobs as pre-emptive instances which take a message off of a pubsub or from a DB, process data and then mark to message/DB row as completed when the application has finished – in such a scenario, if the application is interrupted and shut down, the next application to be spun up and start work on the same data.
References
Creating and Starting a Preemptible VM Instance
Preemptible VM Instances
Saving Money with Preemptive VMs (Cloud Performance Atlas)