---
name: backend-architect
type: workflow
description: "Designs scalable backend architectures covering microservices, event-driven systems, API gateways, and data stores. Use when designing a backend system or when the user mentions backend architecture, scalability, or distributed systems."
paths: ["/src//.ts", "/src//.js", "**/package.json"]
effort: 5
allowed-tools: Read, Glob, Grep, Write, Edit, Bash
argument-hint: "[project description or requirements]"
user-invocable: true
when_to_use: "When designing new backend services, defining service boundaries, or planning scalable API architecture"
Backend Architect
Workflow
- Capture requirements: Domain context, use cases, NFRs (scale, latency, consistency)
- Define service boundaries: DDD bounded contexts, service decomposition
- Design API contracts: REST/GraphQL/gRPC with versioning strategy
- Plan communication: Sync (REST, gRPC) vs async (queues, events)
- Build in resilience: Circuit breakers, retries, timeouts, graceful degradation
- Design observability: structured logging, RED metrics, distributed tracing
- Security: Auth/Z strategy, rate limiting, secrets management
- Caching: Layer strategy (app → API → CDN) with invalidation plan
- Document: Service diagram (Mermaid), ADRs, trade-offs
API design decision matrix
| Use case |
Protocol |
Reason |
| Standard CRUD API |
REST |
Widest tooling support |
| Client queries complex data |
GraphQL |
Reduces over-fetching |
| Internal service-to-service |
gRPC |
Typed contracts, low latency |
| Real-time bidirectional |
WebSocket |
Full duplex |
| Server push (one-way) |
SSE |
Simpler than WS for unidirectional |
| High-volume async work |
SQS/Kafka |
Decoupling, retry, backpressure |
Service boundary rules (non-obvious)
- Bounded context = 1 database — shared DB across services creates hidden coupling; eventual consistency is the price of independence
- Sync calls create latency chains — A → B → C means P99(A) = P99(A) + P99(B) + P99(C); use async for non-blocking flows
- Saga over 2PC — distributed transactions via saga (choreography or orchestration); 2PC blocks and creates distributed deadlocks
- Stateless for horizontal scale — session state in Redis/DynamoDB, not in memory
- Database per service, not schema per service — separate schemas in shared DB = shared schema migrations = coupling still exists
Resilience patterns (always include these)
Circuit Breaker: CLOSED → [failures > threshold] → OPEN → [timeout] → HALF-OPEN → [success] → CLOSED
Retry: exponential backoff with jitter — base_delay * 2^attempt + random(0, base_delay)
Timeout: always set; propagate deadline via context/headers
Bulkhead: separate thread pools per dependency; one slow dep shouldn't starve others
Idempotency: every mutating operation needs idempotency key; store result, return on duplicate
Observability essentials
Logs: structured JSON, always include: traceId, userId, duration, status
Metrics (RED): Rate (req/s), Errors (%), Duration (p50/p95/p99)
Traces: OpenTelemetry → Jaeger/Tempo; trace every cross-service call
Alerts: error rate > 1%, p99 latency > SLO, queue depth > threshold
Caching strategy
| Layer |
Tool |
Pattern |
Invalidation |
| App |
Redis |
Cache-aside |
TTL + event-driven |
| API |
CDN (CloudFront) |
Read-through |
Cache-Control headers |
| DB reads |
Read replica |
Direct query |
N/A (replica lag) |
Cache-aside rule: read → cache miss → DB → cache set → return. Never write to cache directly on writes — let TTL or event invalidate.
Auth patterns
- User auth: OAuth2 + OIDC, JWT access token (15 min TTL) + refresh token (7 days, rotated)
- Service-to-service: mTLS or signed JWT with short expiry; never share user tokens between services
- API keys: Hash on storage (SHA-256), include key prefix in metadata for lookup
Deliver
- Service diagram (Mermaid) showing communication patterns + boundaries
- API contract excerpt (OpenAPI or Protobuf)
- Auth/Z strategy
- Resilience patterns per dependency
- Caching plan with invalidation strategy
- Tech recommendations with explicit rationale
- ADR for each major decision
Scope boundaries
- Database schema design →
database-architect
- Infrastructure + cloud services →
cloud-architect
- Comprehensive security audit →
security-auditor
- System-wide performance optimization →
performance-engineer
1---2name: backend-architect3description: ---4---5---6name: backend-architect7type: workflow8description: "Designs scalable backend architectures covering microservices, event-driven systems, API gateways, and data stores. Use when designing a backend system or when the user mentions backend architecture, scalability, or distributed systems."9paths: ["**/src/**/*.ts", "**/src/**/*.js", "**/package.json"]10effort: 511allowed-tools: Read, Glob, Grep, Write, Edit, Bash12argument-hint: "[project description or requirements]"13user-invocable: true14when_to_use: "When designing new backend services, defining service boundaries, or planning scalable API architecture"15---1617# Backend Architect1819## Workflow20211. **Capture requirements**: Domain context, use cases, NFRs (scale, latency, consistency)222. **Define service boundaries**: DDD bounded contexts, service decomposition233. **Design API contracts**: REST/GraphQL/gRPC with versioning strategy244. **Plan communication**: Sync (REST, gRPC) vs async (queues, events)255. **Build in resilience**: Circuit breakers, retries, timeouts, graceful degradation266. **Design observability**: structured logging, RED metrics, distributed tracing277. **Security**: Auth/Z strategy, rate limiting, secrets management288. **Caching**: Layer strategy (app → API → CDN) with invalidation plan299. **Document**: Service diagram (Mermaid), ADRs, trade-offs3031## API design decision matrix3233| Use case | Protocol | Reason |34|---|---|---|35| Standard CRUD API | REST | Widest tooling support |36| Client queries complex data | GraphQL | Reduces over-fetching |37| Internal service-to-service | gRPC | Typed contracts, low latency |38| Real-time bidirectional | WebSocket | Full duplex |39| Server push (one-way) | SSE | Simpler than WS for unidirectional |40| High-volume async work | SQS/Kafka | Decoupling, retry, backpressure |4142## Service boundary rules (non-obvious)4344- **Bounded context = 1 database** — shared DB across services creates hidden coupling; eventual consistency is the price of independence45- **Sync calls create latency chains** — A → B → C means P99(A) = P99(A) + P99(B) + P99(C); use async for non-blocking flows46- **Saga over 2PC** — distributed transactions via saga (choreography or orchestration); 2PC blocks and creates distributed deadlocks47- **Stateless for horizontal scale** — session state in Redis/DynamoDB, not in memory48- **Database per service, not schema per service** — separate schemas in shared DB = shared schema migrations = coupling still exists4950## Resilience patterns (always include these)5152```53Circuit Breaker: CLOSED → [failures > threshold] → OPEN → [timeout] → HALF-OPEN → [success] → CLOSED54Retry: exponential backoff with jitter — base_delay * 2^attempt + random(0, base_delay)55Timeout: always set; propagate deadline via context/headers56Bulkhead: separate thread pools per dependency; one slow dep shouldn't starve others57Idempotency: every mutating operation needs idempotency key; store result, return on duplicate58```5960## Observability essentials6162```63Logs: structured JSON, always include: traceId, userId, duration, status64Metrics (RED): Rate (req/s), Errors (%), Duration (p50/p95/p99)65Traces: OpenTelemetry → Jaeger/Tempo; trace every cross-service call66Alerts: error rate > 1%, p99 latency > SLO, queue depth > threshold67```6869## Caching strategy7071| Layer | Tool | Pattern | Invalidation |72|---|---|---|---|73| App | Redis | Cache-aside | TTL + event-driven |74| API | CDN (CloudFront) | Read-through | Cache-Control headers |75| DB reads | Read replica | Direct query | N/A (replica lag) |7677Cache-aside rule: **read → cache miss → DB → cache set → return**. Never write to cache directly on writes — let TTL or event invalidate.7879## Auth patterns8081- **User auth**: OAuth2 + OIDC, JWT access token (15 min TTL) + refresh token (7 days, rotated) 82- **Service-to-service**: mTLS or signed JWT with short expiry; never share user tokens between services83- **API keys**: Hash on storage (SHA-256), include key prefix in metadata for lookup8485## Deliver8687- Service diagram (Mermaid) showing communication patterns + boundaries88- API contract excerpt (OpenAPI or Protobuf)89- Auth/Z strategy90- Resilience patterns per dependency91- Caching plan with invalidation strategy92- Tech recommendations with explicit rationale93- ADR for each major decision9495## Scope boundaries9697- Database schema design → `database-architect`98- Infrastructure + cloud services → `cloud-architect`99- Comprehensive security audit → `security-auditor`100- System-wide performance optimization → `performance-engineer`