# Spot instances

> Spare cloud servers rented at a deep discount, but taken back on short notice.

- Level: Intermediate
- Topics: Cloud, AWS
- URL: https://tidbit.legios.com.ar/spot-instances/
- In Spanish: [Instancias spot](https://tidbit.legios.com.ar/es/spot-instances/)

Cloud providers keep far more servers than they are using at any moment, so they can always hand capacity to whoever asks. **Spot instances** are how they rent out that idle capacity: the same virtual machines as usual, at a big discount, with one condition. When the provider needs the capacity back for a full-price customer, it takes it, and your machine is stopped or shut down.

On AWS, EC2 Spot can cost up to roughly 90% less than the normal on-demand price, and the price moves slowly with supply and demand for each instance type and Availability Zone. You get a two-minute warning before an interruption, which your software can read to save its work. Google Cloud (Spot VMs) and Azure (Spot Virtual Machines) offer the same idea with their own rules.

Spot is a good fit for work that can be paused, retried or split: batch processing, rendering, data analysis, CI/CD builds, training jobs with checkpoints, or stateless web servers behind a load balancer with enough copies. It is a bad fit for a single database or anything that must not stop. The common pattern is a mix: a base of regular or reserved capacity for what must stay up, and spot on top for the rest, spread across several instance types so one shortage does not take everything at once.

## An analogy

Like flying standby: you pay much less for an empty seat, but if a full-fare passenger shows up, you get off the plane.

## Keep in mind

- Same machines, big discount, but they can be reclaimed.
- On AWS you get a two-minute notice before an interruption.
- Great for batch jobs, builds and anything that can restart.
- Mix with regular instances and spread across instance types.

## Go deeper

- [Spot Instances (Amazon EC2 docs)](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances.html)
- [Amazon EC2 Spot Instances](https://aws.amazon.com/ec2/spot/)
- [Spot VMs (Google Cloud docs)](https://cloud.google.com/compute/docs/instances/spot)

## Related terms

- [Cloud computing](https://tidbit.legios.com.ar/cloud-computing/): Renting computers over the internet instead of buying your own.
- [Server](https://tidbit.legios.com.ar/server/): A computer whose job is to answer requests from other computers, all day, every day.
- [Virtual machine](https://tidbit.legios.com.ar/virtual-machine/): A complete computer made of software, running inside a real one.
- [Regions and Availability Zones](https://tidbit.legios.com.ar/regions-and-availability-zones/): Where AWS physically lives: cities worldwide, each split into separate data centers.
- [Google Cloud](https://tidbit.legios.com.ar/google-cloud/): Google's cloud business: computing, storage, data and AI services rented by the hour.
- [Microsoft](https://tidbit.legios.com.ar/microsoft/): The company of Windows and Office, now just as much a cloud company with Azure.
- [Batch processing](https://tidbit.legios.com.ar/batch-processing/): Collecting data for a while and then processing it all in one big run.
- [CI/CD](https://tidbit.legios.com.ar/ci-cd/): Automation that builds, tests and ships every code change, so releases become routine.
