| name | advanced-patterns |
| description | SOLID, 12-Factor, performance engineering, feature flags. Use when working on advanced-patterns tasks, related files, debugging, implementation, review, or verification workflows. |
Skill: Advanced Patterns & Principles
Auto-Detect
Trigger this skill when:
- Task mentions: SOLID, 12-Factor, feature flags, performance budget, circuit breaker
- Patterns: architecture principles, progressive enhancement, graceful degradation
- Context: system design decisions, scaling patterns, operational excellence
Decision Tree: Architecture Pattern
What problem are you solving?
+-- Need to decouple components?
| +-- Event-driven (pub/sub) or Dependency Injection
+-- Need resilience against failures?
| +-- Circuit breaker + retry + fallback
+-- Need gradual feature rollout?
| +-- Feature flags (OpenFeature standard)
+-- Need to scale reads vs writes differently?
| +-- CQRS (separate read/write models)
+-- Need to handle partial failures in distributed tx?
| +-- Saga pattern (choreography or orchestration)
+-- Need to enforce performance budgets?
+-- Performance gates in CI + monitoring
SOLID in Practice (2026)
class AuthService {
async authenticate(credentials: Credentials): Promise<AuthResult> { }
async refreshToken(token: string): Promise<TokenPair> { }
}
class UserProfileService {
async updateProfile(userId: string, data: ProfileUpdate): Promise<User> { }
}
interface PaymentProcessor {
charge(amount: Money, method: PaymentMethod): Promise<ChargeResult>;
refund(chargeId: string, amount: Money): Promise<RefundResult>;
}
class PaymentService {
constructor(private processors: Map<string, PaymentProcessor>) {}
async charge(method: PaymentMethod, amount: Money): Promise<ChargeResult> {
const processor = this.processors.get(method.type);
if (!processor) throw new UnsupportedPaymentMethod(method.type);
return processor.charge(amount, method);
}
}
interface ReadRepository<T> {
findById(id: string): Promise<T | null>;
findMany(filter: Filter): Promise<T[]>;
}
interface WriteRepository<T> {
create(data: CreateInput<T>): Promise<T>;
update(id: string, data: UpdateInput<T>): Promise<T>;
delete(id: string): Promise<void>;
}
class OrderService {
constructor(
private readonly orders: WriteRepository<Order>,
private readonly payments: PaymentProcessor,
private readonly notifications: NotificationSender,
) {}
}
12-Factor App (2026 Edition)
# | Factor | Modern Implementation
---|---------------------|----------------------------------------------
1 | Codebase | One repo, many deploys (monorepo OK with proper boundaries)
2 | Dependencies | Lockfile committed, pinned versions, no implicit deps
3 | Config | Env vars via secrets manager (Vault, AWS SSM, Doppler)
4 | Backing services | Treat as attached resources (connection string in config)
5 | Build/release/run | Container image = immutable artifact, GitOps deploy
6 | Processes | Stateless containers, state in external stores
7 | Port binding | Container exposes port, service mesh handles routing
8 | Concurrency | Horizontal pod autoscaling, queue workers scale independently
9 | Disposability | < 5s startup, graceful shutdown (drain connections, finish jobs)
10 | Dev/prod parity | Same container image, feature flags for differences
11 | Logs | Structured JSON to stdout, collected by platform (Loki, CloudWatch)
12 | Admin processes | One-off containers/jobs (Kubernetes Job, ECS task)
Beyond 12-Factor (2026 additions):
13 | Observability | OpenTelemetry traces + metrics + logs from day one
14 | Security | Zero-trust, mTLS between services, secrets rotation
15 | Feature management | Feature flags for decoupling deploy from release
Feature Flags (OpenFeature)
import { OpenFeature } from '@openfeature/server-sdk';
import { LaunchDarklyProvider } from '@launchdarkly/openfeature-node-server';
await OpenFeature.setProviderAndWait(new LaunchDarklyProvider(sdkKey));
const client = OpenFeature.getClient();
async function getCheckoutFlow(userId: string, plan: string): Promise<'legacy' | 'new' | 'experimental'> {
const context = { targetingKey: userId, plan, region: 'us-east' };
return client.getStringValue('checkout-flow', 'legacy', context);
}
const flow = await getCheckoutFlow(user.id, user.plan);
switch (flow) {
case 'new': return renderNewCheckout();
case 'experimental': return renderExperimentalCheckout();
default: return renderLegacyCheckout();
}
Circuit Breaker
enum CircuitState { CLOSED, OPEN, HALF_OPEN }
class CircuitBreaker {
private state = CircuitState.CLOSED;
private failures = 0;
private lastFailureTime = 0;
private successesInHalfOpen = 0;
constructor(
private readonly threshold: number = 5,
private readonly timeout: number = 30_000,
private readonly halfOpenMax: number = 3,
) {}
async execute<T>(fn: () => Promise<T>, fallback?: () => T): Promise<T> {
if (this.state === CircuitState.OPEN) {
if (Date.now() - this.lastFailureTime > this.timeout) {
this.state = CircuitState.HALF_OPEN;
this.successesInHalfOpen = 0;
} else {
if (fallback) return fallback();
throw new CircuitOpenError('Circuit is open');
}
}
try {
const result = await fn();
this.onSuccess();
return result;
} catch (error) {
this.onFailure();
if (fallback) return fallback();
throw error;
}
}
private onSuccess(): void {
if (this.state === CircuitState.HALF_OPEN) {
this.successesInHalfOpen++;
if (this.successesInHalfOpen >= this.halfOpenMax) {
this.state = CircuitState.CLOSED;
this.failures = 0;
}
} else {
this.failures = 0;
}
}
private onFailure(): void {
this.failures++;
this.lastFailureTime = Date.now();
if (this.failures >= this.threshold) {
this.state = CircuitState.OPEN;
}
}
}
const paymentCircuit = new CircuitBreaker(3, 60_000);
const result = await paymentCircuit.execute(
() => paymentGateway.charge(amount),
() => ({ status: 'queued', message: 'Payment will be retried' })
);
Performance Engineering
const performanceBudget = {
web: {
LCP: 2500,
FID: 100,
CLS: 0.1,
TTI: 3500,
bundleSize: 200_000,
},
api: {
p50: 100,
p95: 500,
p99: 1000,
errorRate: 0.001,
},
};
Progressive Enhancement
if ('IntersectionObserver' in window) {
} else {
}
Anti-Patterns
| Anti-Pattern | Problem | Solution |
|---|
| SOLID dogmatism | Over-abstraction, 10 files for simple feature | Apply SOLID proportionally to complexity |
| Feature flags never cleaned up | Flag spaghetti, dead code paths | 30-day rule: at 100% → remove flag + old code |
| No circuit breaker on external calls | Cascade failures take down system | Circuit breaker + fallback for all external deps |
| Optimizing without measuring | Wasted effort on non-bottlenecks | Profile first, budget second, optimize third |
| Premature microservices | Distributed monolith, 10x complexity | Monolith first → modular → extract if proven need |
| No graceful degradation | One failure = total outage | Fallbacks at every integration point |
| Config in code | Rebuild to change behavior | Environment variables + feature flags |
| No performance gates in CI | Regressions ship silently | Lighthouse CI, bundle size checks, load tests |
Verification Checklist