Model Serving Inference
Skill Profile
(Select at least one profile to enable specific modules)
Overview
Model serving is the process of deploying ML models to production and handling inference requests efficiently at scale.
Why This Matters
- Performance: Optimize inference latency and throughput
- Scalability: Handle production traffic efficiently
- Cost: Reduce infrastructure costs through optimization
- Reliability: Ensure consistent model performance
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:
- Model checkpoints and configurations
- Inference requests (prompts, parameters)
- Scaling policies and thresholds
- Monitoring and logging configuration
- Entry Conditions:
- Model trained and exported
- Serving infrastructure deployed
- Load balancer configured
- Monitoring system in place
- Outputs:
- Model responses (generated text, tokens)
- Inference metrics (latency, throughput)
- Scaling events
- Monitoring alerts
- Artifacts Required (Deliverables):
- Model serving configuration
- Load balancer configuration
- Monitoring dashboard
- Scaling policies
- Acceptance Evidence:
- Model serving endpoints accessible
- Inference latency within SLA
- Throughput meets requirements
- Auto-scaling working
- Success Criteria:
- P50 latency < 100ms
- P95 latency < 500ms
- Throughput > 100 req/s
- GPU utilization > 70%
Skill Composition
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 / Pitfalls
- ⛔ Don't: Log PII, catch-all exception, N+1 queries
- ⚠️ Watch out for: Common symptoms and quick fixes
- 💡 Instead: Use proper error handling, pagination, and logging
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
1---2name: model-serving-inference3description: Model serving is the process of deploying ML models to production and handling inference requests efficiently at scale.4---5
6# Model Serving Inference
7
8## Skill Profile
9*(Select at least one profile to enable specific modules)*
10- [ ] **DevOps**
11- [x] **Backend**
12- [ ] **Frontend**
13- [ ] **AI-RAG**
14- [ ] **Security Critical**
15
16## Overview
17Model serving is the process of deploying ML models to production and handling inference requests efficiently at scale.
18
19## Why This Matters
20- **Performance**: Optimize inference latency and throughput
21- **Scalability**: Handle production traffic efficiently
22- **Cost**: Reduce infrastructure costs through optimization
23- **Reliability**: Ensure consistent model performance
24
25---
26
27## Core Concepts & Rules
28
29### 1. Core Principles
30- Follow established patterns and conventions
31- Maintain consistency across codebase
32- Document decisions and trade-offs
33
34### 2. Implementation Guidelines
35- Start with the simplest viable solution
36- Iterate based on feedback and requirements
37- Test thoroughly before deployment
38
39
40## Inputs / Outputs / Contracts
41* **Inputs**:
42 - Model checkpoints and configurations
43 - Inference requests (prompts, parameters)
44 - Scaling policies and thresholds
45 - Monitoring and logging configuration
46* **Entry Conditions**:
47 - Model trained and exported
48 - Serving infrastructure deployed
49 - Load balancer configured
50 - Monitoring system in place
51* **Outputs**:
52 - Model responses (generated text, tokens)
53 - Inference metrics (latency, throughput)
54 - Scaling events
55 - Monitoring alerts
56* **Artifacts Required (Deliverables)**:
57 - Model serving configuration
58 - Load balancer configuration
59 - Monitoring dashboard
60 - Scaling policies
61* **Acceptance Evidence**:
62 - Model serving endpoints accessible
63 - Inference latency within SLA
64 - Throughput meets requirements
65 - Auto-scaling working
66* **Success Criteria**:
67 - P50 latency < 100ms
68 - P95 latency < 500ms
69 - Throughput > 100 req/s
70 - GPU utilization > 70%
71
72## Skill Composition
73* **Depends on**: [skill-llm-security-redteaming](./llm-security-redteaming/), [skill-prompting-patterns](./prompting-patterns/)
74* **Compatible with**: [skill-retrieval-quality](./retrieval-quality/), [skill-kubernetes-platform](../../62-scale-operations/kubernetes-platform/)
75* **Conflicts with**: None
76* **Related Skills**: [skill-data-migrations-backfill](../../62-scale-operations/data-migrations-backfill/), [skill-multi-tenancy-saas](../../62-scale-operations/multi-tenancy-saas/)
77
78---
79
80## Quick Start / Implementation Example
81
821. Review requirements and constraints
832. Set up development environment
843. Implement core functionality following patterns
854. Write tests for critical paths
865. Run tests and fix issues
876. Document any deviations or decisions
88
89```python
90# Example implementation following best practices
91def example_function():
92 # Your implementation here
93 pass
94```
95
96
97## Assumptions / Constraints / Non-goals
98
99* **Assumptions**:
100 - Development environment is properly configured
101 - Required dependencies are available
102 - Team has basic understanding of domain
103* **Constraints**:
104 - Must follow existing codebase conventions
105 - Time and resource limitations
106 - Compatibility requirements
107* **Non-goals**:
108 - This skill does not cover edge cases outside scope
109 - Not a replacement for formal training
110
111
112## Compatibility & Prerequisites
113
114* **Supported Versions**:
115 - Python 3.8+
116 - Node.js 16+
117 - Modern browsers (Chrome, Firefox, Safari, Edge)
118* **Required AI Tools**:
119 - Code editor (VS Code recommended)
120 - Testing framework appropriate for language
121 - Version control (Git)
122* **Dependencies**:
123 - Language-specific package manager
124 - Build tools
125 - Testing libraries
126* **Environment Setup**:
127 - `.env.example` keys: `API_KEY`, `DATABASE_URL` (no values)
128
129
130## Test Scenario Matrix (QA Strategy)
131
132| Type | Focus Area | Required Scenarios / Mocks |
133| :--- | :--- | :--- |
134| **Unit** | Core Logic | Must cover primary logic and at least 3 edge/error cases. Target minimum 80% coverage |
135| **Integration** | DB / API | All external API calls or database connections must be mocked during unit tests |
136| **E2E** | User Journey | Critical user flows to test |
137| **Performance** | Latency / Load | Benchmark requirements |
138| **Security** | Vuln / Auth | SAST/DAST or dependency audit |
139| **Frontend** | UX / A11y | Accessibility checklist (WCAG), Performance Budget (Lighthouse score) |
140
141
142## Technical Guardrails & Security Threat Model
143
144### 1. Security & Privacy (Threat Model)
145* **Top Threats**: Injection attacks, authentication bypass, data exposure
146- [ ] **Data Handling**: Sanitize all user inputs to prevent Injection attacks. Never log raw PII
147- [ ] **Secrets Management**: No hardcoded API keys. Use Env Vars/Secrets Manager
148- [ ] **Authorization**: Validate user permissions before state changes
149
150### 2. Performance & Resources
151- [ ] **Execution Efficiency**: Consider time complexity for algorithms
152- [ ] **Memory Management**: Use streams/pagination for large data
153- [ ] **Resource Cleanup**: Close DB connections/file handlers in finally blocks
154
155### 3. Architecture & Scalability
156- [ ] **Design Pattern**: Follow SOLID principles, use Dependency Injection
157- [ ] **Modularity**: Decouple logic from UI/Frameworks
158
159### 4. Observability & Reliability
160- [ ] **Logging Standards**: Structured JSON, include trace IDs `request_id`
161- [ ] **Metrics**: Track `error_rate`, `latency`, `queue_depth`
162- [ ] **Error Handling**: Standardized error codes, no bare except
163- [ ] **Observability Artifacts**:
164 - **Log Fields**: timestamp, level, message, request_id
165 - **Metrics**: request_count, error_count, response_time
166 - **Dashboards/Alerts**: High Error Rate > 5%
167
168
169## Agent Directives & Error Recovery
170*(ข้อกำหนดสำหรับ AI Agent ในการคิดและแก้ปัญหาเมื่อเกิดข้อผิดพลาด)*
171
172- **Thinking Process**: Analyze root cause before fixing. Do not brute-force.
173- **Fallback Strategy**: Stop after 3 failed test attempts. Output root cause and ask for human intervention/clarification.
174- **Self-Review**: Check against Guardrails & Anti-patterns before finalizing.
175- **Output Constraints**: Output ONLY the modified code block. Do not explain unless asked.
176
177
178## Definition of Done (DoD) Checklist
179
180- [ ] Tests passed + coverage met
181- [ ] Lint/Typecheck passed
182- [ ] Logging/Metrics/Trace implemented
183- [ ] Security checks passed
184- [ ] Documentation/Changelog updated
185- [ ] Accessibility/Performance requirements met (if frontend)
186
187
188## Anti-patterns / Pitfalls
189
190* ⛔ **Don't**: Log PII, catch-all exception, N+1 queries
191* ⚠️ **Watch out for**: Common symptoms and quick fixes
192* 💡 **Instead**: Use proper error handling, pagination, and logging
193
194
195## Reference Links & Examples
196
197* Internal documentation and examples
198* Official documentation and best practices
199* Community resources and discussions
200
201
202## Versioning & Changelog
203
204* **Version**: 1.0.0
205* **Changelog**:
206 - 2026-02-22: Initial version with complete template structure
207