Build a Multi-Model Inference Workflow Platform for External Clients
System DesignModel answerLast updated
Design a platform that chains independently deployed ML models into reliable workflows, covering orchestration, schemas, caching, versioning, failure handling, observability, and tenant isolation.
Your organization runs several machine learning models, each deployed as its own service. Examples include a classifier, an embedding generator and a re-ranker. External customers want to combine these models into pipelines (for example, embed, then retrieve, then re-rank, then classify) without wiring the services together themselves.
Design a platform that lets customers define and run such pipelines. State your own assumptions about scale and latency, then cover:
- Request routing and orchestration: how a request enters, how the pipeline is executed, and how the synchronous and batch/asynchronous modes differ.
- Data flow and schemas: how data moves between models, how contracts are defined and validated, and where validation happens.
- Storage and caching: intermediate data, final results, retention, and cache design.
- Model and version management: how pipelines refer to models, how new versions are rolled out, and how results stay reproducible.
- Failure handling: timeouts, retries, fallbacks, and what happens when a long job crashes midway.
- Observability and traceability: tracing, metrics, and the audit trail.
- Scaling and deployment: how model services and the orchestration layer scale, including GPU considerations.
- Multi-tenancy: authentication, rate limiting, quotas and data isolation.
- Service communication: when you would pick RPC (such as gRPC) versus REST between internal services, and the trade-offs in latency, schema evolution, observability and backward compatibility.
Be explicit about the trade-offs behind your choices and what you would deliberately leave out of a first version.
Hints
Hint 1
Split the problem into two execution paths early: a low-latency synchronous path and a durable asynchronous path. Ask what each one can afford to pay for in terms of checkpointing and persistence.
Hint 2
Push as much validation as possible to pipeline registration time (type-checking the graph against model contracts) so the request-time hot path only validates the edge input.
Hint 3
For reproducibility and safe rollouts, think about resolving model aliases to exact versions at run start and recording them, and include the model version in cache keys so upgrades invalidate stale entries automatically.
Hint 4
For failure handling, think in terms of deadlines propagated through the whole chain, retry budgets to prevent retry storms, idempotent steps keyed by run and step, and declared degraded fallbacks.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Assumptions
- About 500 tenants with sensitive data, so isolation matters.
- Sync traffic peaks at roughly 5k requests/s, with 3-5 model calls per pipeline, giving about 20k internal calls/s.
- Sync target: p99 under 300 ms end to end, orchestration overhead under 20 ms.
- Async: up to about 10M items/day, with SLAs of minutes to hours.
- Inputs up to 1 MB. A 768-dimension fp32 embedding is about 3 KB.
- Availability of 99.9% for sync and at-least-once completion for async.
2. API and data model
A public REST/JSON API versioned under /v1:
POST /v1/workflows/{id}:runfor sync execution.POST /v1/workflows/{id}:submitfor async, returning ajob_id.GET /v1/jobs/{job_id}for status and a result location.POST /v1/workflowsto register a pipeline definition.
Mutating calls take an Idempotency-Key. Responses include a trace_id, the pipeline version and the resolved model versions.
Core entities:
- Workflow spec: an immutable, versioned DAG. Each step has a model reference, input mapping, timeout, retry policy, cacheability flag and optional fallback.
- Model registry: model, version, artifact location, schema ID, status (shadow, canary, active, deprecated) and traffic weight.
- Run record: tenant, pinned versions, per-step state and result location, in Postgres or DynamoDB.
- Results: small ones inline, large ones in object storage under a tenant prefix, encrypted with per-tenant keys and subject to a retention TTL.
3. Architecture
Edge: an API gateway handles authentication, quotas and WAF. Behind it are two distinct execution paths.
Sync path. A stateless orchestrator loads the compiled DAG from a local cache, runs independent branches in parallel and passes intermediates in memory. Only the final result and metadata are persisted. Durable checkpointing would add roughly 5-20 ms per step, which the latency budget cannot absorb.
Async path. Jobs go onto a queue and are run by a durable workflow engine (Temporal, Step Functions, or Argo for batch). Each step output is checkpointed to object storage or Redis, so a crash resumes at the failed step rather than from scratch. Large intermediates pass by reference, not by value.
Separating these paths is the central design decision: sync optimizes for latency, async for durability.
4. Deep dives
Schemas. Each model publishes a Protobuf contract to a schema registry. At registration, the platform type-checks the DAG (for example, embedding dimension must match the re-ranker input). At request time only the edge input is validated, using JSON Schema. Errors surface early and the hot path stays cheap.
Caching. Use a content-addressed key hash(model@version, normalized_input). Including the version makes invalidation automatic on upgrade. Caches are tenant-scoped by default. Cross-tenant sharing is allowed only for explicitly public data and only by policy.
Versioning and rollout. Pipelines reference model@alias. The alias is resolved at run start and recorded, so results are reproducible. Rollout is shadow traffic with offline comparison, then canary at 1%, 10% and 50% with automatic rollback on error rate, latency or prediction drift, then full promotion. Tenants may pin exact versions, and deprecated versions keep serving for a grace period with warning headers.
Failure handling.
- Propagate an overall deadline so each step's timeout derives from the remaining budget and no work continues after the client gave up.
- Retry only idempotent, retryable errors, with exponential backoff and jitter, at most 2 retries on the sync path, and a retry budget (around 10% of traffic) to avoid retry storms.
- Circuit breakers per model service.
- Fallbacks declared in the spec, such as skipping the re-ranker and returning a
degraded: trueflag, or falling back to the previous model version. - Async steps are idempotent, keyed on
(run_id, step_id), with at-least-once queue delivery, a dead-letter queue after K failures, and partial results exposed.
Observability. One OpenTelemetry trace per run with a span per step, tagged with tenant, model version, cache hit and retry count. RED metrics per model and tenant, GPU utilization, queue depth, and ML signals such as input drift and score distribution shift. An audit log records which model version produced each result, which matters when a customer asks why a verdict was returned. Payload sampling needs PII redaction.
Scaling. Model services run on Kubernetes with separate GPU and CPU pools and autoscale on queue depth or in-flight requests rather than CPU. Dynamic batching (Triton, TorchServe) waiting about 5 ms to group up to 32 requests raises GPU throughput. Keep warm replicas for large models because cold starts can take minutes. The orchestrator is stateless and scales horizontally. Deploy multi-region active-active for sync, honoring data residency.
Multi-tenancy. The gateway authenticates with OAuth2 client credentials or API keys and converts them to a signed internal identity propagated downstream, with mTLS between services. Token-bucket rate limits per tenant and per workflow live in Redis, backed by longer-horizon quotas for cost control and per-tenant concurrency caps on async jobs to prevent noisy neighbors. Storage and cache keys are tenant-prefixed with per-tenant encryption keys.
5. RPC vs REST internally
| Concern | gRPC/Protobuf | REST/JSON |
|---|---|---|
| Latency | Binary, HTTP/2 multiplexing, lower overhead; important at 20k calls/s | Larger payloads, more parsing |
| Schema evolution | Strong contracts, field numbers allow additive changes | Looser; needs OpenAPI discipline |
| Deadlines | Built-in propagation | Manual headers |
| Observability | Needs tooling for binary payloads | Easy to inspect with curl and logs |
| Compatibility | Never reuse field numbers, only add optional fields | Version in the URL, tolerate unknown fields |
Use gRPC between the orchestrator and model services, and REST at the public edge where ease of adoption matters most.
6. Common mistakes
- Using one execution path for both sync and async, which either breaks latency or loses durability.
- Scaling GPU services on CPU metrics.
- Omitting the model version from cache keys.
- Unbounded retries that amplify an outage.
- Resolving aliases at every step, so one run can mix model versions.
- Skipping tenant isolation in caches and storage.
7. Scope for a first version
Ship the sync path with a small set of fixed pipelines, registry-based versioning, gateway rate limits and tracing. Add custom DAG authoring, the durable async engine, shadow and canary automation, and multi-region later.