---
title: "Preemption"
url: https://www.daytona.com/compute-glossary/infrastructure/preemption
---

# Preemption

Part of the [Compute Glossary](https://www.daytona.com/compute-glossary.md), section [Infrastructure](https://www.daytona.com/compute-glossary/infrastructure.md).

Also called Preemptible capacity, Spot capacity, Spot instances.

Preemption is the reclaiming of a running machine by its cloud provider before the user releases it, usually because paying customers want the hardware back. It applies to preemptible capacity, idle [compute](https://www.daytona.com/compute-glossary/foundations/compute.md) that a provider rents out cheaply on that condition. It differs from a hardware failure in cause, not in effect, since the machine is gone either way. Software that already survives failed machines can usually survive preemption too.

A provider has to own enough hardware for its busiest hours, so at other times much of it sits idle. Selling that idle hardware earns something instead of nothing, at a price well below the normal rate that often moves with demand. Demand for that idle hardware rises and falls with the hours of the day and the season. When paying customers return, the provider needs a fast way to get the hardware back, and preemption is that way.

The buyer accepts that a machine can vanish when paying customers want it back. In return, work that can stop and resume runs for a fraction of the usual cost. The discount is large enough that batch systems often run mostly on preemptible machines. The trade-off is engineering work, since the software has to save its progress and restart cleanly.

## Capacity models

Capacity models are the terms under which a provider rents out its machines. They differ mainly in the commitment the buyer makes, and in whether a running machine can be taken back. A longer commitment usually buys a lower price, because it lets the provider plan its hardware. The risk moves with it, from the provider to the buyer.

On-demand capacity is there when it is asked for, as long as the [region](https://www.daytona.com/compute-glossary/infrastructure/region.md) has room. Reserved capacity buys a lower price, and sometimes a guarantee of room, in exchange for paying whether or not the machines are used. On-demand pricing pays for flexibility, since the buyer can stop at any time. A reservation is a bet that the machines will stay busy for its whole term.

Preemptible capacity gives up the guarantee that a running machine stays running. Platforms often mix the models, keeping a reserved baseline and sending the work that can wait to preemptible machines. When preemptible machines run short, a scheduler can move that work to on-demand machines and pay more instead of waiting. The baseline is sized for load that never stops, and everything above it is bought as needed.

| **Model**       | **Commitment**              | **Price**                             | **Can be taken back** |
| --------------- | --------------------------- | ------------------------------------- | --------------------- |
| **On-demand**   | None, paid while running.   | List price.                           | No.                   |
| **Reserved**    | Months or years in advance. | Lower than on-demand.                 | No.                   |
| **Preemptible** | None.                       | Lowest, and often varies with demand. | Yes.                  |

## Preemption notices

A preemption notice is the warning a provider sends to a machine shortly before it takes the machine back. The notice gives the workload a short window to save its state and hand off its work. Providers deliver it through a metadata service that the machine can poll, or as a shutdown signal to its operating system. The window is short, so a workload has to be ready to save at any time.

Anything on a [local disk](https://www.daytona.com/compute-glossary/storage/local-disk.md) or in memory is lost unless the workload saved it in time. A [scheduler](https://www.daytona.com/compute-glossary/infrastructure/scheduler.md) that watches for notices can move work off the machine before it disappears. Network storage survives, because it lives apart from the machine and can be attached to a new one. The scheduler can also drain the machine, sending no new work there while the current work finishes or moves.

Availability also changes with demand. In a busy zone, preemptible machines may be hard to get at all, so a design that relies on them needs a fallback. Some machines are reclaimed within minutes of starting, while others run for days. Spreading requests across machine types and zones lowers the chance that all of them are reclaimed at once.

| **Event**   | **Description**                                                                               |
| ----------- | --------------------------------------------------------------------------------------------- |
| **Notice**  | The provider warns the machine, typically between about thirty seconds and two minutes ahead. |
| **Reclaim** | The provider stops or deletes the machine once the notice period ends.                        |

## Fault-tolerant workloads

Fault-tolerant workloads are those that can stop and resume without harm, and they fit preemptible capacity best. Batch jobs and test runs that write progress to [object storage](https://www.daytona.com/compute-glossary/storage/object-storage.md) restart from the last checkpoint on another machine. The time between checkpoints sets how much work a preemption can lose. Frequent checkpoints lose less, but spend more time writing.

Stateless services with many replicas also tolerate losing a few. Each replica holds nothing that the others lack, so traffic simply moves to the replicas that remain. A load balancer stops sending traffic to a replica once it is reclaimed, and the platform starts a replacement. A few spare replicas cover the gap while the replacement starts.

Long-running work with state held only in memory fits badly. It works only when it takes regular [snapshots](https://www.daytona.com/compute-glossary/sandboxes/snapshot.md), so that a preempted machine can be restored elsewhere. Databases and long interactive sessions fall in this group. A memory snapshot also takes time to write, and one started at the last moment must finish within the notice window.

## Sandboxes on preemptible capacity

Sandboxes on preemptible capacity are [sandboxes](https://www.daytona.com/compute-glossary/sandboxes/sandbox.md) that run on hardware the provider may reclaim at short notice. They cost less than sandboxes on guaranteed capacity, in exchange for the risk of stopping at short notice. A platform may run part of its fleet this way and pass some of the saving on. Whether that risk is acceptable depends on how much work a stop would lose.

Short tasks suit preemptible sandboxes best, since a stop costs at most one task that can run again. Batch jobs that save their progress often, such as evaluation runs or training rollouts, also suit them. Interactive sessions suit them poorly, because a person or an agent loses its open processes and its place. Long tasks without saved progress suit them worst, since a stop near the end loses nearly all the work.

A sandbox survives preemption only if its state is saved somewhere the reclaimed host does not hold. Platforms take regular [snapshots](https://www.daytona.com/compute-glossary/sandboxes/snapshot.md) of its disk, and sometimes its memory, to storage outside the host. When a preemption notice arrives, the platform can save a final snapshot and restore it on another host. The sandbox then resumes elsewhere, after a pause that the work inside it has to tolerate.

## Related terms

- [Sandbox](https://www.daytona.com/compute-glossary/sandboxes/sandbox.md)
- [Compute](https://www.daytona.com/compute-glossary/foundations/compute.md)
- [Scheduler](https://www.daytona.com/compute-glossary/infrastructure/scheduler.md)
- [Overcommit](https://www.daytona.com/compute-glossary/infrastructure/overcommit.md)
- [Region](https://www.daytona.com/compute-glossary/infrastructure/region.md)
- [Snapshot](https://www.daytona.com/compute-glossary/sandboxes/snapshot.md)
