← Back to list

Designing Context-Aware Dynamic Routers for Model Serving

When engineering teams first deploy Machine Learning (ML) or Large Language Models (LLMs) into production, they typically hardcode model…

SAHIL SHARMA · 2026-05-24 08:23 · 0 claps · 6.4 min read paywalled
#design-systems #machine-learning #software-architecture #microservices #lmops
Open on Medium ↗
Wiki topics: LLM · Large Language Models OPS · LLMOps & Inference ML · Machine Learning PRD · Product Design EDU · Education & Learning 🏛️ · Architecture

Designing Context-Aware Dynamic Routers for Model Serving

When engineering teams first deploy Machine Learning (ML) or Large Language Models (LLMs) into production, they typically hardcode model endpoints directly into the client application. The client makes a direct request to a specific cluster or service instance, receives a prediction, and renders the result.

This works perfectly at small scale. But as an enterprise platform grows, this design creates a brittle architecture.

If your data science team wants to run an A/B experiment comparing a lightweight model against a heavy model, you are forced to ship client-side updates. If a specific model shard experiences a hardware failure, client applications fail unless they have complex retry logic baked into their codebases. Worse yet, modern models frequently require real-time feature hydration — meaning the client must execute multiple heavy database lookups to collect contextual “facts” (user location, past interactions, session metrics) merely to pass them as inputs into the model request.

To build a reliable platform, you must decouple your clients from your model sharding entirely. Drawing on patterns emerging across high-throughput ML platforms, this article covers how to design a Context-Aware Dynamic Router — a high-throughput, stateless entry point that handles all model traffic intelligently at the edge.

The Core Problem: Client-Coupled ML Infrastructure

Traditional infrastructure relies on Layer 7 load balancers (like NGINX or Envoy) routing traffic based on HTTP paths or round-robin algorithms. These routers are blind to the underlying payload or the user’s business context.

When applied to machine learning and LLM serving, this blindness surfaces three critical failures:

  • Monolithic Client Dependencies: If a calling app expects a specific model variant, any backend optimization, canary release, or structural fallback requires coordination across multiple product engineering teams.
  • Inefficient Feature Hydration: For models to calculate predictions, they need fresh data (e.g., active user features). Forcing the client application to fetch these features before hitting the model service wastes client memory and introduces network hops.
  • Experimentation Chaos: Managing A/B testing dynamically at the infrastructure layer is extremely difficult when using typical path-based routing rules, especially when target configurations rely on highly transient user contexts.

We need an infrastructure layer that abstracts these complexities by executing a Context -> Objective -> Model evaluation flow on the fly.

The Architecture Breakdown

The core design introduces two tightly coordinated layers: a stateful control plane responsible for configuration management, and an ultra-low latency, stateless data plane router (the Switchboard Router) responsible for handling live inference traffic.

1. The Stateful Control Plane

The control plane is the source of truth for the entire routing system. It owns three responsibilities:

  • Experiment Registry: Stores the mapping between Objective tokens, traffic split percentages, and target model shard addresses. Data scientists interact with this layer — never with the router directly.
  • Deployment Lifecycle Manager: Orchestrates the three-phase rollout process (Assignment → Validation → Activation) described in the failure modes section below.
  • Config Broadcaster: Propagates validated routing rule snapshots to all Switchboard Router instances via a push-based protocol, ensuring routers always operate on a consistent, verified snapshot.

The control plane is the only component permitted to write routing configuration. Routers pull no config themselves — they only accept pushed, cryptographically signed snapshots from the control plane.

2. The Core Abstraction: The “Objective”

Instead of letting the client application request a specific model identifier (e.g., llama-3-70b-v2), the client explicitly passes an Objective token — a unique, immutable enumeration assigned to a business goal (e.g., RECOMMEND_HOME_FEED or CLASSIFY_SUPPORT_TICKET).

The router uses this Objective tag alongside the request context to determine exactly which model cluster shard should execute the compute job. This single design decision unlocks everything else: clients become insulated from backend topology, and model teams gain the freedom to swap, version, or shadow-test any shard without a client deployment.

3. The Stateless Data Plane (Switchboard Router)

The router itself is completely stateless, written in a memory-safe, low-latency compiled language (like Rust or Go) to minimize gateway overhead.

  • Rule Compression: The router holds compressed routing rules compiled into JSON or Protocol Buffers in local memory, loaded atomically on config push.
  • The Routing Loop: When an Objective request arrives, the router looks up the matching rule set, evaluates the user’s deterministic experiment hash slot, determines the destination shard, and proxies the connection — all within a single, synchronous hot path.

Because the router holds no mutable state of its own, horizontal scaling is trivial: spin up any number of instances, all operating from the same pushed config snapshot.

4. Context Enrichment Engine (Fact Gathering)

To support model innovation independent of client architectures, the router implements context enrichment hooks. The rule schema declares a list of required “facts” (raw metrics or observations) for specific experimental routing paths.

If a user lands in a 10% experimental bucket, the router actively calls an internal, distributed in-memory cache to fetch user_country and session_depth_count. It injects these parameters directly into the inference request body — without the client application ever knowing a feature store lookup occurred. From the client's perspective, it fired a single request with an Objective token and received a response.

Tradeoffs, Failure Modes, and Mitigations

Shifting to an intelligent routing layer requires careful handling of network limits and state synchronization latencies.

1. Config Propagation Lag vs. Consistency

When a data scientist modifies traffic split variables or registers a new model variant in the control plane, the updated configuration must propagate across hundreds of globally deployed router instances.

The Failure Mode: If a new model version is deployed to a shard but the router’s config lags behind, requests may fail due to validation errors. Conversely, if the router begins routing traffic to a shard before the model has finished initializing, it triggers an immediate spike in HTTP 503 errors.

Mitigation — Three-Phase Deployment Workflow:

The control plane enforces a strict deployment gate before any config change reaches live routers:

  1. Assignment: A CI/CD pipeline or data scientist submits a new model-to-cluster layout to the control plane. The control plane computes the full shard mapping — which model version serves which percentage of which Objective’s traffic.
  2. Validation: The control plane instructs the target model serving cluster to spin up containers, load weights, and execute an automated health check suite, confirming that model dependencies are functional and inference latency meets baseline thresholds.
  3. Mapping Activation: Once the shard signals a healthy status, the control plane emits the updated Virtual IP (VIP) mapping profile to all router instances as an atomic hot-reload event. Routers swap the in-memory config without dropping in-flight connections.

No traffic is shifted until step 3 completes. This eliminates the entire class of race conditions between deployment and routing.

2. Cascading Latency via Inline Feature Fetching

If your router fetches context features (“facts”) inline from primary transaction databases, a sudden traffic surge will cause a cascading failure. The router will bottleneck waiting for database connections, driving up client request timeouts system-wide.

Mitigation: Enforce a hard deadline budget on all fact lookups. If a feature fetch inside the router exceeds a tight 10ms threshold, abort the lookup immediately, drop the user out of the experimental variant, and route directly to the default stable model using standard baseline inputs. Never let an enrichment failure become a client-visible error.

Additionally, all fact sources used by the router must be backed by a dedicated in-memory cache tier (e.g., Redis or a custom distributed store) — never the primary OLTP database directly.

3. Shadow Testing and Storage Exhaustion

One of the key benefits of this gateway is Shadow Testing — mirroring live production traffic to an experimental model variant to measure latencies and output quality without affecting user-facing results. However, duplicating payload data across high-throughput services can easily saturate internal networks and overload storage logging queues.

Mitigation: Execute shadow traffic via fire-and-forget asynchronous threads. The router writes the mirrored request body into a decoupled message queue (e.g., Apache Kafka), allowing downstream workers to forward requests to the experimental model cluster out-of-band — entirely outside the primary client request loop. The client response path is never blocked on shadow execution.

Apply a configurable sampling rate to shadow traffic (e.g., mirror 10% of requests rather than 100%) as an additional safeguard against queue saturation during traffic spikes.

Conclusion

By moving from hardcoded endpoints to abstract, intent-driven Objectives, enterprise ML platforms can handle massive model version shifts, continuous shadow testing, and real-time context enrichment cleanly at the edge — without touching a single client application.

Three key principles underpin this architecture:

  1. Decouple clients via intent abstraction. Never let frontend or microservice clients address specific model variants directly. Force them to declare a business Objective, and delegate all routing logic to a dedicated data plane. This turns model upgrades from coordinated multi-team releases into backend-only operations.
  2. Shift feature hydration to the edge. Offloading fact gathering from calling applications onto the enrichment proxy doesn’t just simplify clients — it centralizes feature freshness guarantees in one place, making it easier to audit, cache, and tune input quality independently of model development.
  3. Enforce atomic control plane verification. The three-phase deployment gate (Assign → Validate → Activate) is what separates this architecture from a sophisticated load balancer. Without it, the intelligence of your routing layer is only as reliable as your least-coordinated deployment.

The router described here is not a performance optimization — it is a platform capability. Once in place, it becomes the foundation for every experimentation, safety, and observability primitive your ML organization will build on top of it.


메타데이터
post_id
732ee8cc84e5
slug
designing-context-aware-dynamic-routers-for-model-serving-732ee8cc84e5
url
https://medium.com/@ys1113457623/designing-context-aware-dynamic-routers-for-model-serving-732ee8cc84e5
canonical_url
https://medium.com/@ys1113457623/designing-context-aware-dynamic-routers-for-model-serving-732ee8cc84e5
author_url
https://medium.com/@ys1113457623
status
ok
fetched_at
2026-06-09 15:37:30