Design a Cloud-Based Development Workspace Service
System DesignModel answerLast updated
Build a system that provisions on-demand containerized development environments with browser-based editing, terminal access, and port forwarding.
You're tasked with designing a service that provisions remote development workspaces in the cloud. Engineers should be able to spin up a fresh workspace from a Git repository, write and run code through a web interface, access running services via their browser, then pause and later restart the workspace without losing their work.
Core Requirements
The system must support:
- Launching a workspace from any Git repository and branch
- Providing a browser-based code editor and shell
- Running arbitrary processes (compilers, test runners, web servers) inside the workspace
- Exposing running services so they're reachable from the engineer's browser
- Pausing a workspace and resuming it later with all files preserved
Engineers will execute untrusted code—builds, scripts, local servers—so isolation is critical.
Scope and Assumptions
- The platform serves thousands of concurrent workspaces across multiple cloud regions
- Workspace launch should complete in under 60 seconds; resume should be faster
- Offer multiple machine sizes (2 CPU / 4 GB up to 16 CPU / 64 GB)
- Repositories may include a configuration file declaring the base image, install steps, and tooling
- Browser access only; desktop editor integration is out of scope for now
- Paused workspaces are retained for 30 days; running workspaces are billed per minute
- Multi-user collaboration is deferred
Focus on architecture, isolation strategy, storage durability, startup performance, secure network access, and cost management.
Hints
Hint 1
Think about how you'll isolate untrusted workloads and what trade-offs each approach brings
Hint 2
Consider what parts of a workspace must survive a stop-start cycle and where that state lives
Hint 3
Fast startup often means preparing assets ahead of time or keeping capacity warm
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
High-Level Architecture
Split the system into two planes:
Control Plane: Handles API requests (create, stop, resume workspace), authenticates users, manages workspace metadata and lifecycle, and schedules workspaces onto available capacity.
Data Plane: Runs the actual workspace containers, hosts the in-browser editor backend and terminal proxy, and handles port forwarding for user services.
A typical flow: user requests a workspace for repository X; control plane checks for a stopped workspace or creates a new record, picks a data-plane node with capacity, provisions storage, and instructs that node to launch the container; data plane pulls the image, mounts storage, starts the container, and reports ready; control plane returns a URL to the browser IDE.
Isolation Model
Each workspace runs untrusted code, so strong isolation is essential. The practical choice is one container per workspace, orchestrated by Kubernetes or a custom container runtime.
- Containers with a hardened runtime (gVisor, Kata Containers) add a layer of defense by intercepting syscalls or running containers in lightweight VMs. gVisor offers near-native performance with a userspace kernel; Kata gives stronger isolation at the cost of memory overhead and slower startup.
- Nested virtualization (each workspace in its own VM) maximizes isolation but increases resource overhead and boot time, making sub-60-second starts harder.
A reasonable default: standard container isolation with seccomp, AppArmor, and resource limits (CPU, memory, disk I/O quotas) to prevent noisy neighbors, plus gVisor for workspaces that request extra isolation.
Workspace Storage and Durability
Developers expect their code, installed dependencies, and shell history to survive a stop-resume cycle and node failures.
Persistent volume per workspace: Attach a block volume (EBS, persistent disk) to the container and mount the home directory there. When the workspace stops, detach the volume; on resume, reattach to the new container. Volumes are region-local and survive node failure.
Snapshot and restore: On stop, trigger an async snapshot of the volume; on resume, provision a new volume from the latest snapshot if the original is unavailable. Snapshots also enable cloning a workspace or rolling back to a known state.
Metadata storage: Store workspace records (user, repo URL, branch, machine size, volume ID, state) in a managed relational database (PostgreSQL). Each workspace row tracks its lifecycle state: PROVISIONING → STARTING → RUNNING → STOPPING → STOPPED → DELETED.
Trade-off: Block volumes add cost and attach latency. An alternative is a network filesystem (NFS, EFS) shared across nodes, which simplifies resume but introduces a single point of contention and potential performance bottleneck under heavy I/O.
Fast Startup
Target: new workspace ready in under 60 seconds, resume in under 30.
Layer caching: Preload common base images (Ubuntu + Node, Python + pip, etc.) on every data-plane node. Use a registry mirror or pull-through cache to avoid repeated downloads.
Prebuilt environment images: When a repository includes a config file (e.g., .devcontainer.json), the control plane can trigger a build of that image after the first use and cache it. Subsequent launches for the same repo pull the prebuilt image, skipping install steps.
Warm pools: Maintain a small pool of pre-provisioned containers with attached blank volumes. When a user requests a workspace, clone the repo into a warm container instead of cold-starting. Replenish the pool in the background. This cuts startup to under 20 seconds but increases idle resource cost.
Resume optimization: Stopped containers keep their volume attached but paused. Resume can unpause the container instead of reattaching the volume, shaving seconds off the path.
Secure Connectivity
Users access the editor, terminal, and forwarded application ports over HTTPS. The challenge: workspaces run inside a private network, and each user's session must be authenticated.
Authenticated gateway: Deploy a gateway (NGINX, Envoy, or custom proxy) at the edge. Users connect to https://workspace-abc123.platform.dev. The gateway checks a signed JWT in the cookie or header, extracts the workspace ID, looks up the data-plane node and container IP from the control plane, and reverse-proxies the request.
Port forwarding: When the user starts a server on port 3000 inside the workspace, the platform exposes it at https://workspace-abc123-3000.platform.dev. The gateway routes by subdomain, forwarding to the container's port. Use WebSocket upgrades for long-lived connections.
Alternative: per-workspace tunnels: Each container runs a lightweight tunnel client that maintains a persistent connection to the gateway. Requests arrive at the gateway, which routes them through the tunnel to the container. This avoids exposing container IPs and simplifies firewall rules, but adds tunnel overhead.
Access control: Verify the requesting user owns the workspace before proxying. Expire sessions after inactivity and rotate JWTs.
Cost Control
Running workspaces consume CPU, memory, and storage. Idle workspaces waste money.
Idle detection: Track inactivity (no terminal input, no HTTP requests, no processes spawned) for 30 minutes. Automatically stop the workspace and notify the user. Offer a "keep alive" button or API for long-running builds.
Retention limits: Delete stopped workspaces and their volumes after 30 days. Warn users a week before deletion and offer an extension or snapshot export.
Right-sizing: Let users pick machine size at creation. Default to the smallest. Monitor CPU and memory usage; suggest downsizing if utilization is consistently low.
Spot instances for data plane: Use preemptible VMs for non-production workspaces with clear warnings. Save 60–80% on compute. Checkpoint workspace state frequently and migrate to stable capacity if preempted.
Capacity Scheduling and Failure Handling
Scheduling: The control plane maintains a registry of data-plane nodes and their available capacity (CPU, memory, disk). When provisioning a workspace, pick a node with sufficient headroom using bin-packing or spread strategies. Update capacity after each placement.
Autoscaling: Monitor aggregate capacity utilization. Scale the data-plane node pool when utilization exceeds 70% for 5 minutes. Scale down when it drops below 30%, draining nodes gracefully by stopping workspaces first.
Node failure: If a node becomes unreachable, mark all workspaces on it as UNKNOWN. Attempt to resume each on a different node by reattaching its volume. Persistent volumes survive node loss; in-memory state (unsaved editor buffers) is lost. Encourage users to save frequently or enable auto-save.
Container crashes: If the workspace container exits unexpectedly, restart it once; if it crashes again within 5 minutes, mark the workspace FAILED and alert the user.
Observability
Track key metrics:
- Time to ready (p50, p99) for new and resumed workspaces
- Active workspace count, grouped by machine size and region
- Idle workspace count and auto-stop rate
- Volume attach/detach latency and snapshot duration
- Gateway request rate, error rate, and latency per workspace
Emit structured logs for every lifecycle transition. Trace a workspace launch end-to-end to identify bottlenecks (image pull, volume attach, git clone).
Common Pitfalls
- Underestimating isolation needs: Containers share the host kernel. A kernel exploit can compromise the node. Defense in depth (gVisor, tight seccomp profiles, resource limits) mitigates this.
- Ignoring storage I/O limits: A single workspace doing heavy disk writes can starve others on the same node. Enforce IOPS quotas per volume.
- Leaking stopped workspaces: Without retention limits, storage costs grow unbounded. Automate cleanup and notify users.
- Exposing internal ports without auth: Every forwarded port must verify the user's identity. Otherwise, any user can probe another's workspace.
Summary
A strong design separates control and data planes, isolates workspaces in containers with optional sandboxing, persists state to durable block volumes with snapshots, optimizes startup with image caching and warm pools, secures access via an authenticated gateway with port forwarding, and controls cost through idle detection and retention policies. Capacity scheduling, autoscaling, and observability ensure the platform handles failures gracefully and scales with demand.