Build a Remote Development Workspace Platform
System DesignModel answerLast updated
Architect a service that provisions isolated development environments accessible via SSH, with persistent storage, scheduled automation, and fault tolerance.
Problem
You're tasked with architecting a platform that provides remote development environments. Engineers can provision personal workspaces, connect to them securely over SSH, and run automated background jobs. The platform must ensure data safety, user isolation, and graceful recovery from infrastructure failures.
Requirements
Core Functionality
- Provision and terminate development environments on demand
- Secure remote access via SSH to individual environments
- Background job scheduling (build automation, testing, linting) with cron-like syntax
- Filesystem persistence across power cycles and network interruptions
Quality Attributes
- Fault Tolerance: Environment data must survive host crashes; workspaces should relocate to healthy infrastructure automatically
- Security: Strong isolation preventing users from accessing the host system or other users' environments
- Responsiveness: SSH connections should establish quickly, both initially and when reconnecting
- Resource Management: Enforce per-user limits on CPU, memory, and storage to prevent monopolization
What to Deliver
- System architecture showing major components and their interactions
- API design for workspace lifecycle and job scheduling
- Data persistence strategy including schema for environments, users, jobs, and execution history
- SSH authentication and routing mechanism with security considerations
- Failure recovery approach: detection, data protection, and workspace migration strategy
Consider scale, concrete trade-offs, and failure modes in your design.
Hints
Hint 1
Think about the isolation boundary: containers share kernels, but users may need root access
Hint 2
Network-attached storage separates compute from state, enabling mobility
Hint 3
Certificate-based SSH with short lifetimes avoids long-lived credentials
Hint 4
Use generation numbers or fencing tokens to prevent split-brain when relocating workspaces
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer: Remote Development Workspace Platform
1. Requirements Clarification and Scale
Start by establishing concrete numbers:
- User base: 100,000 registered developers, ~20,000 concurrent active environments at peak, ~150,000 total environments (including dormant)
- Resource profile: Default allocation of 4 CPU cores, 16 GB RAM, 50 GB persistent disk per environment
- Infrastructure: With 64-core hosts and overhead, approximately 14 environments per machine = ~1,500 hosts at peak
- Storage capacity: 150k environments × 50 GB = 7.5 PB provisioned (actual usage lower with thin provisioning)
- Performance goals:
- SSH connection to running environment: <1s
- Reconnection: <1s
- Cold start from stopped state: <20s
- Durability: Zero data loss for fsync'd writes on host failure; RPO of a few minutes on zone failure via snapshot backups
Key clarifications:
- Do users need root privileges inside environments? (Impacts isolation approach)
- Must scheduled jobs execute even when users are disconnected? (Affects lifecycle management)
2. API Design
POST /api/environments {name, base_image, tier, region} → {id, status}
GET /api/environments/{id} → {status, location, ssh_target, resource_usage}
POST /api/environments/{id}/start
POST /api/environments/{id}/stop
POST /api/environments/{id}/hibernate
DELETE /api/environments/{id} (optional final snapshot before deletion)
POST /api/ssh/credentials {env_id, public_key} → {certificate, expiry}
POST /api/environments/{id}/jobs {schedule, command, timeout_sec, wake_on_schedule}
GET /api/environments/{id}/jobs → [{job_id, schedule, enabled}]
DELETE /api/jobs/{job_id}
GET /api/jobs/{job_id}/executions → [{exec_id, status, started, exit_code}]
GET /api/executions/{exec_id}/logs?stream=true
All state-changing operations accept an Idempotency-Key header for safe retries.
3. Data Model
Control plane uses a distributed SQL database (Postgres with sharding, or Spanner), partitioned by user_id:
- users (id, organization, cpu_quota, memory_quota, disk_quota, tier)
- environments (id, owner_id, base_image, tier, desired_status, actual_status, disk_id, host_id, epoch, last_active, created)
- disks (id, env_id, availability_zone, size_gb, attached_to_host, attach_epoch, latest_snapshot)
- hosts (id, zone, total_capacity, allocated_capacity, heartbeat_lease, health_status)
- jobs (id, env_id, schedule_expression, command, timeout_sec, next_execution, enabled)
- executions (id, job_id, scheduled_time, attempt_number, outcome, exit_code, log_location, started, completed)
- ssh_connections (id, user_id, env_id, cert_fingerprint, gateway_id, established, terminated)
Critical fields:
- desired_status vs actual_status drives reconciliation loops
- epoch is a monotonic counter incremented on every placement change, used for fencing
Logs stream to object storage, not the transactional database.
4. Architecture Overview
User SSH → Load Balancer → SSH Gateway Fleet → Environment SSH daemon
↓ (route resolution) ↑
API/CLI → Control Plane → State Reconciler → Host Agent (on compute nodes)
↓ ↓
Metadata DB Job Scheduler → Task Queue → Host Agent
Log Collector → Object Storage
Storage: Network block volumes (cloud EBS, Ceph RBD), zone-scoped, with snapshot capability
Compute Layer:
- Orchestrate environments as lightweight VMs (Firecracker, Kata Containers) rather than Docker containers
- Rationale: Users need root, which requires kernel-level isolation. Standard containers share the host kernel.
- Resource limits: cgroups for CPU/memory, storage IOPS throttling, namespace quotas for total user consumption
Storage Architecture:
- Root and home filesystems live on network-attached block devices
- Decoupling compute from storage enables workspace migration
- Hosts maintain only a local cache of base images (loaded lazily via content-addressed layers)
- Enables fast cold starts while preserving user state
Host Agent: Runs on each compute node, responsible for heartbeats, volume attachment, VM lifecycle, job execution, and log forwarding.
5. SSH Authentication and Routing
SSH lacks SNI, so routing uses the username field: ssh [email protected]
Certificate-Based Authentication:
- User authenticates to control plane via SSO (OIDC + MFA)
- Local CLI tool generates a keypair and calls
/api/ssh/credentialswith the public key - Internal CA signs a short-lived certificate (8-12 hour validity) containing user identity and authorized environment IDs as extensions
- User's SSH client trusts the gateway's host certificate authority via
@cert-authorityin known_hosts (eliminates trust-on-first-use warnings)
Gateway Connection Flow:
- Verify: Check certificate signature, expiration, and revocation status (using cached revocation bloom filter)
- Authorize: Validate user owns or has access to requested environment
- Route: Query environment's current host location from cache (short TTL, invalidated on epoch changes)
- If environment is stopped, trigger start operation and display progress to user
- Tunnel: Establish mTLS connection to environment's SSH daemon over private network overlay
- Gateway authenticates using dynamically issued internal certificate
- Environment SSH daemon only trusts internal CA, never user keys directly
- User private keys never leave their machine; environments never expose public endpoints
- Bridge: Proxy the connection, logging metadata and optionally keystrokes for compliance
Security Measures:
- Micro-VMs with seccomp profiles, no host filesystem mounts
- Network policies block inter-environment and metadata service access
- Outbound traffic routed through NAT/filtering proxy
Performance:
- Gateway instances deployed in all regions with anycast addressing
- Connection routing cached, persistent connection pools to hosts
- Reconnections only require handshake replay (~1 RTT + crypto), recommend tmux/mosh for session persistence
6. Host Failure Handling
Detection Phase:
- Host agents renew a lease every 10 seconds
- After ~3 missed renewals (30s), reconciler marks host as SUSPECT
- Cross-validate with secondary signal: cloud provider instance API or peer health probe from same availability zone
- Reduces false positives from network partitions
Fencing (Critical): This prevents split-brain data corruption if a partitioned host continues writing:
- Force-detach the disk via storage API
- Increment environment epoch in database
- Storage layer and host agents reject all operations with stale epochs
- With Ceph: use RBD exclusive locks with client blacklisting
- If partitioned host recovers, agent observes epoch mismatch and immediately kills the VM
Recovery:
- Select healthy host in same availability zone (block volumes are zone-bound)
- Attach disk with new epoch
- Run filesystem journal replay if needed
- Boot VM and restore network routes
- Update gateway routing cache
Cross-Zone Disaster Recovery:
- Periodic snapshots to object storage (zone-independent)
- RPO determined by snapshot frequency (typically 15-30 minutes)
- RTO includes snapshot restore and cold start (~2-3 minutes)
7. Job Scheduling
Scheduler Component:
- Periodic sweep finds jobs with
next_execution ≤ now - Enqueues execution tasks with idempotency keys
- Updates
next_executionbased on cron expression - Handles misfires (late execution): either skip, run once immediately, or run all missed
Execution Flow:
- Task dequeued by host agent where environment resides
- If environment stopped and job configured to wake: start environment first
- Execute command in environment context (via VM guest agent or SSH)
- Stream logs to collector, record exit code
- Retry on transient failures (host crash), respect timeout limits
8. Trade-offs and Alternatives
VM vs Container Isolation:
- Chose VMs (Firecracker/Kata) for security with root access
- Trade-off: Higher memory overhead (~125MB per VM), slightly slower cold starts
- Alternative: Rootless containers + gVisor could reduce overhead but with performance penalty
Network vs Local Storage:
- Chose network block devices for migration capability
- Trade-off: I/O latency (~1ms vs microseconds for local NVMe)
- Mitigation: Use NVMe-backed networked storage, local read caching
Certificate vs Key-Based SSH:
- Certificates with short expiry reduce credential exposure
- Trade-off: Requires CA infrastructure, clock synchronization critical
- Benefit: Centralized revocation, no authorized_keys management
Synchronous vs Eventual Consistency:
- Workspace placement uses strong consistency (database)
- Trade-off: Slower under network partitions
- Rationale: Prevents double-allocation and split-brain bugs
9. Common Pitfalls
- Forgotten fencing: Allowing stale hosts to write causes corruption
- Ignoring clock skew: Certificate validation breaks with drift >5 minutes
- Insufficient connection pooling: Gateway-to-host connections become bottleneck
- Missing idempotency: Retried API calls create duplicate environments
- Inadequate logging: Distributed debugging impossible without correlation IDs
- Over-provisioning: Network storage IOPS limits hit before capacity
This design prioritizes correctness (fencing, data durability) and security (isolation, certificate auth) while maintaining acceptable performance through caching, co-location, and asynchronous operations where possible.