Stage 4 · Reliability · Medium · 15 min

Containers, orchestration and autoscaling

How an app is packed so it runs the same way on each machine. And how a system places copies on machines, replaces the ones that die, and adds more under load.

What each interview level is expected to know

Learn first: Load balancing and health checks, CI/CD and safe deployments

After this lesson you can:

  • Explain what an image and a container are, and why they run the same everywhere.
  • Describe how an orchestrator places copies and replaces the ones that die.
  • Work out how many copies an autoscaler asks for from its target.

Start here

See it in 60 seconds

What a container is

A container packs an app with everything it needs, so it runs the same on any machine that runs containers, and many share one machine.

Scene 1 of 6 · Works on the laptop

The app runs on the laptop, but the machine has an older Python, so the same app fails there.

Containers on the machineLaptop, the developer'sLaptopthe developer'shas Python 3.12Container image, one packageContainer imageone packageMachine, 4 CPUs, FAILEDMachine4 CPUsapp needs Python 3.12FAILED
  • Laptop — the developer's — healthy — has Python 3.12
  • Container image — one package — healthy
  • Machine — 4 CPUs — FAILED — app needs Python 3.12
Containers on the machine
0
Time to start one
not shown yet
  1. Works on the laptop. The app runs on the laptop, but the machine has an older Python, so the same app fails there.
  2. Pack what it needs. A container image packs the app with everything it needs: its Python, its libraries, its settings.
  3. Same image, any machine. The machine runs that image as a container, and the app sees the Python it was packed with.
  4. Three share one machine. Three containers run side by side on one machine, each with its own files, sharing one operating system.
  5. Each has a limit. Each container gets a limit, such as 1 CPU, so one busy app cannot starve the others.
  6. Starts in seconds. A container starts in about 2 s, because it shares the machine's operating system and does not start its own.
  7. Now you try. The machine has 4 CPUs. Each container asks for this many CPUs. How many containers fit? For example: 4 containers fit: 4 of the 4 CPUs are reserved, and none is left over. A container is placed only where its whole request fits, so a machine can have CPU left that no container of that size can use.

Scene 1 of 6: Works on the laptop. The app runs on the laptop, but the machine has an older Python, so the same app fails there.

Key points

  1. An image is the package; a container is that package running.
  2. The same image runs on a laptop, in tests and in production.
  3. Containers share the machine's operating system, so they start in seconds.
  4. An orchestrator such as Kubernetes decides which machine runs each container.

Go deeper in the Orchestrator: copies, machines and autoscaling lab →

In plain words

An app needs more than its own code: the right version of Python, some libraries, some settings. A is one package that holds the app with all of that. So it runs the same on a laptop and on a server. A running image is called a , and many containers can share one machine. Say you want 6 copies of your app on 3 machines. An is the program that places them, starts a new copy when one dies, and keeps the number at 6. An changes that number when traffic rises or falls.

Behind that count, the work runs as a loop. You build the image once, and every server pulls that exact package. You also state how much CPU and memory each one needs, so it lands only where that much room is free. The orchestrator can check each container every few seconds and restart any that has stopped answering. If a whole server goes dark, its containers are started again on the others.

The problem it solves

Without containers, every server is set up by hand, and "it works on my laptop" fails in . Without an orchestrator, a person decides which server runs what, and a machine that dies at 3 a.m. stays dead until someone wakes up. And a fixed number of copies is either too few at the peak or wasted at night.

Why it matters

Designs say "we run 6 copies and it autoscales" as if that were free. An interviewer will ask what places those copies, what happens when a machine dies, and why autoscaling does not save you from a sudden jump.

A worked example

Say one copy serves 40 requests a second, and 120 arrive. Three copies would run at 100%, so you run 6, each at 50%. Then traffic jumps to 300 a second. Six copies can serve only 240, so 60 requests fail each second. The autoscaler needs about 12 seconds to add enough copies, so several hundred requests fail first.

Think of it like…

Think of shipping containers. Any ship or crane can carry one without knowing what is inside. A port manager decides which ship takes each box.

Where this analogy stops working

A standard box that any carrier can move is the useful part. When a ship sinks, its boxes are lost. An orchestrator starts a fresh copy on another machine. But anything the old copy saved on its own disk is gone, so the data must live outside the container.

Try it

See it working

Live simulationOpen the full lab →

Lab · Reliability

Orchestrator: copies, machines and autoscaling

You say how many copies of an app you want. An orchestrator places them on machines, replaces the ones a dead machine took with it, and can add copies when traffic grows. Watch where the copies go, and how long each fix takes.

Try it

Lab time 3.0 s
On machine 1On machine 2On machine 3Pending: noneUsers, 120 requests/sUsers120 requests/sLoad balancer, 6 copies take trafficLoad balancer6 copies take trafficMachine 1, 2 of 4 CPUsMachine 12 of 4 CPUs2 runC1, runningC1runningC4, runningC4runningMachine 2, 2 of 4 CPUsMachine 22 of 4 CPUs2 runC2, runningC2runningC5, runningC5runningMachine 3, 2 of 4 CPUsMachine 32 of 4 CPUs2 runC3, runningC3runningC6, runningC6running

The lab is busy, so only some requests are drawn as dots, few enough to follow. The numbers still count every request.

  • Users — 120 requests/s — healthy
  • Load balancer — 6 copies take traffic — healthy
  • Machine 1 — 2 of 4 CPUs — healthy — 2 run
  • C1 — running — healthy
  • C4 — running — healthy
  • Machine 2 — 2 of 4 CPUs — healthy — 2 run
  • C2 — running — healthy
  • C5 — running — healthy
  • Machine 3 — 2 of 4 CPUs — healthy — 2 run
  • C3 — running — healthy
  • C6 — running — healthy
  • Request
  • Response
  • Error / rejected
Copies running
6/ 6 wanted
Healthy: can serve about 240 requests/s
Pending
0
6 of 12 CPUs reserved
CPU use
45%
of the running copies, last second
Failing now
0%
of requests, over the last 2 s
Time to recover
–
no machine has died yet
Failed since traffic rose
0
requests

Numbers add up:351 arrived = 328 answered + 0 sent to a dead machine + 0 refused, no free copy + 23 in progressThe lab checks this sum as it runs, so a counting mistake would show here.

Controls

Copies
6

Each copy reserves 1 CPU and serves about 40 requests a second.

Every 5 s it sets "Copies wanted" from CPU use, aiming for 60%.

Traffic
120/s
Machines
Machine 1
Machine 2
Machine 3

Up to 5 machines, each with 4 CPUs.

Copies wanted and running
WantedRunning
04812161s2s3s
Show data table
TimeWantedRunning
1s66
1s66
2s66
2s66
3s66
3s66
CPU use and failed requests (%)
CPU useFailed requests
02550751001s2s3s
Show data table
TimeCPU useFailed requests
1s42.10
1s60.40
2s53.80
2s38.80
3s38.80
3s50.40

What just happened

Nothing yet. Start traffic or run an experiment.

What this model simplifies
  • Every copy is the same size: 1 CPU. Real copies ask for different amounts of CPU and memory, and placing them is a harder puzzle.
  • A copy always starts in 2 s. Real ones take seconds to minutes, mostly to fetch the container image.
  • A dead machine is noticed after 3 s, and its copies are replaced at once. Kubernetes marks a silent machine not ready after about 40 s, and by default waits 5 more minutes before it replaces the copies.
  • The load balancer learns of a dead machine at the same moment as the orchestrator. A real one has its own health checks, which are often faster.
  • The autoscaler looks every 5 s and removes copies after 15 quiet seconds. The Kubernetes one looks every 15 s, reads CPU numbers that are already some seconds old, and waits 5 minutes before it removes copies.
  • A request that finds every copy busy fails at once. There is no queue and no retry.
  • "CPU use" is the share of each copy's 8 request slots in use. The load balancer picks at random among the copies with a free slot.
  • Only copies are added by the autoscaler. Adding machines is your job here, and takes no time.

Also try: Deployments · Load balancer

Mechanics

How it works

The pictures use three machines, each with 3 CPUs free, and copies that ask for 1 CPU each. They show where copies go, what happens when a machine dies, and how the autoscaler picks a number.

  1. Pack the app into an image

    An image is one package with the app and everything it needs. Say the app needs Python 3.12 and the server has 3.9. The image brings 3.12 with it, so the app behaves the same on every machine that can run the image. One limit: an image is built for one kind of CPU, and it uses the machine's own kernel. The builds the image once and ships that same image.

  2. Run images as containers

    A container is a running copy of an image. Containers on one machine share its operating system, but each sees only its own files, and can be given a limit on CPU and memory. So a machine with 4 CPUs can run 4 small apps side by side. Once the image is on the machine, a container usually starts in a few seconds.

  3. Tell an orchestrator what you want

    With hundreds of containers on dozens of machines, nobody places them by hand. You tell an orchestrator, such as : keep 6 copies of this image running. A control loop compares what you asked for with what exists, again and again, and fixes any difference.

  4. It places each copy where it fits

    Pick a case to follow below

    With this case: The 6 copies were spread 2 to a machine, and each machine kept 1 CPU free.

    Orchestrator, keeps the count, NOWOrchestratorkeeps the countwants 6NOWMachine A, 3 CPUs freeMachine A3 CPUs freeMachine B, 3 CPUs freeMachine B3 CPUs freeMachine C, 3 CPUs freeMachine C3 CPUs free
    • Orchestrator — keeps the count — healthy — NOW — wants 6
    • Machine A — 3 CPUs free — healthy
    • Machine B — 3 CPUs free — healthy
    • Machine C — 3 CPUs free — healthy
    • Start a copy
    Step 1 of 3

    Step 1 of 3 · Orchestrator

    Done: You ask for 6 copies

    What happens
    Each copy asks for 1 CPU. The orchestrator looks for machines with that much free.
    Why
    Each machine has 3 CPUs free, so 9 copies fit in all.
    What changes
    It starts placing them.
    Next
    One copy goes to each machine
    Copies asked for
    6
    Copies running
    0
    Pending
    0
    none waiting

    Step 1 of 3: Orchestrator. You ask for 6 copies. Each copy asks for 1 CPU. The orchestrator looks for machines with that much free.

    Each copy asks for resources, such as 1 CPU. The orchestrator picks a machine with that much free, and spreads the copies over the machines. If no machine has room, the copy waits. This state is called pending.

    In the picture, 6 copies are spread 2 to a machine. Ask for 10, and 9 of them fill every free CPU. Copy 10 is not started: it waits, pending, until a CPU frees up or a machine is added.

  5. It replaces what dies

    Orchestrator, keeps the countOrchestratorkeeps the countMachine A, 3 CPUs freeMachine A3 CPUs freeMachine B, 3 CPUs free, FAILED, NOWMachine B3 CPUs freesilentFAILEDMachine C, 3 CPUs freeMachine C3 CPUs free
    • Orchestrator — keeps the count — healthy
    • Machine A — 3 CPUs free — healthy
    • Machine B — 3 CPUs free — FAILED — NOW — silent
    • Machine C — 3 CPUs free — healthy
    • Silence
    • Start a copy
    Step 1 of 3

    Step 1 of 3 · Machine B

    Failed: Machine B stops sending heartbeats

    What happens
    Its power failed. Its 2 copies stopped with it.
    Why
    The orchestrator only knows a machine is alive while its heartbeats keep coming.
    What changes
    After a few missed heartbeats, it marks B not ready.
    Next
    The control loop counts 4 copies, not 6
    Copies asked for
    6
    Copies running
    6
    as asked

    Step 1 of 3: Machine B. Machine B stops sending heartbeats. Its power failed. Its 2 copies stopped with it.

    Each machine sends a : a short "I am alive" message. When one goes silent, the orchestrator marks it not ready and starts new copies on other machines. A copy never moves: a new one starts from the same image. This takes seconds to minutes, so run enough copies to lose a machine. It also checks each copy. A failed liveness check means the app is stuck, so it is restarted. A failed readiness check only takes it out of traffic for now.

    In the picture, machine B stops sending heartbeats, and its 2 copies stop with it. The control loop counts 4 copies, not 6, and starts 2 new ones on A and C from the same image.

  6. An autoscaler changes the number

    Orchestrator, keeps the count, NOWOrchestratorkeeps the countNOWMachine A, 3 CPUs freeMachine A3 CPUs free2 · 90% CPUMachine B, 3 CPUs freeMachine B3 CPUs free2 · 90% CPUMachine C, 3 CPUs freeMachine C3 CPUs free2 · 90% CPU
    • Orchestrator — keeps the count — healthy — NOW
    • Machine A — 3 CPUs free — healthy — 2 · 90% CPU
    • Machine B — 3 CPUs free — healthy — 2 · 90% CPU
    • Machine C — 3 CPUs free — healthy — 2 · 90% CPU
    • Start a copy
    Step 1 of 4

    Step 1 of 4 · Orchestrator

    Watch: Traffic rises, and 6 copies run at 90% CPU

    What happens
    The autoscaler checks CPU use. The target is 60%.
    Why
    Busy copies answer more slowly, and a further rise could overload them.
    What changes
    It works out how many copies would bring CPU back to the target.
    Next
    It asks for 6 × 90 ÷ 60 = 9 copies
    Copies
    6
    CPU per copy
    90%
    Watch: target 60%

    Step 1 of 4: Orchestrator. Traffic rises, and 6 copies run at 90% CPU. The autoscaler checks CPU use. The target is 60%.

    What these pictures simplify. These pictures use whole CPUs and a round start time of 30 seconds. Real copies also ask for memory, and how fast a dead machine is noticed depends on settings. The orchestrator lab above runs copies, machines and autoscaling over time.

    An autoscaler measures a signal such as CPU use. Say 6 copies run at 90% CPU and the target is 60%. It asks for 6 × 90 ÷ 60 = 9 copies. It acts after the load arrives, and new copies need time to start, so a sudden jump still hurts for a while. A second autoscaler can add machines when copies are pending.

    In the picture, the autoscaler works out 6 × 90 ÷ 60 = 9 and places 3 new copies. While they start, the 6 old copies stay at 90%. The picture uses 30 seconds as an example start time.

Use it when

  • Many services, or many copies of one: an orchestrator places, restarts and scales them for you.
  • Traffic that changes through the day: an autoscaler runs fewer copies at night and more at the peak.
  • Any team that wants the test servers and the production servers to run the very same package.

Skip it when

  • One small app on one server: an orchestrator is a large system to learn and to run.
  • Autoscaling as your only plan for sudden jumps: new copies arrive seconds to minutes late.
  • A database that keeps its data on the machine's own disk, unless you plan where that data lives: a replaced copy starts empty.

Check yourself

A container keeps failing its liveness check. What does Kubernetes do?

Judgement

Trade-offs and how it fails

What you give up

Packing
Packing many containers onto each machine saves money. But a busy neighbour can still slow you down, and one dead machine takes more copies with it.
Automation
The orchestrator repairs and scales with no person involved. But it is a complex system that can fail, or be set up wrongly, by itself.

Failure modes

  • Pending copies: no machine has a free CPU, so the copies you asked for never start.
  • Scaling too late: a jump in traffic fails requests for the seconds or minutes it takes to add copies.
  • All copies on one machine: when it dies, the whole service is down until new copies start.
  • No limits: one container with a memory leak takes the machine's memory, and its neighbours are killed.

In the real world

  • Docker made containers common. A file called a Dockerfile lists the steps that build an image.
  • Kubernetes is the most used orchestrator. In its words, a copy is a pod, a machine is a node, and a Deployment is the rule "keep N pods running".
  • The Kubernetes autoscaler for pods checks every 15 seconds by default, and waits 5 minutes before it removes copies. Source: Kubernetes docs: Horizontal Pod Autoscaling (checked 14 October 2026)
  • Google ran its services in containers on its own system, Borg, for years before it released Kubernetes in 2014. Source: Kubernetes blog: Borg, the predecessor to Kubernetes (2015) (checked 14 October 2026)

Trade-offs to be ready to discuss: Spare capacity vs cost · Scale on cpu vs scale on queue length

Check yourself

Why set CPU and memory requests on each container?

Interview

What interviewers look for

  • Say "N copies behind a , spread across machines", and give N a reason: enough to lose one machine.
  • When you say "it autoscales", add the signal and the delay: "on CPU at 60%, and new copies take about a minute".
  • Keep services , so any copy can be replaced. Put the data in a database, not in the container.

Say it out loud: Why does an autoscaler not stop failures during a sudden jump in traffic?

8 copies run at 90% CPU. The autoscaler's target is 60%. How many copies does it ask for?

Expected depth by interview level

Levels describe the depth interviewers probe, not years of experience. Choose a level on the learning path to highlight it.

JuniorUseful
What a container is, and why a service runs as several copies.
MidUseful
How copies are placed and replaced, and what an autoscaler measures.
SeniorExpected
Autoscaling lag, spare capacity, and what happens when a machine or a zone is lost.
StaffExpected
How many machines to run and what they cost, limits per team, and how failures of the orchestrator itself are contained.

Practice

Apply it

Three harder questions

The first two use the idea on a new case. The last asks you to judge a design.

Apply it

4 copies run at 30% CPU. The autoscaler's target is 60%. How many copies does it ask for?

Apply it

3 machines each have 4 CPUs free. You ask for 14 copies, and each requests 1 CPU. What happens?

Judge a design

A service runs 6 copies, and the orchestrator has placed all 6 on one machine. What is the risk, and what is better?

Next: security beyond sign-in, where secrets live, what is encrypted, and how a service limits abuse.

Go deeper

Sources and further reading

First-hand sources to check this page against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.