Architecture Documentation and Communication Questions
Making an architecture legible to others: architecture decision records, diagramming and visualization (C4, sequence, deployment diagrams), and communicating designs to technical and non-technical stakeholders. Covers capturing rationale, keeping docs current, and presenting a system clearly under time pressure. The communication skill that separates a good design from an understood one.
You inherit a monolithic model host that needs to be decomposed into microservices. Create a migration plan outline with phases, diagrams to produce at each phase (context/containers/components), risk mitigations, and minimal documentation requirements to keep stakeholders aligned during migration.
Sample Answer
Phase 0 — Assess & align (2–3 weeks)
- Activities: inventory models, data flows, infra, SLAs, owners, dependencies (feature store, training pipelines, batch jobs, A/B frameworks).
- Diagrams to produce: Context diagram (users, data sources, downstream consumers, monitoring systems).
- Risks & mitigations: hidden dependencies — run traffic logging & dependency tracing; unclear SLAs — run stakeholder workshop to capture KPIs.
- Docs: inventory spreadsheet, stakeholder RACI, SLA summary.
Phase 1 — Design & carve boundaries (2–3 weeks)
- Activities: identify candidate service boundaries (feature service, model inference, preprocessing, model registry, retraining), define API contracts, data contracts, auth.
- Diagrams: Container diagram (each proposed microservice, DBs, queues, model store).
- Risks: data contract mismatch — define schemas & backward-compatible changes; compute cost spikes — capacity planning.
- Docs: API contract docs (OpenAPI), data schema, deployment template examples.
Phase 2 — Strangler & pilot extraction (4–6 weeks)
- Activities: implement façade/proxy (routing), extract 1 non-critical model as microservice (inference + metrics), wire feature store access.
- Diagrams: Component diagram for extracted service (components: preproc, model server, cache, metrics).
- Risks: performance regression — performance budget tests, shadow traffic; prediction mismatch — run shadow/parallel inference and compare outputs.
- Docs: integration test plan, runbook for rollback, performance test results.
Phase 3 — Iterate & scale extraction (6–12 weeks)
- Activities: extract remaining services iteratively, introduce async queues for heavy preprocessing, standardize model packaging (container + model registry + CI/CD).
- Diagrams: Updated Container diagram showing async flows, scaling points, canary paths.
- Risks: consistency across services — enforce CI templates, linters; deployment drift — infra-as-code.
- Docs: CI/CD playbook, model packaging spec, API versioning policy.
Phase 4 — Cutover & decommission (2–4 weeks)
- Activities: route production traffic gradually (canary → 50% → 100%), monitor model performance, roll back if regressions.
- Diagrams: Context diagram showing final system and decommissioned components.
- Risks: downstream breakages — maintain compatibility layer for a sprint; data loss — snapshot data and replay tests.
- Docs: final runbook, service-level objectives, incident response plan.
Minimal documentation to keep stakeholders aligned (always kept current)
- Executive one-pager: goals, timeline, key risks & mitigation, owners.
- Technical contract docs: OpenAPI, data schemas, model registry API, auth.
- Runbooks: deploy, rollback, observability checklist (latency, error rates, prediction drift, throughput).
- Dashboards & alerts: model-quality metrics (AUC, bias metrics), latency, throughput, resource cost.
- Migration log: change history, dates of cutover, test results.
Key principles
- Use strangler pattern and shadow testing to avoid regressions.
- Automate CI/CD, tests (unit, integration, performance, model-equivalence).
- Keep data contracts strict and backward compatible; version models and features.
- Start with lowest-risk model to validate process; measure impact and adjust.
Create a concise template for an ML system architecture README that will be checked into the code repo. The template must capture: system purpose, key diagrams, owners, runbook link, SLOs, deployment steps, rollback steps, and known limitations. Provide example placeholders and explain how CI can validate the presence of this README.
Sample Answer
Suggested README: ML System Architecture Template
System Purpose
- Short description: What problem this system solves, primary inputs/outputs, and its consumers.
Example: "Real-time fraud scoring service. Inputs: transaction events; Outputs: risk score (0-1) to payments API."
Key Diagrams
- Architecture diagram: path/to/diagrams/arch.png
- Data flow diagram: path/to/diagrams/dataflow.png
- Model lifecycle diagram: path/to/diagrams/model_lifecycle.png
Owners
- Product owner: Name, email, team
- ML owner: Name, email, team
- Infra owner: Name, email, team
- On-call rotation: PagerDuty/Slack channel
Runbook
- Link: https://runbooks.example.com/ML-fraud-scoring
- Short summary: how to detect, mitigate, and escalate incidents
SLOs & Metrics
- Availability SLO: 99.9% per 30-day window
- Latency SLO: 95% requests < 150ms
- Model performance: ROC-AUC ≥ 0.92 (weekly evaluation)
- Monitoring endpoints: /metrics, /health
Deployment Steps
- Preflight: run unit tests, data schema checks, model validation
- Build: docker build -t repo/ml-fraud:v{version}
- Deploy: helm upgrade --install ml-fraud ./charts --set image.tag={version}
- Post-deploy: run smoke tests, model sanity checks
Rollback Steps
- Trigger: if smoke tests fail or SLO breach
- Steps: helm rollback ml-fraud <previous-release>; verify /health and metrics; open incident if rollback fails
Known Limitations
- Data skew window: model assumes stable feature distribution within 24h
- Latency caveat under burst traffic (>2000 rps)
- Unsupported input types: legacy_event_v1
CI Validation (how to enforce README presence)
- Simple CI check ensures README exists and contains required sections (case-insensitive headings).
Example GitHub Actions step:
name: Validate ML README
on: [push, pull_request]
jobs:
check-readme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Validate README
run: |
required=("System Purpose" "Key Diagrams" "Owners" "Runbook" "SLOs" "Deployment Steps" "Rollback Steps" "Known Limitations")
for r in "${required[@]}"; do
if ! grep -qi "^$r" README.md; then
echo "Missing section: $r" && exit 1
fi
done
echo "README validated"
Why this helps
- Consistent on-call readiness, faster incidents, clearer ownership, and automated gatekeeping via CI so every PR includes operational documentation.
Design the documentation and diagram approach for supporting edge deployments of ML models (e.g., mobile or on-prem routers): include update channels, rollback plans, telemetry collection (when connectivity is intermittent), and how to represent offline-first behavior and eventual reconciliation in architecture docs.
Sample Answer
Requirements & constraints:
- Edge targets: mobile apps, on-prem routers with intermittent connectivity, limited storage/CPU.
- Needs: safe updates (canary/staged/instant rollback), reliable telemetry with offline buffering, clear offline-first behavior and eventual reconciliation, security (signed artifacts), minimal latency for inference.
High-level architecture (ASCII):
Cloud CI/CD + Model Registry
|
Distribution Service (signed artifacts, channels)
|
Edge Device: Updater Agent ↔ Model Runtime ←→ App/Inference
| |
Telemetry Queue Local Metrics Store
| |
Persistent Buffer (disk)
↕
Reconciliation Engine (on cloud when connected)
Core components & responsibilities:
- Model Registry & CI/CD
- Store immutable model artifacts with metadata: model_id, version, checksum, semantic channel tag (canary/beta/stable), resource profile, rollback pointer.
- Automated tests: validation, performance, resource profiling.
- Distribution Service / Update Channels
- Channels: alpha (developer), canary (subset), stable. Channel controls set per device via targeting rules.
- Update package: delta-aware (binary diffs), signed, with manifest including pre/post hooks, min runtime version, and health-check probes.
- Staged rollout: percent-based, device-attribute targeting, time-windowed.
- Edge Updater Agent
- Verifies signature, validates checksum, applies update atomically (write-new-then-swap), keeps N most recent artifacts for rollback.
- Health checks: bootstrapping test dataset and smoke inferences; if fails, auto-rollback to previous version.
- Supports manual forced rollback and server-initiated rollback by sending a "retract" flag.
- Telemetry & Intermittent Connectivity
- Edge collects structured telemetry (inference counts, latency histogram, model confidence distribution, drift indicators, resource usage, failed inferences).
- Local durable queue: append-only, compressed, encrypted batches with sequence numbers and vector-clock-like versioning for events.
- Backoff upload strategy: exponential with jitter; when connected, stream prioritized summaries first (aggregates), then raw buffered logs.
- Telemetry schema includes device_id, model_id, model_version, timestamps (local + server-received), sequence numbers, and reconciliation_id.
- Offline-first & Reconciliation
- Document state machine: device maintains authoritative local decisions while offline; server eventual source-of-truth for model versions.
- Use idempotent operations: every update and telemetry batch has monotonically increasing sequence numbers and uniq batch IDs. Server deduplicates.
- Conflict handling: if local policy/decisions diverge (e.g., manual overrides on device), reconciliation rules prioritize local safety policies; model updates tagged incompatible are deferred until admin approval.
- Reconciliation flow: on re-connect, device sends delta summary (applied versions, telemetry aggregates, pending ops). Server validates, computes reconciled state, sends any required commands: accept update, force rollback, or patch.
Data flow summary:
- Push: Registry → Distribution → Updater Agent → Model Runtime.
- Telemetry: Runtime → Local Buffer → (on-connect) → Telemetry Ingest → Monitoring/Alerts + Model Evaluation.
- Rollback: Updater Agent triggers local rollback immediately on health failure or receives server rollback command.
Representation in docs (what to include & visuals):
- Sequence diagrams for update flow and rollback.
- State machine diagram showing device states: Idle, Downloading, Validating, Active, Degraded, RollingBack.
- Data model appendix: manifest schema, telemetry schema, batch format, sequence/clock semantics.
- Runbooks: rollback playbook (automatic vs manual), incident steps, thresholds for auto-rollback (e.g., >X% inference failures or latency >Y ms).
- Security & compliance section: signing, TLS, least privilege for update service, audit logs.
Operational details & metrics:
- Key metrics: update success rate, rollback rate, days-to-detect drift, telemetry delivery lag, inference accuracy drift.
- Alerts tied to thresholds; Canary windows with early stopping rules.
- Storage: keep last 2-3 model binaries; prefer deltas to reduce bandwidth.
Trade-offs:
- Delta updates save bandwidth but add complexity and failure modes — require robust validation and fallback.
- Keeping multiple versions increases storage but dramatically improves rollback safety.
- Aggressive auto-rollbacks reduce impact but risk flapping; use cooldown windows.
Edge-case considerations:
- Power/cost constraints: schedule large downloads on charger/Wi‑Fi.
- Clock skew: use monotonic counters and server timestamping for ordering.
- Partial updates: ensure atomic swap; never delete previous until new passes health checks.
This documentation approach makes offline-first behavior explicit, supports safe staged rollouts with clear rollback paths, and provides robust telemetry with eventual reconciliation for intermittent connectivity.
Draft an architecture diagram and written guidance for handling backpressure in a pipeline where the model-serving tier intermittently slows down due to heavy batch scoring. Show where to insert buffers, queue-size limits, and circuit-breakers and document how clients should be informed (429 vs long polling).
Sample Answer
Requirements & constraints:
- Model-serving intermittently slows (heavy batch scoring), must avoid OOM, preserve throughput and fairness, provide clear client signals (429 vs long-poll), bounded latency for online requests, allow batch jobs to proceed without starving online traffic.
High-level ASCII architecture:
Client -> API Gateway (rate limiter) -> Ingress Buffer (bounded queue) -> Router ->
├─ Online Scoring Pool (fast, autoscaled) -> Response
└─ Batch Scoring Queue (bounded, different priority) -> Batch Workers -> Model Serving Cluster (shared) -> Results Store / Callback
Add:
- Circuit-breaker layer around Model Serving Cluster
- Backpressure controller between Router and Ingress Buffer
- Monitoring & Metrics sink
Where to insert buffers & limits:
- API Gateway: token-bucket + per-client rate limits. Reject early with 429 + Retry-After when soft limit exceeded.
- Ingress Buffer: bounded size N_ingress (e.g., 1000 requests). If full, apply backpressure policy (see below).
- Router splits traffic: Online Pool gets priority tokens; Batch Queue is size N_batch (e.g., 10k messages) with TTL and drop/evict policy.
- Model Serving: per-instance concurrency limit; queue per-instance small (e.g., 10).
- Circuit Breaker: per-model and per-instance with failure and latency thresholds (open when error rate > 5% or p95 latency > 2x SLO).
Backpressure & policies:
- Priority + admission: Online requests have higher priority and dedicated tokens. Batch jobs consume only spare capacity.
- Queue-size thresholds:
- Ingress: green < 70% (accept), yellow 70–90% (start shedding low-priority; return 429 for non-idempotent), red > 90% (reject batch, optionally shed low-value online).
- Batch queue: apply TTL (e.g., 5–30 min). When full, drop FIFO oldest or apply priority-based eviction.
- Circuit-breaker behavior:
- Closed -> monitor; Half-open -> probed; Open -> reject immediately with 503 for internal services or 429 for client-facing (if client retriable).
- When open, trigger fast-fail for new requests and drain small retry tokens for probes.
Client communication: 429 vs long polling
- Immediate rejection: use 429 Too Many Requests with Retry-After header for clients that should retry later. Include JSON with estimated retry-after, queue position (optional), and whether request is idempotent.
- Long-poll / async: for clients that can wait, offer an async API: client POST -> accepted 202 with job-id and location; server returns 202 while enqueued. Use Webhook, WebSocket, or long-poll GET /status (with exponential backoff client-side). Provide SSE/WebSocket for real-time queue updates and final result push.
- For non-idempotent operations, prefer async admission (202) or reject (429) rather than retrying.
Operational details & metrics:
- Expose metrics: ingress queue length, batch queue length, per-model latency p50/p95/p99, instance concurrency, circuit-breaker state, drop rate.
- Auto-scale online pool on p95 latency and queue length; scale batch workers by backlog.
- Alerting: sustained queue > threshold for X minutes, high cb open ratio, increased 429 rate.
Trade-offs:
- Bounded queues and early rejection protect system stability at cost of client-visible errors; async patterns trade immediate response for reliability.
- Strict prioritization benefits SLAs for online traffic but delays batch processing — acceptable if batches are non-urgent.
Example parameterization (starting point):
- Ingress N=1000; Online pool per-instance concurrency 8; per-instance queue 10; Batch queue N=10000, TTL=30min; CB: open if error rate >5% over 1min or p95 latency >2s.
This design preserves model-serving stability by isolating priorities, bounding buffers, fast-fail via circuit-breakers, and giving clear client guidance (429 + Retry-After for immediate rejection; 202 + async status or long-poll/SSE for waitable requests).
A distributed inference path shows stateful services. Discuss how you'd document state management choices: sticky sessions, externalizing state, or event-sourcing. Create a short diagram example and explain operational implications for scaling, failover, and testing.
Sample Answer
Situation: Designing a distributed inference path where some services are stateful (session info, feature caches, user personalization). I would document state-management choices by describing trade-offs, required guarantees, implementation patterns, and operational impacts for sticky sessions, externalized state, and event-sourcing.
Short diagram (ASCII):
Client -> LB -> Inference API -> Router
Router -> {Model Server A (sticky)} OR Router -> Model Server -> State Store (Redis / DB) OR Router -> Model Server -> Event Log (Kafka) -> Stateful Processor
- Sticky sessions
- When: low-latency per-session cache (e.g., session-based feature vectors), simple deployments.
- Implementation notes: use consistent-hash or session-affinity at LB; include session TTL and eviction policy.
- Guarantees: affinity but weak resilience; if instance dies, session lost or requires rehydration.
- Operational implications:
- Scaling: horizontal scale by adding instances; rebalancing causes session re-assignment and cache cold-start.
- Failover: requires sticky failover logic; may accept transient degraded accuracy until rewarm.
- Testing: simulate instance failure and rebalance to measure cold-start latency and accuracy drift.
- Externalizing state (Redis/DB)
- When: multiple replicas need shared read/write state (feature store, model metadata).
- Implementation notes: schema, consistency model (eventual vs strong), caching layer, connection pooling.
- Guarantees: central persistence; supports instance replacement without losing state.
- Operational implications:
- Scaling: scale statestore (sharding, read replicas); watch network and serialization costs.
- Failover: rely on DB HA (replication, leader election); ensure transactional or idempotent updates.
- Testing: chaos tests on DB failover, latency spike, and network partition; verify idempotency.
- Event-sourcing (Kafka + materialized views)
- When: need auditability, replayability, causal ordering (online feature construction, incremental learning).
- Implementation notes: append-only event log, processors build materialized state, compaction, schema evolution.
- Guarantees: strong audit trail, state can be rebuilt to any point.
- Operational implications:
- Scaling: partition event log for throughput; processors scale by consumer groups and partitioning key design.
- Failover: consumer offsets allow replay; ensure exactly-once or idempotent processing to avoid duplicates.
- Testing: test replay correctness, schema evolution, and consumer reprocessing; validate end-to-end latency.
Recommendation summary (for ML inference):
- Prefer externalized state for most production ML (fast lookup, HA).
- Use event-sourcing when replayability, provenance, or complex derived features required.
- Use sticky sessions only for ephemeral caches where rewarm cost is acceptable.
Document checklist (for each choice):
- Why chosen (use case)
- Data model & TTL
- Consistency and SLA targets (latency, error budget)
- Failure modes and recovery playbook
- Scaling plan and metrics to monitor (cache hit rate, DB latency, consumer lag)
- Testing matrix (unit, integration, chaos, replay)
This documentation helps engineers, SREs, and data scientists make informed trade-offs and run safe, testable ML inference in production.
Unlock Full Question Bank
Get access to all Architecture Documentation and Communication interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.