Design a Container Orchestrator
Understanding the Problem
🚢 What is a container orchestrator? A container orchestrator runs containers across a cluster of machines on your behalf. You say "keep five copies of this image running, each with 1 CPU and 2 GB of memory," and it picks machines, starts the containers, restarts them when they crash, moves them when a machine dies, and swaps them for a new version without downtime. Kubernetes is the best-known one; Nomad, Docker Swarm, and Borg inside Google are others.
The question usually arrives as "design Kubernetes." Your interviewer doesn't want a tour of every Kubernetes feature. They want to see you derive the few ideas that make it work: declarative desired state in a consistent store, controllers that reconcile actual state toward it, and a scheduler that places work. If you already know Kubernetes well, use the names, but explain why each piece exists. (For what Kubernetes itself looks like as a tool, see Kubernetes.)
Functional Requirements
Core Requirements
- Users should be able to declare an application (container image, number of replicas, CPU and memory needs) and have the system keep it running.
- The system should place each container on a machine that has room for it and satisfies its constraints.
- The system should replace containers that crash and reschedule them when a machine fails.
- Users should be able to update an application to a new version with a rolling update, without downtime.
Below the line (out of scope)
- Building images and the image registry.
- Persistent volumes and storage drivers (we'll mention them only where they affect correctness).
- Multi-cluster federation.
Non-Functional Requirements
Ask about cluster size. We'll target a large single cluster: 5,000 nodes running 150,000 containers. (Those are, not by coincidence, around the largest sizes Kubernetes officially supports.)
Core Requirements
- Cluster state must be strongly consistent. Two components must never both believe they own the same container or the same slot on a node.
- The control plane should be highly available: losing any one machine, including a control plane machine, shouldn't stop the cluster.
- Running workloads should keep running if the control plane is down. A control plane outage should freeze changes, not kill applications.
- After a node dies, its containers should be running elsewhere within a few minutes.
- The scheduler should place on the order of 100 containers per second, so a big deploy or a lost rack recovers quickly.
Below the line (out of scope)
- Hard multi-tenant isolation between hostile tenants (that's a sandboxing problem: gVisor, Kata, microVMs).
- Real-time placement guarantees.
Back-of-the-envelope. Every object in the cluster (each container group, node, application spec) is a few KB of JSON. 150,000 containers plus specs, nodes and endpoints is a few hundred thousand objects × ~5 KB ≈ 1-2 GB of state. That fits in memory on one machine.
Writes are modest too. 5,000 nodes heartbeating every 10 seconds is 500 writes per second; container status changes add a few hundred more on a normal day and a few thousand during a big rollout. The hard part is reads: dozens of components (the scheduler, controllers, 5,000 node agents, network proxies on every node) all need to know about changes, quickly. If each polled the full state every second, we'd be serving 5,000 × 1 GB per second.
The state is small; the audience is big. That observation drives two of the key design choices: a single strongly consistent store (it fits), and a watch-based API where components get pushed changes instead of polling.