AgentSkillsCN

backend-engineering

使用 Rust(Axum)构建生产级、可扩展的后端,为高性能服务提供支持;同时利用 FastAPI 构建 Python API。涵盖 ML 推理服务(ONNX、vLLM、TensorRT)、事件驱动架构(Kafka、RabbitMQ、Redis)、Docker/Kubernetes 编排,以及 AWS 部署(ECS、EKS、Lambda)。适用于构建 API、微服务、实时系统、ML 服务基础设施,或在 AWS 上部署容器化应用时使用。

SKILL.md
--- frontmatter
name: backend-engineering
description: Build production-grade, scalable backends with Rust (Axum) for high-performance services and FastAPI for Python APIs. Includes ML inference serving (ONNX, vLLM, TensorRT), event-driven architecture (Kafka, RabbitMQ, Redis), Docker/Kubernetes orchestration, and AWS deployment (ECS, EKS, Lambda). Use when building APIs, microservices, real-time systems, ML serving infrastructure, or deploying containerized applications to AWS.

Backend Engineering Skill

Build scalable, high-performance backends using the right tool for each layer.

Language Selection Framework

Use CaseChooseRationale
High-throughput streamingRust/AxumMemory efficiency, no GC pauses
ML inference orchestrationFastAPILibrary ecosystem, model compatibility
CRUD APIs, rapid prototypingFastAPIDevelopment velocity
Sub-millisecond latencyRust/AxumPredictable performance
Data pipelinesHybridRust for hot paths, Python for orchestration

Quick Start Patterns

FastAPI Service

python
from fastapi import FastAPI, Depends
from sqlalchemy.ext.asyncio import AsyncSession
from contextlib import asynccontextmanager

@asynccontextmanager
async def lifespan(app: FastAPI):
    # Startup: initialize pools, connections
    yield
    # Shutdown: cleanup

app = FastAPI(lifespan=lifespan)

@app.get("/health")
async def health(): return {"status": "ok"}

Rust/Axum Service

rust
use axum::{routing::get, Router, Json};
use std::sync::Arc;

#[derive(Clone)]
struct AppState { /* db pools, config */ }

async fn health() -> Json<serde_json::Value> {
    Json(serde_json::json!({"status": "ok"}))
}

#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/health", get(health))
        .with_state(Arc::new(AppState {}));
    
    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
    axum::serve(listener, app).await.unwrap();
}

Reference Documentation

Consult these references based on task requirements:

TaskReference File
FastAPI patterns, async DB, testingreferences/fastapi.md
Rust/Axum services, SQLx, error handlingreferences/rust.md
ML inference, quantization, vLLMreferences/ml-serving.md
Kafka, RabbitMQ, Redis, event patternsreferences/event-driven.md
Docker multi-stage builds, securityreferences/docker.md
Kubernetes production patternsreferences/kubernetes.md
AWS ECS, EKS, Lambda, CDKreferences/aws.md

Architecture Decision Flow

code
New Backend Service Request
           │
           ▼
┌──────────────────────────┐
│ Latency requirement?      │
│ < 10ms → Rust            │
│ > 10ms → FastAPI ok      │
└──────────────────────────┘
           │
           ▼
┌──────────────────────────┐
│ ML model serving?         │
│ LLM → vLLM               │
│ Vision/NLP → ONNX/TensorRT│
│ None → skip              │
└──────────────────────────┘
           │
           ▼
┌──────────────────────────┐
│ Event-driven?             │
│ High throughput → Kafka  │
│ Complex routing → RabbitMQ│
│ Real-time → Redis Streams│
└──────────────────────────┘
           │
           ▼
┌──────────────────────────┐
│ Deployment target?        │
│ Simple → ECS Fargate     │
│ Complex/Multi-cloud → EKS│
│ Event handlers → Lambda  │
└──────────────────────────┘

Production Checklist

Before deploying any service:

  • Health checks (liveness + readiness)
  • Graceful shutdown handling
  • Resource limits configured (CPU, memory)
  • Connection pooling tuned
  • Circuit breakers on external calls
  • Structured logging (JSON)
  • Distributed tracing enabled
  • Secrets in Secrets Manager
  • Multi-stage Docker build
  • Auto-scaling configured