KatInterview

Design a Multi-Cloud GPU Fleet Manager CLI

System DesignModel answer
MediumModel answerSystem Designclistate-managementidempotency

Last updated

Design the architecture and reconciliation logic for a CLI tool that provisions and manages GPU VMs across heterogeneous cloud providers.

Scenario

Your team operates GPU workloads across several cloud providers. Each provider has its own API, its own quirks, and its own way of reporting instance state. Engineers are spending too much time writing one-off scripts and reconciling drift between what they asked for and what's actually running.

You've been asked to design a command-line tool called cloudgpu that gives users a single, consistent interface to manage GPU VM fleets regardless of the underlying provider.

The core command to support is:

cloudgpu fleet --gpu A100 --count 5 --region us-east-1

What You Need to Design

1. Provider interface

Define a minimal abstraction so that new cloud providers can be added without touching the CLI or core reconciliation logic. What operations does every provider need to expose? How do you register providers and dispatch to the right one?

2. Desired-state reconciliation

The fleet command is declarative: --count 5 means "I want 5 running instances," not "give me 5 more." Describe the read-plan-apply loop that bridges desired state and actual state. Your design must handle:

  • Running the same command twice without creating duplicates.
  • Recovering cleanly if the process crashes mid-provisioning.

3. State persistence

You have a local state.json available for persistence. Explain what you store there, how you keep it consistent, and what happens if it becomes stale or corrupt.

Expected CLI Behavior

# First invocation — nothing running yet
$ cloudgpu fleet --gpu A100 --count 2
[INFO]  Pool us-east-1/A100 — desired: 2, actual: 0 → provisioning 2
[OK]    2 instances running (vm-a1b2, vm-c3d4)

# Scaling up — 2 already healthy
$ cloudgpu fleet --gpu A100 --count 3
[INFO]  Pool us-east-1/A100 — desired: 3, actual: 2 → provisioning 1
[OK]    3 instances running (vm-a1b2, vm-c3d4, vm-e5f6)

# Idempotent re-run — nothing to do
$ cloudgpu fleet --gpu A100 --count 3
[INFO]  Pool us-east-1/A100 — desired: 3, actual: 3 → no change
[OK]    3 instances running

Edge Cases to Address

  • A provider returns a rate-limit error during provisioning. How does your tool respond?
  • One out of two requested VMs fails to boot. What does your tool do with the healthy one, the failed one, and the reported exit state?

Hints

Hint 1

Think about where the authoritative view of running instances lives. If state.json gets corrupted or deleted, can your tool still recover? What makes that possible?

Hint 2

Idempotency under crashes is the hard part. Before you call a provider API, what do you need to write to disk — and what property must the provider support — so that a crash between 'API called' and 'result recorded' doesn't leave a phantom VM?

Hint 3

For edge cases, separate the concerns: rate limits are a retry problem, partial boot failures are a convergence problem. You don't need to roll back healthy instances — running the command again should be enough to reach the desired state.