Sikau

Project: Ready for millions · Day 4 · about 55 min

Final: Capacity planning

Simulate a queue-driven worker fleet and pick the cheapest setup that meets the target.

Festival day

Exam results come out and 100 jobs a second pour into your SQS queue for ten ticks. Workers scale on backlog per worker, but new ones take time to boot, and every worker-tick costs money. Instead of guessing, simulate: run each candidate configuration through the rush and pick the cheapest that keeps the backlog under your target.

One tick at a time

  • Jobs arrive and join the backlog.
  • Workers that finished booting start working.
  • Each active worker clears perWorker jobs.
  • Desired workers = ceil(backlog ÷ targetBacklog), clamped to min…max: launch (they boot for startupDelay ticks) or stop active ones.
  • Pay for every active and booting worker.
const spike = (t) => (t >= 5 && t < 15 ? 100 : 5); // a 10-tick rush

The rest of this lesson

  • Why simulateexplain
  • Choosing the cheapest good setupexplain
  • One simulated tickorder
  • Setting to effectmatch
  • simulate and cheapestchallenge
  • Badge quizquiz
  • At scale: complete!recap

Continue this lesson free — run real code in your browser

Continue with Google

See all 4 lessons of Project: Ready for millions