Infrastructure Scaling, Capacity Planning, and High Availability Questions
Making infrastructure grow and stay up: horizontal and vertical scaling, autoscaling, load balancing, capacity planning and forecasting, and high-availability and redundancy design. Covers sizing systems for demand, distributing load, and eliminating single points of failure so services remain available as they scale. The reliability-and-growth discipline.
Explain how you would measure and attribute performance regressions caused by an infrastructure migration (for example moving training workloads from on-prem GPUs to a cloud provider). Describe experiments, statistical tests (A/B, canary), baseline metrics, and how to control for confounders like dataset differences or hyperparameter drift.
Sample Answer
Situation: We’re migrating training workloads from on‑prem GPUs to a cloud provider and need to detect any performance regressions (model quality, training time, cost, stability) and attribute root causes.
Approach overview:
- Define baseline metrics
- Model metrics: validation loss, accuracy, AUC, calibration, convergence steps/epochs
- System metrics: per‑step time, GPU utilization, memory, I/O throughput, network latency, job wallclock, cost per epoch
- Stability metrics: variance across runs, failure/retry rates
- Experimental design
- Canary/parallel runs: run identical training jobs simultaneously on on‑prem (control) and cloud (treatment) with identical code, container, data snapshot.
- A/B with replication: run N independent seeds per environment (N based on power calculation) to capture run variance.
- Paired experiments: if same random seeds possible, run paired comparisons to reduce variance.
- Statistical tests & thresholds
- For scalar model metrics: use paired t‑test if differences normal; otherwise Wilcoxon signed‑rank. Report effect size and 95% CI via bootstrap.
- For non‑inferiority/equivalence: use pre‑defined delta (e.g., ≤0.2% accuracy drop acceptable) and run equivalence test (TOST) or one‑sided tests.
- For performance (time/cost): use bootstrap CIs and Mann‑Whitney if skewed; test throughput distributions (KS test) for shape changes.
- Correct for multiple comparisons (Benjamini‑Hochberg) when testing many metrics.
- Controlling confounders
- Data: use identical snapshot and deterministic preprocessing; validate no silent data drift (KS/MMD tests on features).
- Hyperparameters: pin exact hyperparameters, random seeds, CUDA/cuDNN versions, mixed‑precision settings. If cloud hardware differs, run a controlled hyperparameter sweep on both to detect interactions.
- Software stack: use same Docker images/binaries; log library versions.
- Warm‑up & caching: discard first few epochs/steps to avoid cold‑start bias.
- Resource variance: control instance types (GPU model), isolate noisy neighbors by using dedicated instances or repeat experiments to average variance.
- Attribution workflow
- Correlate metric changes with system counters (e.g., higher I/O wait → slower step time). Use causal steps:
a) Observe metric delta significant by test above.
b) Check system metrics timeline and per‑step traces; identify correlated anomalies.
c) Reproduce with microbenchmarks (memory copy, disk, NCCL all‑reduce) to isolate subsystem.
d) If hypothesis matches, run targeted fix and rerun A/B to confirm regression resolved.
- Automation & practials
- Automate runs with CI job orchestration, standardized logging (structured traces, Prometheus/Cloud metrics), and artifact capture (model checkpoints).
- Predefine SLOs and rollback criteria (e.g., accuracy drop > delta or training time > x%).
- Ensure sample size/power planning up front; log raw outputs for post‑hoc analysis.
This combination of controlled parallel experiments, robust statistical testing (including non‑inferiority/equivalence), strict environment reproducibility, and system‑level profiling yields reliable detection and attribution of migration‑caused regressions.
Create a strategy and test plan to compress model artifacts stored in a model registry and measure trade-offs between storage savings and retrieval latency for 100k downloads per month. Include compression formats, partial loading strategies, caching layers, and capacity planning for metadata DB and storage tiers.
Sample Answer
Strategy overview:
- Goal: minimize long-term storage cost for ~100k downloads/month while keeping cold-to-warm retrieval latency within SLO (e.g., median ≤200ms, p95 ≤800ms).
- Approach: tiered storage + hybrid compression + partial-loading + multi-layer cache + metadata optimization.
Compression formats and when to use:
- Gzip (DEFLATE): best for small artifacts (source, pickles) — fast decompression, good ratio.
- Zstd (level 3-6): balanced speed/ratio for medium artifacts (torch .pt, TF SavedModel). Use level ~3 for fast retrieval, level ~6 for max savings in cold tier.
- LZ4 / Snappy: minimal CPU cost for frequently downloaded artifacts (top 10% hottest).
- Delta/quantization + model-specific formats: for large checkpoints, store a base checkpoint + deltas (binary diffs) and optionally quantized variants (int8) for inference-only use.
Partial loading strategies:
- Sharded artifacts: store model weights in chunked files (e.g., 64MB blobs) so only required shards are retrieved.
- Index file (small, JSON/BSON): maps model logical layers → shard IDs + byte ranges, enabling range GETs from object storage.
- Lazy loader in client SDK: fetch metadata and only download shards required for warm-start or for specific model submodules.
Caching layers:
- CDN in front for public/low-latency access (edge caching).
- Warm cache: Redis/Memcached for metadata and small artifacts; S3-compatible gateway cache for hot shards.
- Local node cache on serving clusters (LRU, size per node based on memory budget).
Metadata DB and storage tiers capacity planning:
- Metadata DB (Postgres/managed cloud): estimate 100k downloads/month → ~3.3k/day. For 1M artifacts, assume 1KB metadata each → ~1GB raw; provision 4–8GB DB with IOPS headroom. Indexes for lookup (artifact_id, version, tags) and TTL for temp entries. Plan for 99.99% availability and read replicas for scaling.
- Storage tiers:
- Hot (SSD-backed object store / block): top 10% hottest shards; size ≈ 0.1 * total compressed size.
- Warm (standard object storage): next 40%.
- Cold (archive, Glacier-like): remaining 50% with async retrieval.
- Throughput: expect peak concurrent downloads (~100k/month → ~70 req/min average; peak assume 10x → 700 req/min). Ensure object storage egress and IOPS accommodate concurrent shard GETs; design for 1000 concurrent connections.
Test plan & trade-off measurement:
- Baseline: measure uncompressed retrieval latency and storage footprint for representative artifact set (small, medium, large).
- Compression matrix: for each format/level, measure compression ratio, CPU cost (decompress/ms per MB), end-to-end retrieval latency (including object GET + decompress), and memory overhead.
- Partial-load scenarios: measure latency when requesting 1 shard, 10% of shards, full model.
- Cache effectiveness: simulate access patterns (Zipf with configurable hot-set size). Measure hit rates, upstream storage bandwidth, and end-to-end latency with and without caches.
- Load test: generate 100k downloads/month traffic profile with realistic bursts, measure SLO attainment, CPU, network, and storage costs.
- Cost-latency trade-off analysis: compute $/GB-month + egress + CPU decompression vs median/p95 latency. Plot Pareto frontier to pick compression levels per tier.
- Failure and recovery: test partial shard unavailability, metadata DB failover, and cold-tier retrieval latency (hours vs minutes).
Decision rules:
- Keep hot artifacts LZ4/uncompressed if latency-critical and top 5–10% traffic.
- Use Zstd level 3 for warm tier to balance cost and latency.
- Archive with max compression for rarely-used artifacts; provide async restore with notifications.
- Sharding + index always enabled for large models to minimize transfer.
Instrumentation:
- Collect metrics: artifact size (orig/compressed), compress/decompress time, shard GET latency, cache hit/miss, DB read latency, egress bytes.
- Alert on SLO breaches and increase hot-tier promotion when hit rate > threshold.
This plan balances storage savings against retrieval latency with measurable experiments to choose per-artifact policies.
You must reduce inference cost per request by 30% without degrading accuracy beyond an agreed threshold. Propose a prioritized action plan including model-level changes (e.g., distillation), serving optimizations (batching, caching), and infra changes (right-sizing, spot). Explain how you would measure and validate the impact of each step.
Sample Answer
First, establish a clear baseline and constraints:
- Baseline: current cost/request, P50/P95 latency, throughput, and accuracy metrics (e.g., AUC, F1) with 95% CI.
- Constraint: ≤30% cost reduction and accuracy degradation ≤ agreed delta (e.g., ≤0.5% absolute or non-inferiority margin).
- Set KPIs: cost/request, latency SLA, error rates, and business metric impact.
Priority action plan (fast → higher effort), with validation for each:
- Measurement & Canary setup (day 0)
- Implement per-request telemetry (cost attribution), and canary/A-B framework.
- Validate: reproduce baseline metrics in canary; ensure monitoring and alerting.
- Serving optimizations — software quick wins (low risk, high ROI)
- Enable request batching and async inference; tune batch size and concurrency.
- Add result caching for repeated inputs (TTL-based).
- Use efficient model runtime (ONNX, TensorRT, TorchScript).
- Expected impact: 5–15% cost reduction.
- Validate: run load tests comparing cost/throughput and P95 latency; ensure accuracy unchanged. Canary 10–20% traffic, compare metrics vs control using statistical tests.
- Model-level cheap optimizations (medium risk)
- Post-training quantization (INT8) and weight pruning with small accuracy checks.
- Knowledge distillation to a smaller architecture (student model) if quantization insufficient.
- Expected impact: 10–25% cost reduction (depends on model).
- Validate: offline eval on holdout + slice tests; deploy student model in canary; run A/B for business metrics, requiring non-inferiority with pre-specified sample size and significance.
- Architecture & batching at infra level (medium-high effort)
- Right-size instances (profiling CPU/GPU utilization); use smaller/more efficient instance types or infer on CPUs for small models.
- Adopt autoscaling and request-level concurrency tuning to maximize utilization.
- Expected impact: additional 5–15%.
- Validate: cost simulations + staged rollout; check latency percentiles under real traffic.
- Spot/preemptible + capacity planning (cost-focused, higher risk)
- Use spot/ preemptible instances with checkpointing and multi-zone fallbacks; keep a small reserved pool for critical low-latency paths.
- Implement graceful degradation (fallback to smaller model or cached responses) on preemption.
- Expected impact: 10–40% on infra VM costs.
- Validate: controlled experiments with induced preemptions; ensure SLOs hold and measure failover cost/latency.
- Longer-term model redesign (highest effort)
- Retrain with efficiency-aware objectives (latency-aware NAS, sparsity regularization), or switch to fundamentally cheaper architectures.
- Consider multi-model routing (cheap model first, escalate to expensive only when uncertain).
- Validate: rigorous offline + online experiments, phased rollout.
Measurement & validation principles:
- Use AB/canary with power calculations (sample size) to detect accuracy deltas and latency regressions.
- Track cost/request decomposition (compute, memory, network).
- Maintain rollback thresholds (e.g., >X ms P95 increase or >Y% accuracy drop triggers rollback).
- Run longitudinal monitoring for model drift and cost variance.
Trade-offs & safeguards:
- Favor serving optimizations first (low risk). Model changes require stronger validation and rollback plans.
- Prioritize user-facing SLOs over raw cost.
- Keep experiment logs and reproducible pipelines so any successful optimization is codified.
Expected timeline: software optimizations (1–2 weeks), quantization/distillation (2–6 weeks), infra changes (1–4 weeks), model redesign (months). With this prioritized plan and rigorous validation, achieving a 30% cost reduction while protecting accuracy is realistic.
Describe strategies to scale a nightly data preprocessing pipeline that processes thousands of files: partitioning, map-reduce patterns, autoscaling worker pools, serverless vs managed batch services, and trade-offs among cost, latency, and operational complexity.
Sample Answer
Requirements & constraints:
- Nightly batch: process thousands of files within a fixed window (e.g., 4–8 hours).
- Input variety, idempotency, retryability, and downstream ML training deadlines.
- Targets: throughput, cost budget, acceptable latency, operational overhead.
High-level approach:
- Partition by file/key: split workload into independent shards (by prefix, date, or hash). Aim for many small tasks to allow parallelism but avoid tiny-task overhead.
- Map-Reduce pattern: Map stage = per-file extraction/feature computation (stateless, embarrassingly parallel). Reduce stage = aggregation (joins, feature aggregation) using keyed shuffles or a distributed engine.
- Execution engines: use a managed distributed framework (Spark on EMR/Dataproc, Dataflow) for heavy shuffles; or an autoscaling worker pool for map-only workloads.
Autoscaling worker pools:
- Use containerized workers (Kubernetes Job/CronJobs or managed batch like AWS Batch, GCP Batch) with horizontal autoscaling based on queue length / pending tasks.
- Prefer pull-based task queues (Cloud Pub/Sub, SQS) so workers scale with backlog and support retries.
Serverless vs managed batch:
- Serverless (Cloud Functions, Lambda, FaaS): low ops, good for many small, short tasks; cost can spike and cold starts/timeout limits constrain heavy CPU/memory.
- Managed batch/cluster (Spark, Dataflow, Batch): better for large data, heavy shuffles, in-memory processing, and cost-efficient for long jobs; higher operational complexity.
Trade-offs:
- Cost vs latency: more parallelism reduces latency but increases transient compute cost. Use spot/preemptible VMs for cost savings with checkpointing.
- Operational complexity vs control: serverless lowers ops but limits resources and debugging; managed clusters require more maintenance but give performance tuning.
- Fault tolerance: design idempotent tasks, checkpoint intermediate outputs to object storage, use retries and DLQs.
Monitoring & reliability:
- Track per-file success, task lag, CPU/memory, shuffle bytes, and cost. Implement end-to-end SLA alerts and automated retries with exponential backoff.
Example flow:
- Ingest files to object store → scheduler enqueues tasks by shard → autoscaled worker pool runs map jobs (write partial features) → managed Spark job performs aggregations/reduce → write outputs to feature store for nightly training.
This design balances scalability, cost, and operational effort and can be tuned (task size, parallelism, spot usage) based on observed bottlenecks.
How do you define Service Level Objectives (SLOs) and error budgets for an ML inference endpoint? Provide concrete example SLOs (e.g., availability percentage, p95 latency threshold), show a simple formula for computing an error budget, and explain how the remaining error budget should influence capacity and incident response actions.
Sample Answer
Definition: An SLO is a measurable target for a service’s user-facing behavior (availability, latency, correctness) over a time window. An error budget = 1 − SLO and represents allowed unreliability that the team can "spend" for launches, changes, or degraded performance.
Concrete example SLOs for an ML inference endpoint (30-day window):
- Availability: 99.95% (allowed downtime = 0.05% → 21.6 minutes/month)
- Latency: p95 < 120 ms for successful inferences
- Accuracy/regression: model AUC drop ≤ 0.02 from baseline
Simple error-budget formula:
- Error budget (%) = 100% − SLO%
- Remaining budget at time t = Error budget − Observed error% over window
Example: SLO=99.95% → error budget 0.05%. If actual downtime this month = 0.02% → remaining = 0.03%.
How remaining error budget drives actions:
- Healthy budget (large remaining): safe to deploy risky changes, scale conservatively, run experiments.
- Low budget (near exhaustion): stop non-essential deploys, shift to conservative autoscaling (pre-warm nodes, increase replicas), enable degraded-mode fallbacks (cache responses, route to simpler model), increase monitoring and alerting sensitivity.
- Budget exhausted: treat as incident — trigger on-call, rollback recent changes, enable emergency capacity (scale up), communicate SLA impacts to stakeholders, and run postmortem to adjust SLOs or architecture.
Operational best practices:
- Track separate budgets per dimension (availability, latency, correctness).
- Measure errors by user-impacting events (timeouts, incorrect predictions above threshold).
- Tie error-budget policy to runbook actions (automated and human), and review SLOs quarterly as traffic and model accuracy evolve.
Unlock Full Question Bank
Get access to all 46 Infrastructure Scaling, Capacity Planning, and High Availability interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.