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.
- 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
- Works on the laptop. The app runs on the laptop, but the machine has an older Python, so the same app fails there.
- Pack what it needs. A container image packs the app with everything it needs: its Python, its libraries, its settings.
- Same image, any machine. The machine runs that image as a container, and the app sees the Python it was packed with.
- Three share one machine. Three containers run side by side on one machine, each with its own files, sharing one operating system.
- Each has a limit. Each container gets a limit, such as 1 CPU, so one busy app cannot starve the others.
- Starts in seconds. A container starts in about 2 s, because it shares the machine's operating system and does not start its own.
- 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
- An image is the package; a container is that package running.
- The same image runs on a laptop, in tests and in production.
- Containers share the machine's operating system, so they start in seconds.
- 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 (The package a container is started from: the app, the right versions of what it needs, and its settings.) 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 (A running package that holds an app and everything it needs. Many containers can share one machine, each with its own files and limits.), and many containers can share one machine. Say you want 6 copies of your app on 3 machines. An (A program that decides which machine runs each container, and keeps the number of copies you asked for running.) is the program that places them, starts a new copy when one dies, and keeps the number at 6. An (A program that adds copies when a signal such as CPU use is high, and removes them when it is low.) 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 (The live system that real users reach, as opposed to a test or practice copy.). 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
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.
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 (A fixed chain of automatic steps, where each step hands its result to the next. A CI/CD pipeline builds, tests and releases every code change.) builds the image once and ships that same image.
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.
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 (The most used orchestrator. It calls a copy a pod and a machine a node.): 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.
It places each copy where it fits
Pick a case to follow belowWith this case: The 6 copies were spread 2 to a machine, and each machine kept 1 CPU free.
Orchestrator, keeps the count, NOW Orchestrator keeps the count wants 6 NOW Machine A, 3 CPUs free Machine A 3 CPUs free Machine B, 3 CPUs free Machine B 3 CPUs free Machine C, 3 CPUs free Machine C 3 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 3Step 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 for6Copies running0Pending0none waitingStep 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.
It replaces what dies
Orchestrator, keeps the count Orchestrator keeps the count Machine A, 3 CPUs free Machine A 3 CPUs free Machine B, 3 CPUs free, FAILED, NOW Machine B 3 CPUs free silent FAILED Machine C, 3 CPUs free Machine C 3 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 3Step 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 for6Copies running6as askedStep 1 of 3: Machine B. Machine B stops sending heartbeats. Its power failed. Its 2 copies stopped with it.
Each machine sends a (A small "I am alive" message sent again and again at a steady interval, to show that a server or connection still works. The interval depends on the system: milliseconds in some, seconds in others.): 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.
An autoscaler changes the number
Orchestrator, keeps the count, NOW Orchestrator keeps the count NOW Machine A, 3 CPUs free Machine A 3 CPUs free 2 · 90% CPU Machine B, 3 CPUs free Machine B 3 CPUs free 2 · 90% CPU Machine C, 3 CPUs free Machine C 3 CPUs free 2 · 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 4Step 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
Copies6CPU per copy90%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
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
Interview
What interviewers look for
- Say "N copies behind a (A server that receives every request first and passes each one to one of several servers behind it.), 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 (Keeping no memory of earlier requests. Each request carries what the server needs, so any copy of the server can answer it.), 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?
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
Apply it
Judge a design
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.
- Official docsOverviewKubernetes documentationWhat an orchestrator does: placing containers, restarting them, and rolling out changes.
- Official docsHorizontal Pod AutoscalingKubernetes documentationThe formula the autoscaler uses to pick a pod count from a metric.
- Research paperLarge-scale cluster management at Google with Borg (2015)Verma et al., EuroSysThe system that Kubernetes learned from, and the lessons Google drew from it.