AgentSkillsCN

12 Factor Apps

12 因子应用

SKILL.md

12-Factor Apps

yaml
name: 12-factor-apps
description: Cloud-native application design principles for portable, scalable, maintainable systems

When to Use This Skill

  • Building cloud-native applications that need to run across different environments
  • Preparing for containerization (Docker, Kubernetes) or serverless deployment
  • Diagnosing deployment issues related to configuration, state, or environment coupling
  • Evaluating application architecture for production readiness
  • Onboarding teams to modern deployment practices

Philosophy

The 12-factor methodology emerged from Heroku's experience deploying thousands of applications. It codifies patterns that make applications:

  • Portable: Run identically in development, staging, and production
  • Scalable: Scale horizontally by adding process instances
  • Maintainable: Clear boundaries between concerns
  • Resilient: Handle failures gracefully through statelessness and disposability

These aren't arbitrary rules—each factor addresses a specific class of problems encountered at scale.

The 12 Factors at a Glance

#FactorPrincipleWhy It Matters
1CodebaseOne codebase, many deploysEliminates "works on my machine" drift
2DependenciesExplicitly declare and isolateReproducible builds, no implicit system dependencies
3ConfigStore in environmentSecrets stay out of code, environment-specific settings
4Backing ServicesTreat as attached resourcesSwap databases, caches, queues without code changes
5Build, Release, RunStrictly separate stagesImmutable releases, traceable deployments
6ProcessesExecute as stateless processesHorizontal scaling, crash recovery
7Port BindingExport services via port bindingSelf-contained services, no runtime injection
8ConcurrencyScale via the process modelCPU-bound vs I/O-bound process types
9DisposabilityFast startup, graceful shutdownElastic scaling, zero-downtime deploys
10Dev/Prod ParityKeep environments similarCatch issues early, reduce deployment surprises
11LogsTreat as event streamsCentralized aggregation, structured observability
12Admin ProcessesRun as one-off processesMigrations, scripts run in same environment

For detailed implementation guidance, see factors-overview.md.

Modern Context

The 12-factor methodology predates containers and Kubernetes, but its principles map directly:

12-Factor ConceptModern Implementation
Stateless processesContainer ephemeral storage
Config in environmentConfigMaps, Secrets, Parameter Store
Port bindingContainer networking, service mesh
DisposabilityPod lifecycle, liveness/readiness probes
ConcurrencyHorizontal Pod Autoscaler, replica sets
Build/Release/RunCI/CD pipelines, GitOps, container registries

Serverless embraces these factors implicitly—functions are stateless, ephemeral, and scaled by the platform.

Limitations and Extensions

The original 12 factors focus on application architecture. They don't deeply address:

  • Security: Authentication, authorization, secrets rotation
  • Telemetry: Metrics, tracing, health endpoints (beyond logs)
  • API contracts: Versioning, backwards compatibility
  • Service dependencies: Circuit breakers, timeouts, retries

Modern "15-factor" and "beyond 12-factor" extensions add:

  • API First: Design contracts before implementation
  • Telemetry: Metrics and distributed tracing
  • Authentication/Authorization: Security as a first-class concern

Reference Documents

Detailed implementation guidance organized by concern:

Attribution

Primary Source:

Supporting Resources:

  • Kevin Hoffman, Beyond the Twelve-Factor App (O'Reilly, 2016)
  • AWS: Applying the Twelve-Factor App Methodology to Serverless Applications
  • Red Hat: 12-Factor App Meets Kubernetes