0
0
Microservicessystem_design~25 mins

Why gradual migration reduces risk in Microservices - Design It to Understand It

Choose your learning style9 modes available
Design: Gradual Migration in Microservices
Focus on migration strategy and risk reduction techniques. Out of scope: detailed microservice implementation or specific technology stacks.
Functional Requirements
FR1: Migrate a monolithic application to microservices step-by-step
FR2: Ensure system remains functional during migration
FR3: Minimize downtime and user impact
FR4: Allow rollback of changes if issues occur
FR5: Enable testing of new microservices independently
Non-Functional Requirements
NFR1: Support at least 10,000 concurrent users during migration
NFR2: API response latency p99 under 300ms
NFR3: Availability target 99.9% uptime during migration
NFR4: Data consistency must be maintained between old and new systems
Think Before You Design
Questions to Ask
❓ Question 1
❓ Question 2
❓ Question 3
❓ Question 4
❓ Question 5
Key Components
API Gateway or Router for traffic splitting
Service Registry for discovery
Message queues for asynchronous communication
Database synchronization or dual writes
Monitoring and logging tools
Design Patterns
Strangler Fig pattern
Canary releases
Blue-Green deployment
Feature toggles
Circuit breaker pattern
Reference Architecture
Monolith System
   |
   | Gradual Migration
   v
+-------------------+       +-------------------+
| Old Monolith      |<----->| API Gateway       |
+-------------------+       +-------------------+
                                |          |
                                |          v
                                |    +-------------------+
                                |    | New Microservice 1 |
                                |    +-------------------+
                                |
                                v
                           +-------------------+
                           | New Microservice 2 |
                           +-------------------+
Components
API Gateway
Nginx, Kong, or custom proxy
Route requests to old monolith or new microservices based on migration progress
Old Monolith
Existing monolithic application
Serve requests not yet migrated
New Microservices
Docker containers, Kubernetes
Handle migrated functionality independently
Database Synchronization
Dual writes, change data capture
Keep data consistent between old and new systems
Monitoring & Logging
Prometheus, ELK stack
Track system health and detect issues early
Request Flow
1. Client sends request to API Gateway.
2. API Gateway decides to route request to old monolith or new microservice based on migration phase.
3. If routed to new microservice, it processes request independently.
4. Both old and new systems write to synchronized databases to maintain data consistency.
5. Monitoring tools collect logs and metrics from all components.
6. If issues detected, rollback to old monolith by changing routing rules in API Gateway.
Database Schema
Entities remain consistent across old and new systems. Dual writes or event sourcing ensure data synchronization. Key entities include User, Order, Product with relationships preserved. Migration may involve splitting monolithic tables into microservice-specific schemas.
Scaling Discussion
Bottlenecks
API Gateway becomes a single point of failure or bottleneck.
Data synchronization overhead increases latency.
Rollback complexity if data diverges.
Monitoring large distributed systems is challenging.
Solutions
Use multiple API Gateway instances with load balancing and failover.
Implement eventual consistency with conflict resolution strategies.
Design rollback procedures with data reconciliation tools.
Use centralized logging and distributed tracing for observability.
Interview Tips
Time: Spend 10 minutes understanding migration goals and risks, 15 minutes designing gradual migration architecture, 10 minutes discussing scaling and rollback strategies, 10 minutes answering questions.
Explain why migrating gradually reduces risk by limiting blast radius.
Discuss routing strategies to split traffic safely.
Highlight importance of data consistency and rollback plans.
Mention monitoring to detect issues early.
Show awareness of scaling challenges and solutions.