Coding
AI Prompt for Microservice Extraction
Extract microservices safely with this AI prompt: service boundaries, API contracts, data migration strategy, and reversible strangler steps included.
The prompt
Role: You are a systems architect who extracts microservices from monoliths without big-bang rewrites. Context: Monolith: [STACK]. Code to extract: [CODE_OR_MODULE]. Intended service responsibility: [SERVICE_RESPONSIBILITY]. Current coupling: [COUPLING: shared DB / shared code / none]. Task: 1) Define the service boundary: what goes in, what stays out, and the API contract (endpoints/messages with schemas). 2) Design the data strategy: shared DB initially vs own DB with migration plan — justify the choice. 3) Write the extraction plan as strangler steps: each step independently deployable and reversible. 4) List the new failure modes (network, partial failure, eventual consistency) and how each is handled. 5) Define when the extraction is DONE (old code deleted, traffic fully shifted). Format: Boundary + contract first, then data strategy, then the step plan, then failure modes, then done-criteria. Constraints: No big-bang cutover — every step must be reversible. Be explicit about consistency trade-offs; distributed transactions need justification. The API contract comes before code.
Variables to fill in
Replace each [variable] in the prompt with your own details:
[STACK] [CODE_OR_MODULE] [SERVICE_RESPONSIBILITY] [COUPLING]
Example input
CODE=monolithic order processing function (validate → charge → inventory → notify), TARGET=standalone microservice, STACK=Node.js, BOUNDARIES=keep DB shared initially
How to use this prompt
Describe the current boundaries (shared DB? shared code?) — they constrain the extraction. Define the service's responsibility crisply; vague boundaries create distributed monoliths.
Tips for the best results
- Define 'done' upfront — extractions stall at 90% without it.
- Ask for the failure-mode list; distributed systems fail in new ways.
- Challenge whether a well-structured module beats a microservice for your scale.
Frequently asked questions
Does it just copy the function?
It designs the service boundary, API, and extraction steps — the hard part of microservices is the boundary, not the code.
How do I know the service boundary is right?
It changes for one business reason at a time and owns its data. The prompt tests your boundary against those two criteria before designing anything.