We are designing a legacy strangler-fig migration for SOAP services. The goal is to gradually replace the old SOAP services with new ones (likely REST or other modern patterns) without a big-bang rewrite. We will use adapters, gradual feature shift, and monitoring.
Key concepts:
- Strangler Fig Pattern: Gradually replace parts of the legacy system by building a new system around it, and then slowly strangling the old system by routing traffic to the new components until the old system is replaced.
- Adapters: These will be used to translate between the old SOAP interface and the new service interfaces. They can act as a facade or a proxy.
- Gradual Feature Shift: Move functionality piece by piece. We might start by moving non-critical features first, then critical ones.
- Monitoring: Essential to ensure that the new system is working correctly and to compare with the old system for correctness and performance.
We are migrating SOAP services. Let's assume we have a monolithic SOAP service (or a set of SOAP services) that we want to replace with microservices (or a new architecture) that expose REST APIs (or other protocols). However, we must continue to support the existing SOAP clients until we can migrate them.
Steps:
- Identify and catalog the SOAP services and their operations.
- Set up a monitoring system that can track both the legacy SOAP services and the new services. We need to compare responses, performance, error rates, etc.
- Build an adapter layer (or a gateway) that can receive SOAP requests and route them to the appropriate new service (or the old one if not yet migrated). This adapter might also be responsible for translating SOAP to REST (or whatever the new service uses) and back.
- Gradually shift features:
a. For a given operation (or a set of related operations) in a SOAP service, implement the same functionality in a new service (with a modern API).
b. Update the adapter to route requests for that operation to the new service instead of the old one.
c. Run both the old and new in parallel for that operation and monitor for discrepancies (using the monitoring system).
d. Once confident, completely switch over the operation to the new service and remove the old implementation (or at least stop routing to it).
- Repeat for each operation or feature until all are migrated.
- Eventually, when all operations are migrated, we can decommission the old SOAP service.
However, note that SOAP services often have complex operations and stateful interactions. We must be cautious about state and transactions.
Alternative approach: Instead of an adapter that translates SOAP to REST, we could build the new services to also support SOAP? But that might not be desirable because we want to move away from SOAP. Alternatively, we could use an API gateway that handles the protocol translation.
Let's design a more concrete plan:
Phase 1: Setup and Monitoring
- Deploy a monitoring system (like distributed tracing, logging, metrics) that can track requests through both the legacy SOAP service and the new services.
- Set up a test environment that mirrors production and can run both the old and new services for comparison.
Phase 2: Build the Adapter/Gateway
- Implement a SOAP-to-REST (or whatever) adapter. This could be a separate service that:
- Exposes the same WSDL as the legacy SOAP service (or a subset) so that existing clients can continue to call.
- Internally, it maps SOAP operations to calls to the new services (or the old one if not yet migrated).
- The adapter should be able to route based on configuration (so we can gradually switch).
- It should also log and monitor the requests and responses for comparison.
Phase 3: Gradual Migration
- For each SOAP operation (or a group of operations that form a feature):
- Implement the new service (with a modern API) that provides the same business logic.
- Update the adapter's routing configuration to send requests for that operation to the new service (in parallel, we might send to both for comparison?).
- Use the monitoring to compare the responses of the old and new services for the same input (we can replay production traffic in test, or use a shadowing approach in production).
- If discrepancies are found, fix the new service.
- Once the new service is deemed correct and performant, switch the adapter to route all traffic for that operation to the new service.
- Mark the operation as migrated and consider removing the old implementation (but keep it as a fallback for a while?).
Phase 4: Decommissioning
- After all operations are migrated, we can remove the old SOAP service and the adapter might be simplified (or removed if we also migrate the clients to call the new services directly).
Considerations:
- Stateful interactions: SOAP can be stateful (using WS-*). We must ensure that the new service can handle state if needed, or we need to manage state differently (maybe in a database or distributed cache). The adapter might need to handle state translation.
- Security: SOAP often uses WS-Security. The new services might use a different security mechanism (like OAuth2). The adapter must handle security token translation.
- Transactions: SOAP might use distributed transactions. The new architecture might use eventual consistency. We must design accordingly.
- Error handling: SOAP has standardized fault messages. The new services might use different error mechanisms. The adapter must translate errors appropriately.
- Data formats: SOAP uses XML, while REST often uses JSON. The adapter must convert between them.
Monitoring strategy:
- We want to compare the responses of the old and new services for the same request. We can do:
- Shadowing: In production, the adapter sends the request to both the old and new services (without returning the new response to the client) and logs both responses for comparison. This can be done for a percentage of traffic.
- Replay: Record production traffic and replay it against the new service in a test environment, then compare.
- We also want to monitor performance (latency, throughput) and error rates.
Implementation of the adapter:
- The adapter should be designed as a thin layer, focusing on translation and routing. Business logic should be in the new services.
- The adapter might need to maintain state for stateful interactions (like a session). But if the new services are stateless, then the adapter might become stateful, which could be a problem for scaling. We might need to store state in a shared cache (like Redis) or use a sticky session.
Gradual feature shift:
- We can migrate by feature (a set of operations that form a business capability) rather than by individual operations to avoid breaking a use case.
- We might also consider migrating by client or by API version. But since we are using an adapter that presents the same SOAP interface, we can control the routing per operation.
Example:
Suppose we have a SOAP service OrderService with operations: CreateOrder, GetOrder, UpdateOrder, CancelOrder.
We might migrate in this order:
GetOrder (read-only, safer)
CreateOrder
UpdateOrder
CancelOrder
For each, we build a new REST service (or a set of microservices) that implements the operation. The adapter, when it receives a SOAP request for GetOrder, will call the new GetOrder REST endpoint and convert the response to SOAP.
We might also consider building a new service that handles multiple operations (like an Order microservice) that exposes REST endpoints for all order operations. Then the adapter maps each SOAP operation to the corresponding REST endpoint.
Risks:
- The adapter becomes a single point of failure. We must ensure it is highly available.
- The adapter might become a performance bottleneck. We must design it to scale.
- Translation overhead: converting XML to JSON and back, and translating security tokens, might add latency.
Mitigations:
- Deploy the adapter as a cluster behind a load balancer.
- Use efficient libraries for XML/JSON transformation.
- Cache translations if possible (but be cautious with state).
Long-term:
Once all clients are migrated to the new REST APIs, we can remove the adapter and the SOAP interface.
But note: We might not be able to migrate all clients at once. Some clients might be third-party and we have no control. In that case, we might need to keep the SOAP adapter indefinitely for those clients. Then the new REST services are the core, and the adapter is a compatibility layer.
Monitoring tools:
- Use distributed tracing (like Jaeger, Zipkin) to trace requests through the adapter and the services.
- Use logging to capture the request and response (both SOAP and REST) for comparison.
- Set up metrics (latency, error rates) for both the old and new paths.
Testing:
- Unit tests for the adapter's translation logic.
- Integration tests for the adapter with the new services.
- Contract tests: ensure that the new service's behavior (as seen by the adapter) matches the old service's behavior.
Conclusion:
The strangler-fig approach allows us to gradually replace the SOAP services with minimal risk. The adapter acts as the facade that allows the old and new to coexist. By shifting feature by feature and monitoring closely, we can ensure correctness and performance.
Let's outline the steps in a structured way:
-
Analysis:
- Document all SOAP services and operations.
- Identify dependencies and stateful interactions.
- Group operations into features (business capabilities).
-
Monitoring Setup:
- Implement logging and metrics for the legacy SOAP services (if not already).
- Set up a system to capture and compare requests and responses between old and new.
-
Adapter Implementation:
- Build the adapter that:
- Listens on the SOAP endpoint (same as legacy or a new endpoint that we switch clients to).
- For each operation, based on configuration, routes to either the legacy SOAP service (if not migrated) or the new service (via REST or other).
- Translates SOAP envelope to the new service's request format and back.
- Handles security (extract tokens from SOAP header and convert to the new service's auth mechanism).
- Logs and monitors the traffic.
-
Gradual Migration:
- For each feature (or operation):
a. Develop the new service (with modern API) and deploy it alongside the legacy.
b. Update the adapter's routing configuration to send traffic for that feature to the new service (start with a small percentage, then 100%).
c. Monitor the new service's performance and correctness (using the monitoring setup).
d. If issues, fix and iterate.
e. Once stable, mark the feature as migrated and consider removing the old implementation (or leave it as fallback for a while).
-
Decommission Legacy:
- After all features are migrated, remove the legacy SOAP services and the adapter's fallback logic.
- Optionally, remove the adapter if no longer needed (if clients are migrated to direct calls to the new services). Otherwise, keep the adapter for SOAP clients.
-
Client Migration (optional but recommended):
- While we are doing the backend migration, we should also plan to migrate the clients to the new APIs. This might be a separate effort.
- Provide documentation and tools for clients to migrate.
Note: The adapter might need to be versioned. We might have multiple versions of the SOAP interface if we evolve the new services. But since we are strangling the old, we might keep the SOAP interface stable until we decommission.
This is a high-level design. Each step requires detailed planning and execution.
Legacy SOAP Strangler-Fig Migration Design
1. Core Architecture
[SOAP Clients]
↓
[Adapter Layer (Strangler Facade)]
├─→ [Legacy SOAP Services] (gradually reduced)
└─→ [New Service Mesh] (growing)
├─ REST/GraphQL/gRPC APIs
└─ Modern Data Stores
2. Key Components
A. Adapter Gateway
- Protocol Bridge: SOAP → REST/Message Queue translation
- Routing Matrix: Operation-level routing table (config-driven)
- State Management: Session/transaction context preservation
- Security Translation: WS-Security ↔ OAuth2/JWT
- Deployment: Sidecar or standalone gateway cluster
B. Migration Control Plane
routing_config:
- service: OrderService
operations:
GetOrder:
target: new_rest_api/v1/orders/{id}
migration: 100% # 0→100% gradual
fallback: legacy_soap # on failure
CreateOrder:
target: legacy_soap # not yet migrated
migration: 0%
C. Monitoring & Verification Stack
- Traffic Shadowing: 5-10% production traffic mirrored to new services
- Differential Logging: Capture and compare old/new responses
- Canary Metrics:
- Response time delta (p50/p99)
- Payload size comparison
- Fault rate divergence
- Contract Testing: Automated SOAP/REST contract validation
- SLA Dashboard: Real-time comparison per operation
3. Gradual Migration Strategy
Phase 1: Foundation (Weeks 1-4)
- Deploy adapter in monitor-only mode (log but don't route)
- Implement traffic replay system from production logs
- Build new service for read-only, stateless operation (e.g.,
GetCustomer)
- Test adapter translation with 1% shadowed traffic
Phase 2: Early Adopters (Weeks 5-12)
- Migrate non-critical services first:
- Reference data lookups
- Report generation (async)
- Historical queries
- Use feature flags per operation:
if (featureFlags.isMigrated("GetProduct")) {
callNewService();
} else {
callLegacy();
}
- Implement circuit breaker pattern for fallback safety
Phase 3: Core Services (Months 4-6)
- Migrate business-critical services in dependency order:
Customer → Product → Order → Payment → Inventory
- Implement transactional consistency checks:
- Dual-write to legacy and new during transition
- Reconciliation jobs for data divergence
- Migrate stateful operations last (using saga patterns)
Phase 4: Cleanup (Months 7-9)
- Route 100% of migrated operations to new services
- Archive legacy SOAP endpoints after 30-day cooldown
- Remove adapter translation logic for migrated operations
- Decommission legacy services one by one
4. Adapter Implementation Patterns
Translation Examples
<!-- SOAP Request -->
<soap:Envelope>
<GetCustomer>
<customerId>123</customerId>
</GetCustomer>
</soap:Envelope>
↓ Translation ↓
{
"operation": "get_customer",
"params": {"id": "123"},
"metadata": {
"soap_action": "GetCustomer",
"legacy_trace_id": "abc-123"
}
}
Error Handling Strategy
def translate_soap_fault(soap_fault, new_error):
if new_error.is_timeout():
return SOAPFault("Server busy, retry")
elif new_error.is_validation():
return SOAPFault("Invalid request data")
else:
# Preserve legacy fault codes for compatibility
return map_to_legacy_fault_code(new_error)
5. Monitoring & Safety Systems
Automated Safeguards
- Latency Guardrail:
- Alert if new service p99 > legacy p99 + 200ms
- Automatic rollback to legacy if threshold breached
- Data Consistency Checker:
- Compare critical fields between legacy/new responses
- Run every 5 minutes for 10% of traffic
- Rate Limiter:
- Gradually increase new traffic by 5% increments
- 24-hour stability period before next increase
Observability Dashboard
┌─────────────────────────────────────────────┐
│ Migration Health Score: 87/100 │
├─────────────────────────────────────────────┤
│ Service: OrderService │
│ Migrated Operations: 3/5 (60%) │
│ Error Rate Delta: +0.02% │
│ Latency Increase: +45ms (p95) │
│ Last Success: 2 hours ago │
├─────────────────────────────────────────────┤
│ Critical Alerts: │
│ ⚠ PaymentService latency +300ms │
│ ⚠ Data mismatch in GetOrder (0.1%) │
└─────────────────────────────────────────────┘
6. Risk Mitigation
Technical Risks
| Risk | Mitigation |
|---|
| Adapter becomes bottleneck | Scale horizontally; cache translations |
| State loss during migration | Dual-write pattern; state snapshots |
| WS-Security translation flaws | Security regression testing suite |
| Performance degradation | Load testing pre-migration; auto-rollback |
| Data inconsistency | Reconciliation jobs; checksum validation |
Operational Risks
-
Client Communication:
- Maintain WSDL compatibility during transition
- Version API via SOAPAction headers
- Provide migration guides for external clients
-
Rollback Plan:
- 5-minute rollback capability stored in routing config
- Legacy systems read-only during migration
- Daily backup of adapter state
-
Team Coordination:
- Dedicated migration war room first 2 weeks
-每日迁移状态同步会
- Clear ownership per service boundary
7. Success Metrics
Primary KPIs
- Migration Velocity: Operations/week
- Error Budget Burn: < 5% per migrated operation
- Client Impact: Zero downtime for external clients
- Performance Delta: < 15% latency increase per operation
Secondary Metrics
- Adapter overhead: < 10ms p50 latency
- Memory footprint: < 100MB per adapter instance
- Translation accuracy: 100% for 99.9% of traffic
8. Tools & Technologies
| Component | Recommended Options |
|---|
| Adapter Framework | Spring Cloud Gateway, Kong, Envoy |
| Monitoring | Prometheus + Jaeger + ELK |
| Traffic Shadowing | GoReplay, ShadowProxy |
| Contract Testing | Pact, SOAPUI, Postman |
| Feature Flags | LaunchDarkly, Unleash |
| Deployment | Kubernetes + Istio (for traffic shifting) |
9. Timeline Example (12 Months)
Month 1-2: Setup & Monitoring
Month 3-4: 15% operations migrated (non-critical)
Month 5-6: 40% operations migrated (core reads)
Month 7-8: 70% operations migrated (including writes)
Month 9-10: 95% operations migrated
Month 11-12: Legacy decommissioning & adapter cleanup
10. Critical Success Factors
- Executive buy-in for 12-18 month timeline
- Dedicated migration team separate from feature teams
- Legacy freeze on non-critical changes during migration
- Automated verification at every step
- Client patience through transparent communication
Final Note: The strangler-fig pattern succeeds through incrementalism. Each migrated operation must be:
- Verified (functionally equivalent)
- Observed (performing within thresholds)
- Stable (no rollbacks for 30 days)
before considering the next operation. The adapter remains the single point of translation until the very end, when it can be simplified or removed.