How BabySea built adaptive provider selection on Databricks BabySea, a generative-media execution control plane spanning 80+ image and video models across 12+ AI labs and 8+ inference providers, built adaptive provider selection on Databricks so that per-request routing decisions reflect live latency, reliability and cost conditions. The system writes provider-attempt telemetry from regional Supabase into Databricks via Unity Catalog Lakehouse Federation, computes provider rankings there, and exports them to Upstash so the customer-facing API reads a cached ranking in milliseconds with deterministic fallback if Databricks or the cache degrades. The company deliberately kept the intelligence plane out of the hot path, treating adaptive selection as an enhancement rather than a serving dependency. BabySea https://babysea.ai is the execution control plane for generative media: one API across 80+ image and video models from 12+ AI labs, served by 8+ inference providers, running in three sovereign regions: US, EU, and APAC. The hard problem is not exposing models. The hard problem is execution: deciding, per request, which provider should actually run a given model in a given region under real latency, reliability, and cost conditions. Static routing breaks down quickly in that environment, and Databricks https://www.databricks.com is the intelligence layer that makes our provider selection adaptive instead of static. At BabySea, every customer execution produces an attempt record provider, model, submitted/resolved timestamps, outcome, estimated cost, failover order, and cancellation state and that attempt stream lands first in our regional Supabase https://supabase.com systems, because Postgres is the operational source of truth for the product. The deployment region is kept as a regional stack boundary and written into Databricks Bronze/Gold outputs. From there, Databricks runs the learning loop end to end in production. The architectural decision that matters most is this: we did not build a detached analytics estate beside the product, we made Databricks part of the control loop that improves execution outcomes while keeping the customer-serving path operationally safe. That boundary is the whole design. A common failure mode in "smart routing" systems is to let the intelligence plane become a hard dependency for serving traffic, so the first time the ranking service degrades, the customer-visible path degrades with it. We built the opposite system: Databricks computes the ranking, the API consumes a cached export of that ranking in milliseconds, and the API always retains deterministic fallback behavior if Databricks or cache infrastructure degrade. Adaptive selection is an enhancement, never a dependency The runtime chain is straightforward: customer traffic produces provider-attempt telemetry in regional Supabase, Databricks reads that telemetry directly and transforms it into provider-performance and provider-ranking artifacts, those rankings are exported into Upstash https://upstash.com , the API reads the exported ranking for generation provider order: "fastest" while circuit-breaker logic and failover stay in place, and later customer traffic generates new telemetry that closes the loop. That loop is the core of the design, and every workload makes later workloads smarter. Here is what the API actually does when a customer asks for "fastest" . This is the hot path, not pseudocode: js const deploymentRegion = getDeploymentRegion ; if providerOrder === 'fastest' { const ranking = await getCachedRanking model, deploymentRegion ; const configuredProviders = new Set Object.keys providerLookup ; const fromCache = ranking?.providersRanked.filter p = configuredProviders.has p , ; if fromCache && fromCache.length 0 { resolvedOrder = fromCache.join ', ' ; providerOrderSource = 'cached-ranking'; } else { resolvedOrder = converters.providerDisplayOrder .filter p = configuredProviders.has p .join ', ' ; providerOrderSource = 'fallback'; } } Notice what is not in that code. There is no Databricks SDK call, no MLflow client, and no Mosaic AI Model Serving fetch. The hot path reads one Upstash Redis-protocol key, filters it against the providers configured for the requested model, and moves on. Everything Databricks does happens upstream of this line. The first Databricks decision was to avoid copying operational data unless we had a compelling reason to. We use Unity Catalog Lakehouse Federation to connect each regional Databricks workspace to its matching regional Supabase database through a PostgreSQL foreign connection. That gives us a governed entry point into operational routing telemetry without introducing another ETL system, another CDC estate, or another set of consistency problems between the product database and the learning system. This is not just a convenience feature, it changes the operating model. Because the federated source sits under Unity Catalog, governance starts at ingress. Federated source columns carry governed tags such as gdpr status , tenant boundary , and ai telemetry , and those tags matter because the routing system is not just reading "logs", it is reading multi-tenant, region-sensitive execution data that will feed training, ranking, analytics, and operational validation. That means the same control plane that reads provider telemetry also knows which fields are tenant-isolating keys, which fields are compliance-sensitive, and which fields are cost or inference telemetry, with lineage originating at the operational source rather than at a copied derivative. For a multi-region AI infrastructure company, that is a cleaner foundation than shipping raw operational tables into an ungoverned analytics sink and reconstructing meaning later. From the federated source, we refine the data through a Lakeflow Spark Declarative Pipeline into a Bronze, Silver, Gold medallion on Delta Lake. This is not medallion architecture as ceremony: each layer has a specific role in the routing loop. Bronze lands the federated operational tables into Delta-backed materialized views. Its job is not business logic, its job is isolation and reproducibility: isolate the product database from downstream transformations, preserve lineage, and establish a Delta-native substrate for analytics, training, and export. In our production stack, the most important Bronze inputs are the attempt-log path that eventually becomes routing intelligence. Silver is where the routing contract becomes explicit. Provider attempts are cleaned, typed, normalized, and enriched with routing-relevant fields such as latency, success, wasted-attempt semantics, time buckets, and other derived fields needed for aggregation and training. Silver is where "application logs" stop being logs and become a feature-bearing execution dataset, and if you want reliable model training, reliable provider-performance analytics, or reliable ranking generation, this is the layer that has to be correct. Gold produces artifacts the rest of the platform can consume. That includes provider-performance aggregates, but the most important output is gold provider ranking by model , which is the bridge between Databricks and the API. That Gold table is not a BI table. It is a runtime contract. gold provider ranking by model emits one row per model and region, with ranked provider lists, scores, attempt totals, ranking-window metadata, and a computation timestamp. In the current production implementation, the ranking shape combines success rate, wasted-attempt rate, and latency normalization into a single score over a 24-hour window, which gives us a deterministic, explainable, continuously refreshed routing artifact even before any optional real-time model scoring enters the picture. Conceptually, the production scoring shape is: score = success rate 1.0 - wasted rate COST PENALTY - latency p95 norm LATENCY PENALTY with current constants: COST PENALTY = 0.5 LATENCY PENALTY = 0.3 RANKING WINDOW HOURS = 24 The reason this design works is simple. First, it gives the serving layer a compact, explicit object to consume: the API does not need raw execution logs, ad hoc joins, or online feature synthesis, it needs a ranking. Second, it lets the ML path and the non-ML path converge on the same abstraction, so whether the ranking is produced from direct aggregates, a registered predictive model, or both, the serving contract remains stable: here is the ordered provider set for this model in this region. That is what makes the system evolvable without destabilizing the API surface. On top of the medallion, we train a predictive routing model nightly with MLflow and register the resulting artifact in Models in Unity Catalog on a per-region basis babysea us.ml.predictive routing , babysea eu.ml.predictive routing , babysea apac.ml.predictive routing . In the implementation snapshot we documented, the latest READY model versions were US v8, EU v3, and APAC v3. That regional separation is not cosmetic. We operate across sovereign regions, and provider behavior, customer demand shape, cost conditions, and product constraints do not collapse neatly into a single global policy, so treating US, EU, and APAC as distinct learning domains is cleaner technically and safer operationally. The current production training notebook uses a value-prediction approach with a scikit-learn GradientBoostingRegressor , not XGBoost. The serving features are intentionally compact provider , model , hour of day , day of week and the output is one scalar predicted value per provider candidate where higher means better. That score is not exposed directly to customers, it is one input into execution ordering, and the customer-facing abstraction remains stable even while the predictive layer evolves. Production Vercel deployments do not call Databricks on the request path. Databricks remains the internal learning system that exports Gold rankings to Upstash, and the API controls whether the "fastest" sentinel should consume that cached adaptive ranking or fall back to the model's static provider order. js const ADAPTIVE ROUTING ENABLED = process.env.ADAPTIVE ROUTING ENABLED == 'false'; if providerOrder === 'fastest' { const fallbackOrder = converters.providerDisplayOrder .filter p = configuredProviders.has p .join ', ' ; if ADAPTIVE ROUTING ENABLED { const ranking = await getCachedRanking model, deploymentRegion ; const fromCache = ranking?.providersRanked.filter p = configuredProviders.has p , ; if fromCache?.length { resolvedOrder = fromCache.join ', ' ; } else { resolvedOrder = fallbackOrder; } } else { resolvedOrder = fallbackOrder; } } With ADAPTIVE ROUTING ENABLED=true or unset, "fastest" uses the Upstash ranking cache. With ADAPTIVE ROUTING ENABLED=false , "fastest" resolves to the static fallback order. In both modes, circuit-breaker sorting and provider failover still run. The difference between ML-enhanced infrastructure and ML-fragile infrastructure is whether the learning system is a hard dependency for every request. We do not let it become one. This is the architectural discipline that keeps the system safe. The control loop is operationalized through Lakeflow Jobs. In production, the daily schedule is 02:30 UTC to export the Gold ranking into Upstash and 03:00 UTC to retrain and re-register the predictive model. Across three regions, that gives us six unattended jobs coordinating the routing loop: export and training in US, EU, and APAC. This schedule is not arbitrary. The export cadence, ranking window, and cache TTL are chosen as a system: a 24-hour Gold ranking window, a 48-hour Upstash TTL, and daily export cadence. That 48-hour TTL being deliberately longer than the 24-hour refresh cadence is what gives the system fail-open resilience, because yesterday's valid ranking can continue to serve even if today's job does not run. This is a subtle but important lesson in production ML systems: freshness is not the only variable that matters, graceful degradation matters just as much. The API never calls Databricks on the customer request path. Instead, a Lakeflow Job exports each Gold ranking row into Upstash using a key of the form predictive:ranking: