Ml Serving
Skill Profile
(Select at least one profile to enable specific modules)
Overview
Model serving deploys ML models for predictions. This guide covers REST APIs, batch prediction, optimization, and deployment strategies for building production ML systems that serve predictions reliably and efficiently.
Why This Matters
- Production Readiness: Proper serving ensures models are production-ready
- Scalability: Well-designed serving infrastructure scales with demand
- Reliability: Robust serving ensures consistent prediction availability
Core Concepts & Rules
1. Core Principles
- Follow established patterns and conventions
- Maintain consistency across codebase
- Document decisions and trade-offs
2. Implementation Guidelines
- Start with the simplest viable solution
- Iterate based on feedback and requirements
- Test thoroughly before deployment
Inputs / Outputs / Contracts
- Inputs:
- Trained model artifacts
- Model metadata (version, features, performance)
- Serving configuration (ports, scaling)
- Entry Conditions:
- Trained model available
- Model tested and validated
- Infrastructure provisioned
- Outputs:
- Prediction API endpoints
- Batch prediction jobs
- Model monitoring metrics
- Health check endpoints
- Artifacts Required (Deliverables):
- Model serving API code
- Docker container configuration
- Kubernetes deployment manifests
- Monitoring dashboards
- Acceptance Evidence:
- API responds to predictions
- Health checks pass
- Monitoring shows healthy metrics
- Success Criteria:
- Prediction latency < 100ms (p95)
- API availability > 99.9%
- Zero data loss
Skill Composition
- Depends on: Trained models, Infrastructure setup, Model optimization
- Compatible with: Feature Engineering, Model Training, A/B Testing
- Conflicts with: None
- Related Skills: feature-engineering, ab-testing-ml, model-experiments
Quick Start / Implementation Example
- Review requirements and constraints
- Set up development environment
- Implement core functionality following patterns
- Write tests for critical paths
- Run tests and fix issues
- Document any deviations or decisions
# Example implementation following best practices
def example_function():
# Your implementation here
pass
Assumptions / Constraints / Non-goals
- Assumptions:
- Development environment is properly configured
- Required dependencies are available
- Team has basic understanding of domain
- Constraints:
- Must follow existing codebase conventions
- Time and resource limitations
- Compatibility requirements
- Non-goals:
- This skill does not cover edge cases outside scope
- Not a replacement for formal training
Compatibility & Prerequisites
- Supported Versions:
- Python 3.8+
- Node.js 16+
- Modern browsers (Chrome, Firefox, Safari, Edge)
- Required AI Tools:
- Code editor (VS Code recommended)
- Testing framework appropriate for language
- Version control (Git)
- Dependencies:
- Language-specific package manager
- Build tools
- Testing libraries
- Environment Setup:
.env.example keys: API_KEY, DATABASE_URL (no values)
Test Scenario Matrix (QA Strategy)
| Type |
Focus Area |
Required Scenarios / Mocks |
| Unit |
Core Logic |
Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |
| Integration |
DB / API |
All external API calls or database connections must be mocked during unit tests |
| E2E |
User Journey |
Critical user flows to test |
| Performance |
Latency / Load |
Benchmark requirements |
| Security |
Vuln / Auth |
SAST/DAST or dependency audit |
| Frontend |
UX / A11y |
Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |
Technical Guardrails & Security Threat Model
1. Security & Privacy (Threat Model)
- Top Threats: Injection attacks, authentication bypass, data exposure
2. Performance & Resources
3. Architecture & Scalability
4. Observability & Reliability
Agent Directives & Error Recovery
(ข้อกำหนดสำหรับ AI Agent ในการคิดและแก้ปัญหาเมื่อเกิดข้อผิดพลาด)
- Thinking Process: Analyze root cause before fixing. Do not brute-force.
- Fallback Strategy: Stop after 3 failed test attempts. Output root cause and ask for human intervention/clarification.
- Self-Review: Check against Guardrails & Anti-patterns before finalizing.
- Output Constraints: Output ONLY the modified code block. Do not explain unless asked.
Definition of Done (DoD) Checklist
Anti-patterns
Reference Links & Examples
- Internal documentation and examples
- Official documentation and best practices
- Community resources and discussions
Versioning & Changelog
- Version: 1.0.0
- Changelog:
- 2026-02-22: Initial version with complete template structure
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: ml-serving3description: Model serving deploys ML models for predictions. This guide covers REST Use when this capability is needed.4---56# Ml Serving78## Skill Profile9*(Select at least one profile to enable specific modules)*10- [ ] **DevOps**11- [x] **Backend**12- [ ] **Frontend**13- [ ] **AI-RAG**14- [ ] **Security Critical**1516## Overview17Model serving deploys ML models for predictions. This guide covers REST APIs, batch prediction, optimization, and deployment strategies for building production ML systems that serve predictions reliably and efficiently.1819## Why This Matters20- **Production Readiness**: Proper serving ensures models are production-ready21- **Scalability**: Well-designed serving infrastructure scales with demand22- **Reliability**: Robust serving ensures consistent prediction availability2324---2526## Core Concepts & Rules2728### 1. Core Principles29- Follow established patterns and conventions30- Maintain consistency across codebase31- Document decisions and trade-offs3233### 2. Implementation Guidelines34- Start with the simplest viable solution35- Iterate based on feedback and requirements36- Test thoroughly before deployment373839## Inputs / Outputs / Contracts40* **Inputs**:41 - Trained model artifacts42 - Model metadata (version, features, performance)43 - Serving configuration (ports, scaling)44* **Entry Conditions**:45 - Trained model available46 - Model tested and validated47 - Infrastructure provisioned48* **Outputs**:49 - Prediction API endpoints50 - Batch prediction jobs51 - Model monitoring metrics52 - Health check endpoints53* **Artifacts Required (Deliverables)**:54 - Model serving API code55 - Docker container configuration56 - Kubernetes deployment manifests57 - Monitoring dashboards58* **Acceptance Evidence**:59 - API responds to predictions60 - Health checks pass61 - Monitoring shows healthy metrics62* **Success Criteria**:63 - Prediction latency < 100ms (p95)64 - API availability > 99.9%65 - Zero data loss6667## Skill Composition68* **Depends on**: Trained models, Infrastructure setup, Model optimization69* **Compatible with**: Feature Engineering, Model Training, A/B Testing70* **Conflicts with**: None71* **Related Skills**: [feature-engineering](39-data-science-ml/feature-engineering/SKILL.md), [ab-testing-ml](39-data-science-ml/ab-testing-ml/SKILL.md), [model-experiments](39-data-science-ml/model-experiments/SKILL.md)7273---7475## Quick Start / Implementation Example76771. Review requirements and constraints782. Set up development environment793. Implement core functionality following patterns804. Write tests for critical paths815. Run tests and fix issues826. Document any deviations or decisions8384```python85# Example implementation following best practices86def example_function():87 # Your implementation here88 pass89```909192## Assumptions / Constraints / Non-goals9394* **Assumptions**:95 - Development environment is properly configured96 - Required dependencies are available97 - Team has basic understanding of domain98* **Constraints**:99 - Must follow existing codebase conventions100 - Time and resource limitations101 - Compatibility requirements102* **Non-goals**:103 - This skill does not cover edge cases outside scope104 - Not a replacement for formal training105106107## Compatibility & Prerequisites108109* **Supported Versions**:110 - Python 3.8+111 - Node.js 16+112 - Modern browsers (Chrome, Firefox, Safari, Edge)113* **Required AI Tools**:114 - Code editor (VS Code recommended)115 - Testing framework appropriate for language116 - Version control (Git)117* **Dependencies**:118 - Language-specific package manager119 - Build tools120 - Testing libraries121* **Environment Setup**:122 - `.env.example` keys: `API_KEY`, `DATABASE_URL` (no values)123124125## Test Scenario Matrix (QA Strategy)126127| Type | Focus Area | Required Scenarios / Mocks |128| :--- | :--- | :--- |129| **Unit** | Core Logic | Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |130| **Integration** | DB / API | All external API calls or database connections must be mocked during unit tests |131| **E2E** | User Journey | Critical user flows to test |132| **Performance** | Latency / Load | Benchmark requirements |133| **Security** | Vuln / Auth | SAST/DAST or dependency audit |134| **Frontend** | UX / A11y | Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |135136137## Technical Guardrails & Security Threat Model138139### 1. Security & Privacy (Threat Model)140* **Top Threats**: Injection attacks, authentication bypass, data exposure141- [ ] **Data Handling**: Sanitize all user inputs to prevent Injection attacks. Never log raw PII142- [ ] **Secrets Management**: No hardcoded API keys. Use Env Vars/Secrets Manager143- [ ] **Authorization**: Validate user permissions before state changes144145### 2. Performance & Resources146- [ ] **Execution Efficiency**: Consider time complexity for algorithms147- [ ] **Memory Management**: Use streams/pagination for large data148- [ ] **Resource Cleanup**: Close DB connections/file handlers in finally blocks149150### 3. Architecture & Scalability151- [ ] **Design Pattern**: Follow SOLID principles, use Dependency Injection152- [ ] **Modularity**: Decouple logic from UI/Frameworks153154### 4. Observability & Reliability155- [ ] **Logging Standards**: Structured JSON, include trace IDs `request_id`156- [ ] **Metrics**: Track `error_rate`, `latency`, `queue_depth`157- [ ] **Error Handling**: Standardized error codes, no bare except158- [ ] **Observability Artifacts**:159 - **Log Fields**: timestamp, level, message, request_id160 - **Metrics**: request_count, error_count, response_time161 - **Dashboards/Alerts**: High Error Rate > 5%162163164## Agent Directives & Error Recovery165*(ข้อกำหนดสำหรับ AI Agent ในการคิดและแก้ปัญหาเมื่อเกิดข้อผิดพลาด)*166167- **Thinking Process**: Analyze root cause before fixing. Do not brute-force.168- **Fallback Strategy**: Stop after 3 failed test attempts. Output root cause and ask for human intervention/clarification.169- **Self-Review**: Check against Guardrails & Anti-patterns before finalizing.170- **Output Constraints**: Output ONLY the modified code block. Do not explain unless asked.171172173## Definition of Done (DoD) Checklist174175- [ ] Tests passed + coverage met176- [ ] Lint/Typecheck passed177- [ ] Logging/Metrics/Trace implemented178- [ ] Security checks passed179- [ ] Documentation/Changelog updated180- [ ] Accessibility/Performance requirements met (if frontend)181182183## Anti-patterns184#185186## Reference Links & Examples187188* Internal documentation and examples189* Official documentation and best practices190* Community resources and discussions191192193## Versioning & Changelog194195* **Version**: 1.0.0196* **Changelog**:197 - 2026-02-22: Initial version with complete template structure198199---200> Converted and distributed by [TomeVault](https://tomevault.io/claim/amnadtaowsoam) — claim your Tome and manage your conversions.201<!-- tomevault:4.0:skill_md:2026-04-13 -->