Migrating from a monolithWhat is monolith?A software architecture where the entire application lives in a single codebase and deploys as one unit. Simpler to build and debug than microservices. to microservicesWhat is microservices?An architecture where an application is split into small, independently deployed services that communicate over the network, each owning its own data. is one of the highest-stakes architectural changes a team can make. It touches every part of the system: code structure, data storage, deployment, monitoring, and team organization. AI tools can accelerate parts of this process significantly, but they can also lead you astray if you trust them without verification.
This lesson covers where AI genuinely helps with migrationWhat is migration?A versioned script that changes your database structure (add a column, create a table) so every developer and server stays in sync. planning, where it fails, and how to build a workflow that gets the best of both.
AI strengths and weaknesses for migrationWhat is migration?A versioned script that changes your database structure (add a column, create a table) so every developer and server stays in sync.
| Task | AI capability | Trust level | Why |
|---|---|---|---|
| Analyzing code coupling | Strong | Medium | Can scan imports, call graphs, shared types |
| Suggesting service boundaries | Moderate | Low | Splits too aggressively, ignores data coupling |
| Generating API contracts | Strong | High | Boilerplate generation is AI's sweet spot |
| Writing migration scripts | Moderate | Medium | Gets the happy path right, misses edge cases |
| Estimating effort/timeline | Weak | Very low | No context about your team or codebase quirks |
| Planning data migration | Weak | Low | Underestimates referential integrity challenges |
| Scaffolding new services | Strong | High | Docker, CI/CD, project structure, reliable |
| Identifying the distributed monolith risk | Moderate | Medium | Knows the theory, misses your specific patterns |
Prompt: identifying service boundaries
One of the most valuable things AI can do is analyze your monolithWhat is monolith?A software architecture where the entire application lives in a single codebase and deploys as one unit. Simpler to build and debug than microservices.'s code structure and suggest where natural boundaries exist. Here's a prompt pattern that works:
I have a Node.js monolith with the following module structure:
src/
modules/
users/ (User model, auth, profile management)
orders/ (Order creation, status tracking, history)
payments/ (Stripe integration, refunds, invoicing)
inventory/ (Stock levels, warehouse locations)
notifications/ (Email, SMS, push notifications)
analytics/ (Event tracking, dashboards)
shipping/ (Carrier integration, tracking)
The users module is imported by: orders, payments, notifications
The orders module is imported by: payments, shipping, notifications, analytics
The payments module is imported by: orders (for refund status)
The inventory module is imported by: orders
Suggest which modules could become independent services and which
should stay together. For each suggestion, explain the data coupling
implications and what would need to change.AI will typically suggest splitting each moduleWhat is module?A self-contained file of code with its own scope that explicitly exports values for other files to import, preventing name collisions. into its own service. Your job is to push back. Ask follow-up questions:
For the orders-payments boundary you suggested:
1. Orders and payments share a database transaction today (charge + create order is atomic). How would you handle this as separate services?
2. The payments module queries the orders table directly for refund eligibility. How do you decouple this?
3. What happens if the payment service is down when a user tries to place an order?These follow-ups force AI to confront the real complexity it initially glossed over.
Prompt: analyzing coupling in code
AI can scan code for coupling signals that humans miss:
Analyze this module's dependencies and identify coupling that
would make it hard to extract as a separate service:
[paste the module's main files]
Look for:
1. Direct database queries to tables owned by other modules
2. Shared types or interfaces that cross module boundaries
3. Synchronous function calls that would become network calls
4. Transaction blocks that span multiple modules
5. Shared in-memory state (caches, singletons)AI is genuinely good at this because it's pattern matching across code, exactly what LLMs excel at. It will find imports you forgot about, shared utility functions, and transitive dependencies.
What to verify: AI's common mistakes
1. AI splits too aggressively
AI defaults to "one moduleWhat is module?A self-contained file of code with its own scope that explicitly exports values for other files to import, preventing name collisions. = one service." This is almost always wrong for early-stage migrations. A better starting point is 2-3 services that solve a specific scaling or team-ownership problem, with the restWhat is rest?An architectural style for web APIs where URLs represent resources (nouns) and HTTP methods (GET, POST, PUT, DELETE) represent actions on those resources. staying in the monolithWhat is monolith?A software architecture where the entire application lives in a single codebase and deploys as one unit. Simpler to build and debug than microservices..
When AI suggests 8 services, ask: "Which 2 would give us the most benefit with the least risk?" That's usually the right first step.
2. AI ignores data coupling
This is the biggest blind spot. AI will suggest splitting the orders and payments modules into separate services without addressing that they share database tables, foreign keys, and transactions.
Questions to ask:
- Which tables does each proposed service need?
- Are there foreign keys between them?
- Are there transactions that spanWhat is span?One unit of work within a distributed trace, with a start time, duration, and optional attributes describing the operation. both?
- How much data needs to be duplicated or synced?
Data is the hardest part of any migrationWhat is migration?A versioned script that changes your database structure (add a column, create a table) so every developer and server stays in sync.. If AI's plan doesn't have a detailed data migration strategy, it's incomplete.
3. AI underestimates operational complexity
AI will generate a clean architecture diagram with separate services, message queues, and an API gatewayWhat is api gateway?A single entry point that sits in front of multiple backend services, routing requests to the right one and handling shared concerns like authentication and rate limiting.. What it won't mention:
- You need monitoring and alerting for each service separately
- Network failures between services will cause partial failures
- You need distributed tracingWhat is distributed tracing?Tracking a single request as it travels through multiple services, showing timing and dependencies at each step. to debug cross-service issues
- Each service needs its own CI/CDWhat is ci/cd?Continuous Integration and Continuous Deployment - automated pipelines that test your code on every push and deploy it when tests pass. pipelineWhat is pipeline?A sequence of automated steps (install, lint, test, build, deploy) that code passes through before reaching production.
- Database migrations become per-service
- On-call rotation becomes more complex
Ask AI to list the operational requirements for its proposed architecture. Then estimate whether your team can realistically handle them.
4. AI forgets the migration path
AI tends to show you the end state, a clean microservicesWhat is microservices?An architecture where an application is split into small, independently deployed services that communicate over the network, each owning its own data. architecture, without explaining how to get there from your current monolith. The migration path matters more than the target architecture.
Given your suggested target architecture, create a phased migration plan:
- Phase 1: What's the first service to extract? Why?
- Phase 2: What's next? What dependencies does it have on Phase 1?
- For each phase: what's the rollback plan if it fails?
- How long should we run the old and new systems in parallel?
- What metrics tell us the migration is working?Hybrid workflow for migrationWhat is migration?A versioned script that changes your database structure (add a column, create a table) so every developer and server stays in sync. planning
Here's a workflow that uses AI effectively without over-trusting it:
Step 1: AI analyzes the codebase. Give AI your moduleWhat is module?A self-contained file of code with its own scope that explicitly exports values for other files to import, preventing name collisions. structure, import graphs, and database schemaWhat is schema?A formal definition of the structure your data must follow - which fields exist, what types they have, and which are required.. Let it identify coupling hotspots and suggest potential boundaries.
Step 2: Human validates against reality. Check AI's suggestions against: your team size, your deployment maturity, your actual scaling bottlenecks, and your data coupling. Reject suggestions that don't solve a real problem.
Step 3: AI drafts the technical plan. For the boundaries you agreed on, ask AI to generate: APIWhat is api?A set of rules that lets one program talk to another, usually over the internet, by sending requests and getting responses. contracts between services, database migration scripts, DockerWhat is docker?A tool that packages your application and all its dependencies into a portable container that runs identically on any machine. and CI/CDWhat is ci/cd?Continuous Integration and Continuous Deployment - automated pipelines that test your code on every push and deploy it when tests pass. configuration, and the strangler fig routing rules.
Step 4: Human reviews for gaps. Check the plan for: missing error handling, data consistency issues, operational requirements, and rollbackWhat is rollback?Undoing a database migration or deployment to restore the previous state when something goes wrong. procedures.
Step 5: AI implements the agreed plan. Once the plan is validated, AI can scaffold the new services, generate boilerplateWhat is boilerplate?Repetitive, standardized code that follows a known pattern and appears in nearly every project - like setting up a server or wiring up database connections., and even write the proxy routing that gradually shifts traffic.
The pattern is consistent: AI drafts, human validates, AI implements. Skip the validation step and you'll end up with an architecturally clean disaster.
Quick reference
| Use AI for | Don't trust AI for |
|---|---|
| Code coupling analysis | Deciding how many services you need |
| API contract generation | Data migration strategy |
| Service scaffolding (Docker, CI/CD) | Estimating migration timeline |
| Identifying shared dependencies | Understanding your team's operational capacity |
| Generating migration scripts | Knowing when to stop splitting |