-
Notifications
You must be signed in to change notification settings - Fork 0
[C] Generation Microservices
Code Generation Principles Mapped to Microservices
This document maps the Non-Negotiable Principles for Code Generation (with Anti-Patterns) to a microservices architecture.
Microservices amplify both the benefits and risks of code generation:
- Done well, generators reduce duplication and enforce consistency at scale.
- Done poorly, generators create distributed technical debt that is hard to unwind.
This mapping shows how each principle applies concretely in a microservices environment.
Microservices introduce:
- many independent codebases,
- many deployment pipelines,
- many service owners,
- long-lived backward compatibility requirements.
Therefore:
Any weakness in code generation multiplies by the number of services.
Each team must own and understand the templates that generate service code.
- Shared template repositories with versioning (e.g.,
service-template-vX) - Explicit template version pinned per service
- Clear changelogs for template evolution
- Ability for teams to fork or replace templates if needed
- Central platform team controls opaque generators
- “Golden template” that teams cannot modify
- Forced upgrades of templates across services
- Debugging failures by patching generated service code
- Dozens of services stuck on unmaintainable scaffolding
- Platform bottlenecks slow all teams simultaneously
Service definitions must exist outside the generated service code.
- Explicit service descriptors (YAML/JSON/DSL):
- API contracts
- data models
- dependencies
- deployment metadata
- Metadata stored per service and validated independently
- Metadata reused by generators, CI/CD, docs, and observability
- Metadata inferred from code annotations only
- Configuration scattered across repos and pipelines
- Generator-specific metadata formats no one else can read
- Services drift from their intended contracts
- Impossible to reason about system topology
Any service must be rebuildable from scratch with one command.
-
make generateor equivalent per service - Deterministic outputs across machines and CI
- Regeneration does not depend on existing generated files
- CI verifies regeneration produces no diff
- Manual fixes applied after generation
- Regeneration requires tribal knowledge
- Different services regenerate differently
- Inconsistent services
- Broken disaster recovery
- Platform upgrades become dangerous
Business logic inside services must be generator-safe.
- Clear separation:
-
/generated→ disposable -
/domainor/service→ handwritten
-
- Explicit extension points (hooks, adapters, ports)
- Regeneration never touches business logic
- Business logic mixed into generated scaffolding
- “Just edit the generated controller” culture
- No clear ownership of files
- Teams stop regenerating
- Divergent service behavior
- Generator abandonment
Generated service scaffolding must be production-grade, not demo-grade.
- Generated services:
- are testable by default,
- integrate observability (logs, metrics, traces),
- handle errors consistently,
- meet performance baselines.
- Generated code follows team coding standards
- Massive generated frameworks per service
- Excessive abstraction to “cover all cases”
- Poor performance hidden behind network calls
- Latency explosions
- Debugging distributed failures becomes impossible
- Operational cost overwhelms development speed
- Platform team enforces generators without escape hatches
- Teams lose autonomy
- Innovation stalls
- Services generated once and never regenerated
- Template evolution stops
- System fragments over time
- Architecture decisions encoded only in templates
- No ADRs or human review
- Architecture becomes unchangeable
- Templates define conventions, not behavior
- Metadata defines intent; generators enforce consistency
- Regeneration must be boring and safe
- Service autonomy beats template purity
- If a service cannot be regenerated, the generator has failed
- “This service is special; don’t regenerate it.”
- “Only the platform team understands the generator.”
- “We had to hotfix the generated code.”
- “Template upgrades are too risky.”
In microservices:
- code generation is not optional discipline — it is survival discipline.
- bad generators scale failure faster than any human mistake.
Used correctly, code generation:
- enforces consistency,
- preserves autonomy,
- and keeps hundreds of services evolvable.
Microservices reward boring generation and punish clever generation.
The safest generator is the one teams trust enough to run every day.