BeginnerLesson 3 of 126 min read

Pricing Models: On-Demand, Reserved and Spot, and the Maths of Interruptions

Understand the three main ways to pay for cloud computing: on-demand by the hour, reserved at a discount for a commitment, and spot capacity that is cheap but can be taken away. Work out when spot pays off for a job without checkpoints, verified by simulation.

In this lesson you will

  • Compare on-demand, reserved and spot prices
  • Compute expected time with interruptions
  • Find when spot beats on-demand
  • Verify a formula with simulation

About 28 minutes

Three prices for the same computer

Wren’s nightly job processes the day’s ticket sales and takes about ten hours on one server. The same virtual machine is offered at three prices, and the choice can change the bill by a factor of three. On-demand is the base price: pay by the second, with no commitment, and stop at any time. Reserved or committed pricing gives a discount, often 30 to 60 percent, in return for a promise to pay for the machine for a year or three whether you use it or not, which is a sound bet for a server that runs all the time and a waste for one that runs ten hours. Spot or preemptible capacity is spare capacity sold at a deep discount, with the catch that the provider can take it back at short notice when it needs the machines.

Spot only suits work that can tolerate interruptions: batch jobs, rendering, analysis, test runs. If a job restarts from scratch after every interruption, the interruption rate decides whether the discount is real. Suppose that interruptions arrive randomly at an average of λ per hour, and the job needs W hours of uninterrupted running. The expected time to finish, when every interruption sends you back to the start, is (e to the power λW, minus 1) divided by λ, a result from probability theory. For small λW it is close to W, and it grows exponentially: a ten-hour job at one interruption every 50 hours takes about 11 hours on average, and a 40-hour job at the same rate about 90. Checkpointing, saving progress regularly, cuts the penalty: the job restarts from the last checkpoint and not from the start, which makes spot useful for long jobs too.

Model Price Commitment Good for
On-demand Full price None Unpredictable or short use
Reserved / committed Discounted 1 to 3 years Steady, always-on servers
Spot / preemptible Deepest discount None, but interruptible Batch jobs that can restart
Free tier Free within limits Often 12 months Learning
const lambda = 0.02;                                   // interruptions per hour on spot (invented): one every 50 hours on average
const expected = W => (Math.exp(lambda * W) - 1) / lambda;
const onDemand = 1.00, spot = 0.30, reservedFull = 0.60;      // invented prices per hour; reserved is paid for 730 hours a month
for (const W of [2, 10, 24, 48, 100]) { const T = expected(W); console.log('job of', String(W).padStart(3), 'hours: expected spot time', T.toFixed(1).padStart(6), 'h | spot cost', (spot * T).toFixed(2).padStart(6), '| on-demand cost', (onDemand * W).toFixed(2).padStart(6), '|', spot * T < onDemand * W ? 'spot cheaper' : 'on-demand cheaper'); }
let lo = 1, hi = 400; for (let i = 0; i < 60; i++) { const m = (lo + hi) / 2; if (spot * expected(m) < onDemand * m) lo = m; else hi = m; }
console.log('spot stays cheaper than on-demand for jobs up to about', lo.toFixed(1), 'hours without checkpoints');
const reservedMonthly = reservedFull * 730, jobsHours = 10 * 30;
console.log('reserved for the month:', reservedMonthly.toFixed(0), '| on-demand for 300 job hours:', (onDemand * jobsHours).toFixed(0), '| spot for 30 nightly jobs of 10 h:', (30 * spot * expected(10)).toFixed(0));
console.log('DATA ' + JSON.stringify({ T10: expected(10), T100: expected(100), limit: lo }));
job of   2 hours: expected spot time    2.0 h | spot cost   0.61 | on-demand cost   2.00 | spot cheaper
job of  10 hours: expected spot time   11.1 h | spot cost   3.32 | on-demand cost  10.00 | spot cheaper
job of  24 hours: expected spot time   30.8 h | spot cost   9.24 | on-demand cost  24.00 | spot cheaper
job of  48 hours: expected spot time   80.6 h | spot cost  24.18 | on-demand cost  48.00 | spot cheaper
job of 100 hours: expected spot time  319.5 h | spot cost  95.84 | on-demand cost 100.00 | spot cheaper
spot stays cheaper than on-demand for jobs up to about 103.2 hours without checkpoints
reserved for the month: 438 | on-demand for 300 job hours: 300 | spot for 30 nightly jobs of 10 h: 100

The program uses an interruption rate of 0.02 per hour, one every 50 hours on average, and invented prices of 1.00 for on-demand, 0.30 for spot and 0.60 for reserved. For a ten-hour job the expected spot time is 11.1 hours, so the spot cost is 3.32 against 10.00 on-demand: a large saving for a small penalty, which is why nightly batch jobs are the classic use for spot. For a 100-hour job the expected time rises to 319 hours, since restarting from scratch becomes very likely to happen again and again, and the spot cost of 96 is more than the on-demand cost of 100. The crossover, found by bisection, is a job length of about 103 hours with these numbers: shorter jobs are cheaper on spot, longer ones are not, unless they save their progress.

The last lines compare monthly costs for Wren’s nightly job. A reserved server costs 0.60 for every hour of the month, 438 in all, to run ten hours a day, which wastes two thirds of the commitment. On-demand for the 300 job hours is 300, and spot for 30 nightly runs of ten hours is under 100. For an always-on web server the picture reverses: running 730 hours at 1.00 on-demand costs 730, the reserved server 438, a saving of 40 percent. The lesson is to match the price to the pattern of use: reserved for what is always on, on-demand for what is unpredictable, spot for what can restart, and revisit the mix when the load changes.

Independent check: the formula for the expected time was tested by simulation. The program drew random times to the next interruption from an exponential distribution, repeated attempts until one lasted the full length, and averaged the total time over many jobs. For ten-hour jobs the simulated mean is 11.07 hours against the formula’s 11.07, and for 100-hour jobs 318 against 319, close in both cases, within the noise of the sampling. The crossover was recomputed in Python by the same bisection and agrees. The formula assumes that interruptions are random and independent, and real spot markets have patterns, so check the provider’s interruption statistics and design for them.

Check by hand: for a 10-hour job, λW = 0.2, and e to the 0.2 is 1.2214, so the expected time is 0.2214 / 0.02 = 11.07 hours. At 30 cents per hour the cost is 3.32, against 10.00 for on-demand. For W = 100, λW = 2, e squared is 7.389, and (7.389 – 1) / 0.02 = 319 hours.

Commitments are bets

A reserved price only saves money if you really use the capacity for the whole term. Start with a base amount that you are sure about, and use on-demand for the rest.

Save progress on spot

If a job can write a checkpoint every few minutes, interruptions cost minutes and not hours, and spot becomes useful for long jobs too.

About this course

No cloud account is needed for this course. The cloud services in these lessons are small simulations that run on your own computer, in Python 3.13 or Node.js 22, because the ideas, such as access policies, queues, autoscaling and templates, are the same at every provider. Prices and names are invented or generic, and each provider’s services and prices change often, so check the current documentation of the provider you use. Every result was checked a second way. Providers’ discount models have many variants, such as savings plans and sustained-use discounts. Compare the current ones for your usage.

Practice

Add checkpoints every hour to the model and compute the expected time of a 100-hour job. Compute the break-even number of hours per month at which a reserved server beats on-demand. Find the real prices of three instance types and rerun the lesson.

Check what you learned

Five quick questions. Pick an answer and you will see straight away whether it is right and why.

What is spot capacity?

  1. A kind of storage
  2. A free service
  3. A reserved server
  4. Spare capacity sold at a deep discount that can be taken back

Use for restartable work.

When do reserved prices pay off?

  1. For a one-hour test
  2. Never
  3. When the server runs most of the time for the whole term
  4. For random use

A commitment is a bet.

What happens to a long job without checkpoints on spot?

  1. It is always cheaper
  2. It never finishes
  3. The expected time grows exponentially with its length
  4. It runs twice as fast

(e^(λW) – 1) / λ.

Why simulate the formula?

  1. To slow the job
  2. An independent check of the mathematics
  3. It is required
  4. To lower the price

Monte Carlo agrees.

Which workload suits spot?

  1. The only web server
  2. Batch jobs that can restart
  3. A database primary
  4. A login service

Anything interruption-tolerant.

Summary

  • On-demand, reserved and spot suit different patterns of use.
  • Reserved is a commitment bet; spot is interruptible.
  • Without checkpoints, expected spot time is (e^(λW) – 1) / λ.
  • Match the price model to the workload, and verify formulas by simulation.

Next lesson

Lesson 4 covers identity and access management.

Questions

Can spot instances be taken away without warning?

Providers give a short notice, often one or two minutes, and then stop the machine. Design jobs to handle it, with checkpoints and automatic restarts.

What is a savings plan?

A commitment to spend a certain amount per hour for a term, in return for a discount, with more flexibility than reserving a specific machine. Check each provider's current offers.

How do I stop surprise bills?

Set budgets and alerts, tag resources, delete what you do not use, and review the bill monthly. Lesson 11 covers cost control.

Progress is saved in this browser.