Technical Architecture and Engineering Practices for a Large Model Service Platform (MaaS)
This article explains how to build a large model service platform (MaaS) that treats models as governed infrastructure rather than isolated API calls. It covers a five-layer reference architecture, model abstraction and routing, fine-tuning decisions, evaluation pipelines with release gates, inference optimization across latency, throughput, and cost, application orchestration with RAG, security and compliance, and a phased evolution roadmap. Readers will find practical design principles, code examples, and capacity and cost guidance for running multi-model services in production.
1. Why a Platform Instead of Point-to-Point API Calls
The typical early approach to adopting large models is to call a single inference endpoint and concatenate prompts into each request. This is sufficient for validation, but problems surface quickly in production: model version upgrades cause output drift, prompts scattered across business code cannot be reused, the absence of an evaluation baseline makes it impossible to tell whether a new version is better, and rising concurrency drives latency and cost out of control. Sensitive data also flows out with requests and becomes hard to audit.
The essence of a large model service platform—commonly called MaaS (Model as a Service)—is to treat the model as a governable infrastructure resource and add lifecycle management on top of it. Based on the form described in the source material, such platforms generally cover three core services: fine-tuning, evaluation, and inference. They also integrate models from multiple organizations as well as in-house models, forming a model marketplace that users can select from. For developers, the value is not “being able to call a model” but being replaceable, measurable, and rollback-capable.
2. Layered Architecture: A Practical Reference Model
Divide platform capabilities into five layers, decoupled through explicit contracts:
- Resource layer: heterogeneous compute pools (training and inference cards in separate pools), high-speed interconnect, object storage, and a container platform.
- Model layer: a base model repository, version lineage, and artifact-based management of weights and configurations.
- Service layer: fine-tuning, model evaluation, inference services, and batch and offline jobs.
- Orchestration layer: application development frameworks, prompt and knowledge base management, tool invocation, and workflows.
- Governance layer: identity and permissions, quotas and rate limiting, logging, monitoring and alerting, and audit and compliance.
The key design principle is “artifactization”: datasets, training configurations, checkpoints, evaluation reports, and inference endpoints should all be immutable artifacts with version numbers, so any production change can be traced back to a specific combination of artifacts.
3. Model Integration and the Abstraction Layer
Multiple model providers bring freedom of choice but also coupling risk. You must insert an abstraction layer between business logic and specific models to hide differences in parameter naming, message structure, and streaming protocols.
from dataclasses import dataclassfrom typing import Protocol, Iterator@dataclassclass GenConfig:temperature: float = 0.7top_p: float = 0.9max_tokens: int = 1024stop: tuple[str, ...] = ()class ChatModel(Protocol):def generate(self, messages: list[dict], cfg: GenConfig) -> str: ...def stream(self, messages: list[dict], cfg: GenConfig) -> Iterator[str]: ...class RoutingModel:"""Route to different backend models by task type and cost budget."""def __init__(self, routes: dict[str, ChatModel]):self.routes = routesdef generate(self, messages, cfg, task="general"):return self.routes[task].generate(messages, cfg)
The abstraction layer also carries three engineering responsibilities: unified retries and timeouts (distinguishing retryable rate-limit errors from non-retryable context-length-exceeded errors), unified metering (recording input and output tokens and cost attribution), and unified fallback (switching to a backup model when the primary is unavailable and tagging the response).
4. Data and Fine-Tuning: When to Fine-Tune and When Not To
A common mistake is handing every quality problem to fine-tuning. The practical order of judgment is: first optimize prompts and context, then introduce retrieval augmentation, and only then consider parameter-efficient fine-tuning. If the knowledge a task requires changes frequently, fine-tuning hardens that knowledge into weights and increases maintenance cost instead.
Typical scenarios that suit fine-tuning are highly fixed style and format, a need for stable structured output, or the need to compress long prompts to reduce cost. Data requirements include: strict separation of training, validation, and test sets with time-based splitting to prevent leakage; consistent formatting between instructions and outputs; deduplication of repeated and low-quality samples; and manual spot checks for annotation consistency.
# Training data should use a unified structure for cross-model reuse and automated validationrecord = {"messages": [{"role": "system", "content": "You are a ticket classification assistant that outputs only fixed labels."},{"role": "user", "content": "Login page does not respond to clicks, cache already cleared"},{"role": "assistant", "content": "frontend-login"}]}
Parameter-efficient methods such as LoRA train only a small number of additional parameters, with significantly lower memory and storage overhead than full-parameter training. They also make it easy to maintain multiple adapters per business line and load them dynamically on the same base model, which naturally fits the isolation requirements of a multi-tenant platform.
5. Evaluation: No Baseline, No Iteration
Evaluation must be independent of training and run as an automated pipeline. Build three tiers of metrics:
- Automated metrics: accuracy, field-level F1 for extraction tasks, and schema validation pass rate for structured output.
- Model review: use a stronger model to score against a rubric, after calibrating consistency with human annotations to avoid self-evaluation bias.
- Human spot checks: a fixed sampling ratio covering long-tail and adversarial samples.
Beyond quality, evaluate engineering metrics: time to first token, output tokens per second, cost per request, and performance degradation under long context. Write all results into an evaluation report artifact bound to the model version, and use it as a release gate.
def gate(report, baseline, effect_min=0.0, p95_latency_max=2.0):ok_effect = report.score >= baseline.score + effect_minok_latency = report.p95_latency <= p95_latency_maxok_format = report.schema_pass_rate >= 0.99return ok_effect and ok_latency and ok_format
6. Inference Serving: The Triangle of Latency, Throughput, and Cost
Inference optimization should proceed layer by layer. On the request side, batch requests together and use priority queues; on the engine side, use continuous batching, KV cache reuse, quantization, and operator optimization; on the system side, use elastic scaling across multiple replicas and prefix cache reuse to reduce repeated computation. Streaming output noticeably improves the interactive experience, but you need compensation logic for errors that surface mid-stream.
Capacity planning can be estimated with a simplified model: required concurrent replicas ≈ peak QPS × average generation time ÷ per-replica concurrency, with more than 30% headroom reserved for bursts. Cost governance relies on quotas, per-tenant metering, and tiered routing—simple tasks go to small models, and only complex tasks are escalated.
7. Application Orchestration and Knowledge Augmentation
Platform value ultimately shows up on the application side. Organize applications as workflows: intent recognition → retrieval → prompt assembly → model invocation → validation → fallback. Retrieval augmentation needs attention to chunking strategy, hybrid retrieval (keyword and vector), reranking, and citation traceability so answers can be verified. Tool invocation should follow the principle of least privilege and allowlists, and write operations require a second confirmation.
8. Security, Compliance, and Stability
Multi-model platforms typically need to pass third-party security standard audits such as SOC 2 and the ISO series. The point of these certifications is to bring permissions, audit, change management, and incident response into a verifiable process. Engineering practice should implement tenant-level key isolation and least privilege, redaction of sensitive information before it enters the model, full-chain logging and invocation auditing, content safety filtering, and data retention and deletion policies. For stability, set up circuit breakers, rate limiting, fallback, and canary releases; validate any model or prompt change with a small traffic share first.
9. Suggested Evolution Roadmap
Phase one: integrate a single model and version prompts. Phase two: add an evaluation pipeline with automated gates. Phase three: introduce fine-tuning and retrieval augmentation, forming model routing. Phase four: complete multi-tenant metering, a cost dashboard, and compliance auditing. Vendors such as Baidu AI Cloud also provide general-category large model services along with supporting object storage, container platform, logging, and monitoring and alerting capabilities, which can serve as the foundation for the architecture above. The core conclusion: only when models are treated as replaceable, measurable, and governable artifacts does engineering complexity become truly manageable.
